aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/profile/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/shared/profile/lib.rs')
-rw-r--r--components/shared/profile/lib.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/components/shared/profile/lib.rs b/components/shared/profile/lib.rs
index 7be3d265d6c..fef2b255bea 100644
--- a/components/shared/profile/lib.rs
+++ b/components/shared/profile/lib.rs
@@ -11,3 +11,17 @@
pub mod ipc;
pub mod mem;
pub mod time;
+
+/// Measure the given callback with the time profiler and (if enabled) tracing.
+///
+/// `$category` must be const, because we use it to derive the span name.
+#[macro_export]
+macro_rules! time_profile {
+ ($category:expr, $meta:expr, $profiler_chan:expr, $($callback:tt)+) => {{
+ #[cfg(feature = "tracing")]
+ let span = tracing::info_span!($category.variant_name(), servo_profiling = true);
+ #[cfg(not(feature = "tracing"))]
+ let span = ();
+ $crate::time::profile($category, $meta, $profiler_chan, span, $($callback)+)
+ }};
+}