diff --git a/Cargo.lock b/Cargo.lock index 8d3b7006ee8..84eb863e5d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4156,15 +4156,6 @@ dependencies = [ "tendril", ] -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] - [[package]] name = "matches" version = "0.1.10" @@ -5510,16 +5501,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata 0.4.7", - "regex-syntax 0.8.4", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", + "regex-syntax", ] [[package]] @@ -5539,15 +5521,9 @@ checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.4", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.8.4" @@ -7303,14 +7279,10 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ - "matchers", "nu-ansi-term", - "once_cell", - "regex", "sharded-slab", "smallvec", "thread_local", - "tracing", "tracing-core", "tracing-log", ] diff --git a/ports/servoshell/Cargo.toml b/ports/servoshell/Cargo.toml index 5e6ff09800e..e18769916e1 100644 --- a/ports/servoshell/Cargo.toml +++ b/ports/servoshell/Cargo.toml @@ -48,7 +48,8 @@ multiview = ["libservo/multiview"] native-bluetooth = ["libservo/native-bluetooth"] profilemozjs = ["libservo/profilemozjs"] refcell_backtrace = ["libservo/refcell_backtrace"] -tracing = ["dep:tracing", "dep:tracing-subscriber", "dep:tracing-perfetto"] +tracing = ["dep:tracing", "dep:tracing-subscriber"] +tracing-perfetto = ["tracing", "dep:tracing-perfetto"] webdriver = ["libservo/webdriver"] webgl_backtrace = ["libservo/webgl_backtrace"] @@ -62,6 +63,9 @@ mime_guess = { workspace = true } url = { workspace = true } servo-media = { workspace = true } tokio = { workspace = true } +tracing = { workspace = true, optional = true } +tracing-subscriber = { workspace = true, optional = true } +tracing-perfetto = { workspace = true, optional = true } [target.'cfg(target_os = "android")'.dependencies] android_logger = "0.14" @@ -111,9 +115,6 @@ raw-window-handle = "0.6" shellwords = "1.0.0" surfman = { workspace = true, features = ["sm-x11", "sm-raw-window-handle-06"] } tinyfiledialogs = "3.0" -tracing = { workspace = true, optional = true } -tracing-subscriber = { workspace = true, features = ["env-filter"], optional = true } -tracing-perfetto = { workspace = true, optional = true } webxr = { git = "https://github.com/servo/webxr", features = ["ipc", "glwindow", "headless"] } winit = "0.29.10" diff --git a/ports/servoshell/desktop/cli.rs b/ports/servoshell/desktop/cli.rs index 0fa2bcc8a00..78dd8426924 100644 --- a/ports/servoshell/desktop/cli.rs +++ b/ports/servoshell/desktop/cli.rs @@ -8,42 +8,13 @@ use getopts::Options; use log::error; use servo::config::opts::{self, ArgumentParsingResult}; use servo::servo_config::pref; -#[cfg(feature = "tracing")] -use tracing::subscriber::set_global_default; -#[cfg(feature = "tracing")] -use tracing_perfetto::PerfettoLayer; -#[cfg(feature = "tracing")] -use tracing_subscriber::layer::SubscriberExt; -#[cfg(feature = "tracing")] -use tracing_subscriber::util::SubscriberInitExt; -#[cfg(feature = "tracing")] -use tracing_subscriber::EnvFilter; use crate::desktop::app::App; use crate::panic_hook; pub fn main() { crate::crash_handler::install(); - - #[cfg(feature = "tracing")] - { - let file = std::fs::File::create("servo.pftrace").unwrap(); - let perfetto_layer = PerfettoLayer::new(std::sync::Mutex::new(file)); - - // Set up a custom tracing subscriber and PerfettoLayer for performance tracing. - // The servo.pftrace file can be uploaded to https://ui.perfetto.dev for analysis. - let env_filter_layer = EnvFilter::from_default_env(); - let subscriber = tracing_subscriber::registry() - .with(env_filter_layer) - .with(perfetto_layer); - - // Set the subscriber as the global default for tracing. This means it will be used - // throughout the entire program unless a thread-local subscriber is set. - // Can only be set once; subsequent attempts will fail. - // - set_global_default(subscriber).expect("Failed to set global default subscriber"); - } - + crate::init_tracing(); crate::resources::init(); // Parse the command line options and store them globally diff --git a/ports/servoshell/egl/android/simpleservo.rs b/ports/servoshell/egl/android/simpleservo.rs index d12146382f5..d5b9a73ebc8 100644 --- a/ports/servoshell/egl/android/simpleservo.rs +++ b/ports/servoshell/egl/android/simpleservo.rs @@ -107,6 +107,7 @@ pub fn init( waker: Box, callbacks: Box, ) -> Result<(), &'static str> { + crate::init_tracing(); resources::set(Box::new(ResourceReaderInstance::new())); if let Some(prefs) = init_opts.prefs { diff --git a/ports/servoshell/egl/ohos/simpleservo.rs b/ports/servoshell/egl/ohos/simpleservo.rs index e23415940a2..226a5c18fc7 100644 --- a/ports/servoshell/egl/ohos/simpleservo.rs +++ b/ports/servoshell/egl/ohos/simpleservo.rs @@ -40,6 +40,7 @@ pub fn init( callbacks: Box, ) -> Result { info!("Entered simpleservo init function"); + crate::init_tracing(); resources::set(Box::new(ResourceReaderInstance::new())); gl.clear_color(1.0, 1.0, 1.0, 1.0); diff --git a/ports/servoshell/lib.rs b/ports/servoshell/lib.rs index 8789f1a67c7..6120749c6cf 100644 --- a/ports/servoshell/lib.rs +++ b/ports/servoshell/lib.rs @@ -39,17 +39,28 @@ pub fn main() { desktop::cli::main() } -#[cfg(target_os = "android")] -pub fn main() { - println!( - "Cannot start /ports/servoshell/ on Android. \ - Use /support/android/apk/ + `libservoshell.so` instead" - ); -} +pub fn init_tracing() { + #[cfg(feature = "tracing")] + { + let subscriber = tracing_subscriber::registry(); -#[cfg(target_env = "ohos")] -pub fn main() { - println!("You shouldn't start /ports/servoshell/ on OpenHarmony."); + #[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(); + let perfetto_layer = tracing_perfetto::PerfettoLayer::new(std::sync::Mutex::new(file)); + subscriber.with(perfetto_layer) + }; + + // Same as SubscriberInitExt::init, but avoids initialising the tracing-log compat layer, + // since it would break Servo’s FromScriptLogger and FromCompositorLogger. + // + // + tracing::subscriber::set_global_default(subscriber) + .expect("Failed to set tracing subscriber"); + } } pub fn servo_version() -> String { diff --git a/ports/servoshell/main.rs b/ports/servoshell/main.rs index 08fef65b91f..77406dba5d4 100644 --- a/ports/servoshell/main.rs +++ b/ports/servoshell/main.rs @@ -25,6 +25,8 @@ fn main() { if #[cfg(not(any(target_os = "android", target_env = "ohos")))] { servoshell::main() } else { + // Android: see ports/servoshell/egl/android/simpleservo.rs. + // OpenHarmony: see ports/servoshell/egl/ohos/simpleservo.rs. println!( "Cannot run the servoshell `bin` executable on platforms such as \ Android or OpenHarmony. On these platforms you need to compile \ diff --git a/servo-tidy.toml b/servo-tidy.toml index 406e5aec717..fa9f51bd000 100644 --- a/servo-tidy.toml +++ b/servo-tidy.toml @@ -77,11 +77,6 @@ packages = [ # icu_list -> regex-automata 0.2.0 # tracing-subscriber -> matchers -> regex-automata 0.1.0 "regex-automata", - - # tracing-subscriber (tokio-rs/tracing#3033) uses old version - # regex [-> regex-automata 0.4.7] -> regex-syntax 0.8.4 - # tracing-subscriber -> matchers -> regex-automata 0.1.0 -> regex-syntax 0.6.29 - "regex-syntax", ] # Files that are ignored for all tidy and lint checks. files = [