1#![allow(unused_variables)]
31#![allow(unsafe_code)]
32
33#[cfg(test)]
34mod test;
35
36#[cfg(all(feature = "enable", target_os = "windows"))]
37use superluminal_perf_sys as ffi;
38
39pub const fn enabled() -> bool {
41 cfg!(all(feature = "enable", target_os = "windows"))
42}
43
44pub fn begin_event(id: &'static str) {
46 #[cfg(all(feature = "enable", target_os = "windows"))]
47 unsafe {
48 ffi::PerformanceAPI_BeginEvent_N(
49 id.as_ptr().cast::<i8>(),
50 id.len() as u16,
51 std::ptr::null(),
52 0,
53 ffi::DEFAULT_COLOR,
54 );
55 }
56}
57
58pub fn begin_event_with_color(id: &'static str, color: u32) {
60 #[cfg(all(feature = "enable", target_os = "windows"))]
61 unsafe {
62 ffi::PerformanceAPI_BeginEvent_N(
63 id.as_ptr().cast::<i8>(),
64 id.len() as u16,
65 std::ptr::null(),
66 0,
67 color,
68 );
69 }
70}
71
72pub fn begin_event_with_data(id: &'static str, data: &str, color: u32) {
76 #[cfg(all(feature = "enable", target_os = "windows"))]
77 unsafe {
78 ffi::PerformanceAPI_BeginEvent_N(
79 id.as_ptr().cast::<i8>(),
80 id.len() as u16,
81 data.as_ptr().cast::<i8>(),
82 data.len() as u16,
83 color,
84 );
85 }
86}
87
88pub fn end_event() {
92 #[cfg(all(feature = "enable", target_os = "windows"))]
93 unsafe {
94 let _ = ffi::PerformanceAPI_EndEvent();
97 }
98}
99
100pub fn set_current_thread_name(name: &str) {
102 #[cfg(all(feature = "enable", target_os = "windows"))]
103 unsafe {
104 ffi::PerformanceAPI_SetCurrentThreadName_N(name.as_ptr().cast::<i8>(), name.len() as u16);
105 }
106}
107
108pub fn register_fiber(in_fiber_id: u64) {
110 #[cfg(all(feature = "enable", target_os = "windows"))]
111 unsafe {
112 ffi::PerformanceAPI_RegisterFiber(in_fiber_id);
113 }
114}
115
116pub fn unregister_fiber(in_fiber_id: u64) {
118 #[cfg(all(feature = "enable", target_os = "windows"))]
119 unsafe {
120 ffi::PerformanceAPI_UnregisterFiber(in_fiber_id);
121 }
122}
123
124pub fn begin_fiber_switch(in_current_fiber_id: u64, in_new_fiber_id: u64) {
128 #[cfg(all(feature = "enable", target_os = "windows"))]
129 unsafe {
130 ffi::PerformanceAPI_BeginFiberSwitch(in_current_fiber_id, in_new_fiber_id);
131 }
132}
133
134pub fn end_fiber_switch(in_fiber_id: u64) {
138 #[cfg(all(feature = "enable", target_os = "windows"))]
139 unsafe {
140 ffi::PerformanceAPI_EndFiberSwitch(in_fiber_id);
141 }
142}