Debian Codegraph @

.cargo/vendor/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! function_scope {
14 () => {
15 let _function_name = {
16 struct S;
17 let type_name = core::any::type_name::<S>();
18 &type_name[..type_name.len() - 3]
19 };
20 $crate::scope!(_function_name);
21 };
22 ($data:expr) => {
23 let _function_name = {
24 struct S;
25 let type_name = core::any::type_name::<S>();
26 &type_name[..type_name.len() - 3]
27 };
28 $crate::scope!(_function_name, $data);
29 };
30 }
31
32 #[macro_export]
33 macro_rules! register_thread {
34 () => {
35 let thread_name = std::thread::current()
36 .name()
37 .map(|x| x.to_string())
38 .unwrap_or_else(|| format!("Thread {:?}", std::thread::current().id()));
39
40 $crate::register_thread!(&thread_name);
41 };
42 ($name:expr) => {
43 $crate::superluminal_perf::set_current_thread_name($name);
44 };
45 }
46
47 #[macro_export]
48 macro_rules! finish_frame {
49 () => {
50 // superluminal does not have a frame end function
51 };
52 }
53
54 //
55 // RAII wrappers to support superluminal. These are public as they need to be callable from macros
56 // but are not intended for direct use.
57 //
58 #[doc(hidden)]
59 pub mod superluminal {
60 pub struct SuperluminalGuard;
61
62 // 0xFFFFFFFF means "use default color"
63 const DEFAULT_SUPERLUMINAL_COLOR: u32 = 0xFFFFFFFF;
64
65 impl SuperluminalGuard {
66 pub fn new(name: &'static str) -> Self {
67 superluminal_perf::begin_event(name);
68 SuperluminalGuard
69 }
70
71 pub fn new_with_data(
72 name: &'static str,
73 data: &str,
74 ) -> Self {
75 superluminal_perf::begin_event_with_data(name, data, DEFAULT_SUPERLUMINAL_COLOR);
76 SuperluminalGuard
77 }
78 }
79
80 impl Drop for SuperluminalGuard {
81 fn drop(&mut self) {
82 superluminal_perf::end_event();
83 }
84 }
85 }