diff options
author | Delan Azabani <dazabani@igalia.com> | 2024-11-13 17:52:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-13 09:52:26 +0000 |
commit | c00804190cdc256183ade8f050d5f0408b550303 (patch) | |
tree | 1b8e1d161a99d6f4748f115e1299e0b8d2df99d4 /ports/servoshell | |
parent | 873e82a5329dffeeef9c91d0e47cf34c41c53b03 (diff) | |
download | servo-c00804190cdc256183ade8f050d5f0408b550303.tar.gz servo-c00804190cdc256183ade8f050d5f0408b550303.zip |
Allow filtering of tracing events via SERVO_TRACING (#34236)
* Allow filtering of tracing events via SERVO_TRACING
Signed-off-by: Delan Azabani <dazabani@igalia.com>
* Assume SERVO_TRACING=off by default
Signed-off-by: Delan Azabani <dazabani@igalia.com>
---------
Signed-off-by: Delan Azabani <dazabani@igalia.com>
Diffstat (limited to 'ports/servoshell')
-rw-r--r-- | ports/servoshell/Cargo.toml | 2 | ||||
-rw-r--r-- | ports/servoshell/lib.rs | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/ports/servoshell/Cargo.toml b/ports/servoshell/Cargo.toml index ea2e5584640..a1d0cbf3829 100644 --- a/ports/servoshell/Cargo.toml +++ b/ports/servoshell/Cargo.toml @@ -67,7 +67,7 @@ url = { workspace = true } servo-media = { workspace = true } tokio = { workspace = true } tracing = { workspace = true, optional = true } -tracing-subscriber = { workspace = true, optional = true } +tracing-subscriber = { workspace = true, optional = true, features = ["env-filter"] } tracing-perfetto = { workspace = true, optional = true } [target.'cfg(target_os = "android")'.dependencies] diff --git a/ports/servoshell/lib.rs b/ports/servoshell/lib.rs index c28ccbf79cd..ed29f6284e3 100644 --- a/ports/servoshell/lib.rs +++ b/ports/servoshell/lib.rs @@ -44,11 +44,11 @@ pub fn main() { pub fn init_tracing() { #[cfg(feature = "tracing")] { + use tracing_subscriber::layer::SubscriberExt; let subscriber = tracing_subscriber::registry(); #[cfg(feature = "tracing-perfetto")] let subscriber = { - use tracing_subscriber::layer::SubscriberExt; // Set up a PerfettoLayer for performance tracing. // The servo.pftrace file can be uploaded to https://ui.perfetto.dev for analysis. let file = std::fs::File::create("servo.pftrace").unwrap(); @@ -59,11 +59,18 @@ pub fn init_tracing() { #[cfg(feature = "tracing-hitrace")] let subscriber = { - use tracing_subscriber::layer::SubscriberExt; // Set up a HitraceLayer for performance tracing. subscriber.with(HitraceLayer::default()) }; + // Filter events and spans by the directives in SERVO_TRACING, using EnvFilter as a global filter. + // <https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/layer/index.html#global-filtering> + let filter = tracing_subscriber::EnvFilter::builder() + .with_default_directive(tracing::level_filters::LevelFilter::OFF.into()) + .with_env_var("SERVO_TRACING") + .from_env_lossy(); + let subscriber = subscriber.with(filter); + // Same as SubscriberInitExt::init, but avoids initialising the tracing-log compat layer, // since it would break Servo’s FromScriptLogger and FromCompositorLogger. // <https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/util/trait.SubscriberInitExt.html#method.init> |