From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../rust/profiling/src/superluminal_impl.rs | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 third_party/rust/profiling/src/superluminal_impl.rs (limited to 'third_party/rust/profiling/src/superluminal_impl.rs') diff --git a/third_party/rust/profiling/src/superluminal_impl.rs b/third_party/rust/profiling/src/superluminal_impl.rs new file mode 100644 index 0000000000..298df5cbf7 --- /dev/null +++ b/third_party/rust/profiling/src/superluminal_impl.rs @@ -0,0 +1,65 @@ +#[macro_export] +macro_rules! scope { + ($name:expr) => { + let _superluminal_guard = $crate::superluminal::SuperluminalGuard::new($name); + }; + ($name:expr, $data:expr) => { + let _superluminal_guard = + $crate::superluminal::SuperluminalGuard::new_with_data($name, $data); + }; +} + +#[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) => { + $crate::superluminal_perf::set_current_thread_name($name); + }; +} + +#[macro_export] +macro_rules! finish_frame { + () => { + // superluminal does not have a frame end function + }; +} + +// +// RAII wrappers to support superluminal. These are public as they need to be callable from macros +// but are not intended for direct use. +// +#[doc(hidden)] +pub mod superluminal { + pub struct SuperluminalGuard; + + // 0xFFFFFFFF means "use default color" + const DEFAULT_SUPERLUMINAL_COLOR: u32 = 0xFFFFFFFF; + + 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, DEFAULT_SUPERLUMINAL_COLOR); + SuperluminalGuard + } + } + + impl Drop for SuperluminalGuard { + fn drop(&mut self) { + superluminal_perf::end_event(); + } + } +} -- cgit v1.2.3