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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#[macro_export]
macro_rules! scope {
($name:expr) => {
#[cfg(feature = "profile-with-puffin")]
puffin::profile_scope!($name);
#[cfg(feature = "profile-with-optick")]
optick::event!($name);
#[cfg(feature = "profile-with-superluminal")]
let _superluminal_guard = $crate::superluminal::SuperluminalGuard::new($name);
#[cfg(feature = "profile-with-tracing")]
let _span = tracing::span!(tracing::Level::INFO, $name);
#[cfg(feature = "profile-with-tracing")]
let _span_entered = _span.enter();
};
($name:expr, $data:expr) => {
#[cfg(feature = "profile-with-puffin")]
puffin::profile_scope_data!($name, $data);
#[cfg(feature = "profile-with-optick")]
optick::event!($name);
#[cfg(feature = "profile-with-optick")]
optick::tag!("tag", $data);
#[cfg(feature = "profile-with-superluminal")]
let _superluminal_guard =
$crate::superluminal::SuperluminalGuard::new_with_data($name, $data);
#[cfg(feature = "profile-with-tracing")]
let _span = tracing::span!(tracing::Level::INFO, $name, tag = $data);
#[cfg(feature = "profile-with-tracing")]
let _span_entered = _span.enter();
};
}
pub use profiling_procmacros::function;
#[macro_export]
macro_rules! register_thread {
() => {
let thread_name = std::thread::current()
.name()
.map(|x| x.to_string())
.unwrap_or_else(|| format!("Thread {:?}", std::thread::current().id()));
$crate::register_thread!(&thread_name);
};
($name:expr) => {
#[cfg(feature = "profile-with-optick")]
optick::register_thread($name);
#[cfg(feature = "profile-with-superluminal")]
superluminal_perf::set_current_thread_name($name);
#[cfg(feature = "profile-with-tracy")]
tracy_client::set_thread_name($name);
};
}
#[macro_export]
macro_rules! finish_frame {
() => {
#[cfg(feature = "profile-with-puffin")]
puffin::GlobalProfiler::lock().new_frame();
#[cfg(feature = "profile-with-optick")]
optick::next_frame();
#[cfg(feature = "profile-with-tracy")]
tracy_client::finish_continuous_frame!();
};
}
#[cfg(feature = "profile-with-superluminal")]
#[doc(hidden)]
pub mod superluminal {
pub struct SuperluminalGuard;
impl SuperluminalGuard {
pub fn new(name: &str) -> Self {
superluminal_perf::begin_event(name);
SuperluminalGuard
}
pub fn new_with_data(
name: &str,
data: &str,
) -> Self {
superluminal_perf::begin_event_with_data(name, data, 0);
SuperluminalGuard
}
}
impl Drop for SuperluminalGuard {
fn drop(&mut self) {
superluminal_perf::end_event();
}
}
}