Debian Codegraph @

third_party/rust/profiling/src/tracy_impl.rs

raw
1 #[macro_export]
2 macro_rules! scope {
3 // Note: literal patterns provided as an optimization since they can skip an allocation.
4 ($name:literal) => {
5 // Note: callstack_depth is 0 since this has significant overhead
6 let _tracy_span = $crate::tracy_client::span!($name, 0);
7 };
8 ($name:literal, $data:expr) => {
9 // Note: callstack_depth is 0 since this has significant overhead
10 let _tracy_span = $crate::tracy_client::span!($name, 0);
11 _tracy_span.emit_text($data);
12 };
13 ($name:expr) => {
14 let function_name = {
15 struct S;
16 let type_name = core::any::type_name::<S>();
17 &type_name[..type_name.len() - 3]
18 };
19 let _tracy_span = $crate::tracy_client::Client::running()
20 .expect("scope! without a running tracy_client::Client")
21 // Note: callstack_depth is 0 since this has significant overhead
22 .span_alloc($name, function_name, file!(), line!(), 0);
23 };
24 ($name:expr, $data:expr) => {
25 let function_name = {
26 struct S;
27 let type_name = core::any::type_name::<S>();
28 &type_name[..type_name.len() - 3]
29 };
30 let _tracy_span = $crate::tracy_client::Client::running()
31 .expect("scope! without a running tracy_client::Client")
32 // Note: callstack_depth is 0 since this has significant overhead
33 .span_alloc($name, function_name, file!(), line!(), 0);
34 _tracy_span.emit_text($data);
35 };
36 }
37
38 /// Registers a thread with the profiler API(s). This is usually setting a name for the thread.
39 /// Two variants:
40 /// - register_thread!() - Tries to get the name of the thread, or an ID if no name is set
41 /// - register_thread!(name: &str) - Registers the thread using the given name
42 #[macro_export]
43 macro_rules! register_thread {
44 () => {
45 let thread_name = std::thread::current()
46 .name()
47 .map(|x| x.to_string())
48 .unwrap_or_else(|| format!("Thread {:?}", std::thread::current().id()));
49
50 $crate::register_thread!(&thread_name);
51 };
52 ($name:expr) => {
53 $crate::tracy_client::Client::running()
54 .expect("register_thread! without a running tracy_client::Client")
55 .set_thread_name($name);
56 };
57 }
58
59 /// Finishes the frame. This isn't strictly necessary for some kinds of applications but a pretty
60 /// normal thing to track in games.
61 #[macro_export]
62 macro_rules! finish_frame {
63 () => {
64 $crate::tracy_client::Client::running()
65 .expect("finish_frame! without a running tracy_client::Client")
66 .frame_mark();
67 };
68 }