#![deny(unsafe_code)]
pub mod generic_callback;
pub mod generic_channel;
pub mod ipc;
pub mod mem;
pub mod time;
#[macro_export]
macro_rules! time_profile {
($category:expr, $meta:expr, $profiler_chan:expr, $($callback:tt)+) => {{
let meta: Option<$crate::time::TimerMetadata> = $meta;
#[cfg(feature = "tracing")]
let span = $crate::servo_tracing::info_span!(
$category.variant_name(),
servo_profiling = true,
url = meta.as_ref().map(|m| m.url.clone()),
);
#[cfg(not(feature = "tracing"))]
let span = ();
$crate::time::profile($category, meta, $profiler_chan, span, $($callback)+)
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __profiling_span {
($backend_macro:ident, $span_name:literal $(, $($fields:tt)+)?) => {{
#[cfg(feature = "tracing")]
{
$crate::servo_tracing::$backend_macro!(
$span_name,
servo_profiling = true
$(, $($fields)+)?
)
}
#[cfg(not(feature = "tracing"))]
{
$crate::dummy_tracing::Span()
}
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __profiling_event {
($backend_macro:ident, $event_name:literal $(, $($fields:tt)+)?) => {{
#[cfg(feature = "tracing")]
$crate::servo_tracing::$backend_macro!(
name: $event_name,
servo_profiling = true
$(, $($fields)+)?
);
}};
}
pub mod dummy_tracing {
use std::fmt::Display;
use std::marker::PhantomData;
pub struct Span();
pub struct EnteredSpan(Span);
pub struct Entered<'a>(PhantomData<&'a Span>);
impl Span {
pub fn enter(&self) -> Entered<'_> {
Entered(PhantomData)
}
pub fn entered(self) -> EnteredSpan {
EnteredSpan(self)
}
pub fn in_scope<F: FnOnce() -> T, T>(&self, f: F) -> T {
f()
}
}
impl EnteredSpan {}
impl Entered<'_> {}
#[derive(Debug)]
struct Level();
#[expect(dead_code)]
impl Level {
pub const ERROR: Level = Level();
pub const WARN: Level = Level();
pub const INFO: Level = Level();
pub const DEBUG: Level = Level();
pub const TRACE: Level = Level();
pub fn as_str(&self) -> &'static str {
"disabled"
}
}
impl Display for Level {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
}
#[macro_export]
macro_rules! trace_span {
($span_name:literal $(, $($fields:tt)+)?) => {
$crate::__profiling_span!(trace_span, $span_name $(, $($fields)+)?)
};
}
#[macro_export]
macro_rules! debug_span {
($span_name:literal $(, $($fields:tt)+)?) => {
$crate::__profiling_span!(debug_span, $span_name $(, $($fields)+)?)
};
}
#[macro_export]
macro_rules! info_span {
($span_name:literal $(, $($fields:tt)+)?) => {
$crate::__profiling_span!(info_span, $span_name $(, $($fields)+)?)
};
}
#[macro_export]
macro_rules! trace_event {
($event_name:literal $(, $($fields:tt)+)?) => {
$crate::__profiling_event!(trace, $event_name $(, $($fields)+)?)
};
}
#[macro_export]
macro_rules! debug_event {
($event_name:literal $(, $($fields:tt)+)?) => {
$crate::__profiling_event!(debug, $event_name $(, $($fields)+)?)
};
}
#[macro_export]
macro_rules! info_event {
($event_name:literal $(, $($fields:tt)+)?) => {
$crate::__profiling_event!(info, $event_name $(, $($fields)+)?)
};
}
#[cfg(feature = "tracing")]
pub use tracing as servo_tracing;