profile_traits/lib.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! This module contains APIs for the `profile` crate used generically in the
6//! rest of Servo. These APIs are here instead of in `profile` so that these
7//! modules won't have to depend on `profile`.
8
9#![deny(unsafe_code)]
10
11pub mod generic_channel;
12pub mod ipc;
13pub mod mem;
14pub mod time;
15
16/// Measure the given callback with the time profiler and (if enabled) tracing.
17///
18/// `$category` must be const, because we use it to derive the span name.
19#[macro_export]
20macro_rules! time_profile {
21 ($category:expr, $meta:expr, $profiler_chan:expr, $($callback:tt)+) => {{
22 let meta: Option<$crate::time::TimerMetadata> = $meta;
23 #[cfg(feature = "tracing")]
24 let span = tracing::info_span!(
25 $category.variant_name(),
26 servo_profiling = true,
27 url = meta.as_ref().map(|m| m.url.clone()),
28 );
29 #[cfg(not(feature = "tracing"))]
30 let span = ();
31 $crate::time::profile($category, meta, $profiler_chan, span, $($callback)+)
32 }};
33}