Make tracing available on all platforms, with or without perfetto (#33301)

* Make tracing available on all platforms

Signed-off-by: Delan Azabani <dazabani@igalia.com>

* Gate perfetto support behind its own feature

Signed-off-by: Delan Azabani <dazabani@igalia.com>

---------

Signed-off-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
Delan Azabani 2024-09-04 20:56:29 +08:00 committed by GitHub
parent 891562be8e
commit c0ced7a524
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 33 additions and 79 deletions

View file

@ -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 Servos FromScriptLogger and FromCompositorLogger.
// <https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/util/trait.SubscriberInitExt.html#method.init>
// <https://docs.rs/tracing/0.1.40/tracing/#consuming-log-records>
tracing::subscriber::set_global_default(subscriber)
.expect("Failed to set tracing subscriber");
}
}
pub fn servo_version() -> String {