summaryrefslogtreecommitdiffstats
path: root/third_party/rust/profiling/src/superluminal_impl.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/profiling/src/superluminal_impl.rs
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/profiling/src/superluminal_impl.rs')
-rw-r--r--third_party/rust/profiling/src/superluminal_impl.rs65
1 files changed, 65 insertions, 0 deletions
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();
+ }
+ }
+}