mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add cli option for tracing-filter (#35370)
Using environment variables is not really an option on ohos/android, so add a CLI option to configure tracing. Making it a `pref`, so that we can persist the filter might also be desirable. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
parent
39c1e5d5d6
commit
654df4c8b7
5 changed files with 44 additions and 8 deletions
|
@ -11,7 +11,6 @@ use crate::prefs::{parse_command_line_arguments, ArgumentParsingResult};
|
|||
|
||||
pub fn main() {
|
||||
crate::crash_handler::install();
|
||||
crate::init_tracing();
|
||||
crate::init_crypto();
|
||||
crate::resources::init();
|
||||
|
||||
|
@ -27,6 +26,8 @@ pub fn main() {
|
|||
},
|
||||
};
|
||||
|
||||
crate::init_tracing(servoshell_preferences.tracing_filter.as_deref());
|
||||
|
||||
let clean_shutdown = servoshell_preferences.clean_shutdown;
|
||||
let event_loop = EventsLoop::new(servoshell_preferences.headless, opts.output_file.is_some())
|
||||
.expect("Failed to create events loop");
|
||||
|
|
|
@ -52,7 +52,6 @@ pub fn init(
|
|||
waker: Box<dyn EventLoopWaker>,
|
||||
callbacks: Box<dyn HostTrait>,
|
||||
) -> Result<(), &'static str> {
|
||||
crate::init_tracing();
|
||||
crate::init_crypto();
|
||||
resources::set(Box::new(ResourceReaderInstance::new()));
|
||||
|
||||
|
@ -69,6 +68,8 @@ pub fn init(
|
|||
},
|
||||
};
|
||||
|
||||
crate::init_tracing(servoshell_preferences.tracing_filter.as_deref());
|
||||
|
||||
// Initialize surfman
|
||||
let connection = Connection::new().or(Err("Failed to create connection"))?;
|
||||
let adapter = connection
|
||||
|
|
|
@ -36,7 +36,6 @@ pub fn init(
|
|||
callbacks: Box<dyn HostTrait>,
|
||||
) -> Result<Rc<RunningAppState>, &'static str> {
|
||||
info!("Entered simpleservo init function");
|
||||
crate::init_tracing();
|
||||
crate::init_crypto();
|
||||
let resource_dir = PathBuf::from(&options.resource_dir).join("servo");
|
||||
resources::set(Box::new(ResourceReaderInstance::new(resource_dir)));
|
||||
|
@ -61,6 +60,8 @@ pub fn init(
|
|||
},
|
||||
};
|
||||
|
||||
crate::init_tracing(servoshell_preferences.tracing_filter.as_deref());
|
||||
|
||||
// Initialize surfman
|
||||
let connection = Connection::new().or(Err("Failed to create connection"))?;
|
||||
let adapter = connection
|
||||
|
|
|
@ -44,7 +44,13 @@ pub fn init_crypto() {
|
|||
.expect("Error initializing crypto provider");
|
||||
}
|
||||
|
||||
pub fn init_tracing() {
|
||||
pub fn init_tracing(filter_directives: Option<&str>) {
|
||||
#[cfg(not(feature = "tracing"))]
|
||||
{
|
||||
if filter_directives.is_some() {
|
||||
log::debug!("The tracing feature was not selected - ignoring trace filter directives");
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "tracing")]
|
||||
{
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
|
@ -69,10 +75,16 @@ pub fn init_tracing() {
|
|||
|
||||
// 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 filter_builder = tracing_subscriber::EnvFilter::builder()
|
||||
.with_default_directive(tracing::level_filters::LevelFilter::OFF.into());
|
||||
let filter = if let Some(filters) = &filter_directives {
|
||||
filter_builder.parse_lossy(filters)
|
||||
} else {
|
||||
filter_builder
|
||||
.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,
|
||||
|
|
|
@ -37,6 +37,11 @@ pub(crate) struct ServoShellPreferences {
|
|||
/// Whether or not to run servoshell in headless mode. While running in headless
|
||||
/// mode, image output is supported.
|
||||
pub headless: bool,
|
||||
/// Filter directives for our tracing implementation.
|
||||
///
|
||||
/// Overrides directives specified via `SERVO_TRACING` if set.
|
||||
/// See: <https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html#directives>
|
||||
pub tracing_filter: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for ServoShellPreferences {
|
||||
|
@ -50,6 +55,7 @@ impl Default for ServoShellPreferences {
|
|||
no_native_titlebar: true,
|
||||
searchpage: "https://duckduckgo.com/html/?q=%s".into(),
|
||||
headless: false,
|
||||
tracing_filter: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -311,6 +317,13 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
|
|||
"Set custom user agent string (or ios / android / desktop for platform default)",
|
||||
"NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)",
|
||||
);
|
||||
opts.optmulti(
|
||||
"",
|
||||
"tracing-filter",
|
||||
"Define a custom filter for traces. Overrides `SERVO_TRACING` if set.",
|
||||
"FILTER",
|
||||
);
|
||||
|
||||
opts.optmulti(
|
||||
"",
|
||||
"pref",
|
||||
|
@ -353,6 +366,13 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
|
|||
if let Some(content_process) = opt_match.opt_str("content-process") {
|
||||
return ArgumentParsingResult::ContentProcess(content_process);
|
||||
}
|
||||
// Env-Filter directives are comma seperated.
|
||||
let filters = opt_match.opt_strs("tracing-filter").join(",");
|
||||
let tracing_filter = if filters.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(filters)
|
||||
};
|
||||
|
||||
let mut debug_options = DebugOptions::default();
|
||||
for debug_string in opt_match.opt_strs("Z") {
|
||||
|
@ -544,6 +564,7 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
|
|||
device_pixel_ratio_override,
|
||||
clean_shutdown: opt_match.opt_present("clean-shutdown"),
|
||||
headless: opt_match.opt_present("z"),
|
||||
tracing_filter,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue