1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::{Profiler, SerializationSink, StringComponent, StringId};
pub const SEPARATOR_BYTE: &str = "\x1E";
#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
#[repr(C)]
pub struct EventId(StringId);
impl EventId {
pub const INVALID: EventId = EventId(StringId::INVALID);
#[inline]
pub fn to_string_id(self) -> StringId {
self.0
}
#[inline]
pub fn as_u32(self) -> u32 {
self.0.as_u32()
}
#[inline]
pub fn from_label(label: StringId) -> EventId {
EventId(label)
}
#[inline]
pub fn from_virtual(virtual_id: StringId) -> EventId {
EventId(virtual_id)
}
#[inline]
pub fn from_u32(raw_id: u32) -> EventId {
EventId(StringId::new(raw_id))
}
}
pub struct EventIdBuilder<'p, S: SerializationSink> {
profiler: &'p Profiler<S>,
}
impl<'p, S: SerializationSink> EventIdBuilder<'p, S> {
pub fn new(profiler: &Profiler<S>) -> EventIdBuilder<'_, S> {
EventIdBuilder { profiler }
}
#[inline]
pub fn from_label(&self, label: StringId) -> EventId {
EventId::from_label(label)
}
pub fn from_label_and_arg(&self, label: StringId, arg: StringId) -> EventId {
EventId(self.profiler.alloc_string(&[
StringComponent::Ref(label),
StringComponent::Value(SEPARATOR_BYTE),
StringComponent::Ref(arg),
]))
}
}