Debian Codegraph @

third_party/rust/profiling/src/superluminal_impl.rs

raw
1 #[macro_export]
2 macro_rules! scope {
3 ($name:expr) => {
4 let _superluminal_guard = $crate::superluminal::SuperluminalGuard::new($name);
5 };
6 ($name:expr, $data:expr) => {
7 let _superluminal_guard =
8 $crate::superluminal::SuperluminalGuard::new_with_data($name, $data);
9 };
10 }
11
12 #[macro_export]
13 macro_rules! register_thread {
14 () => {
15 let thread_name = std::thread::current()
16 .name()
17 .map(|x| x.to_string())
18 .unwrap_or_else(|| format!("Thread {:?}", std::thread::current().id()));
19
20 $crate::register_thread!(&thread_name);
21 };
22 ($name:expr) => {
23 $crate::superluminal_perf::set_current_thread_name($name);
24 };
25 }
26
27 #[macro_export]
28 macro_rules! finish_frame {
29 () => {
30 // superluminal does not have a frame end function
31 };
32 }
33
34 //
35 // RAII wrappers to support superluminal. These are public as they need to be callable from macros
36 // but are not intended for direct use.
37 //
38 #[doc(hidden)]
39 pub mod superluminal {
40 pub struct SuperluminalGuard;
41
42 // 0xFFFFFFFF means "use default color"
43 const DEFAULT_SUPERLUMINAL_COLOR: u32 = 0xFFFFFFFF;
44
45 impl SuperluminalGuard {
46 pub fn new(name: &str) -> Self {
47 superluminal_perf::begin_event(name);
48 SuperluminalGuard
49 }
50
51 pub fn new_with_data(
52 name: &str,
53 data: &str,
54 ) -> Self {
55 superluminal_perf::begin_event_with_data(name, data, DEFAULT_SUPERLUMINAL_COLOR);
56 SuperluminalGuard
57 }
58 }
59
60 impl Drop for SuperluminalGuard {
61 fn drop(&mut self) {
62 superluminal_perf::end_event();
63 }
64 }
65 }