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

@ -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.
// <https://docs.rs/tracing/0.1.40/src/tracing/subscriber.rs.html#30>
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