From ae517d957f59a054955d3bcd83b16506ce853d60 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 14 Nov 2024 16:31:26 +0800 Subject: [PATCH 1/2] Allow enable and set profiler settings from cli --- src/config.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index d43968b..719324c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,9 +8,19 @@ use net_traits::{ response::{Response, ResponseBody}, ResourceFetchTiming, }; -use servo_config::opts::{default_opts, set_options, Opts}; +use servo_config::opts::{default_opts, set_options, Opts, OutputOptions}; use winit::{dpi, window::WindowAttributes}; +/// Servo time profile settings +#[derive(Clone, Debug)] +pub struct ProfilerSettings { + /// Servo time profile settings + output_options: OutputOptions, + /// When servo profiler is enabled, this is an optional path to dump a self-contained HTML file + /// visualizing the traces as a timeline. + trace_path: Option, +} + /// Command line arguments. #[derive(Clone, Debug, Default)] pub struct CliArgs { @@ -24,6 +34,8 @@ pub struct CliArgs { pub window_attributes: WindowAttributes, /// Port number to start a server to listen to remote Firefox devtools connections. 0 for random port. pub devtools_port: Option, + /// Servo time profile settings + pub profiler_settings: Option, } /// Configuration of Verso instance. @@ -41,7 +53,7 @@ fn parse_cli_args() -> Result { let args: Vec = std::env::args().collect(); let mut opts = getopts::Options::new(); - opts.optopt("", "url", "URL to load on start", "URL"); + opts.optopt("", "url", "URL to load on start", "docs.rs"); opts.optopt( "", "ipc-channel", @@ -53,32 +65,50 @@ fn parse_cli_args() -> Result { "", "devtools-port", "Launch Verso with devtools server enabled and listen to port", - "port", + "1234", + ); + opts.optopt( + "", + "profiler", + "Launch Verso with servo time profiler enabled and output to stdout with an interval", + "5", + ); + opts.optopt( + "", + "profiler-output-file", + "Make servo profiler output to this file instead of stdout", + "out.tsv", + ); + opts.optopt( + "", + "profiler-trace-path", + "Path to dump a self-contained HTML timeline of profiler traces", + "out.html", ); opts.optopt( "w", "width", "Initial window's width in physical unit, the height command line arg must also be set", - "", + "1280", ); opts.optopt( "h", "height", "Initial window's height in physical unit, the width command line arg must also be set", - "", + "720", ); opts.optopt( "x", "", "Initial window's top left x position in physical unit, the y command line arg must also be set. Wayland isn't supported.", - "", + "200", ); opts.optopt( "y", "", "Initial window's top left y position in physical unit, the x command line arg must also be set. Wayland isn't supported.", - "", + "200", ); let matches: getopts::Matches = opts.parse(&args[1..])?; @@ -103,6 +133,21 @@ fn parse_cli_args() -> Result { None }); + let profiler_settings = if let Ok(Some(profiler_interval)) = matches.opt_get("profiler") { + let profile_output = matches.opt_str("profiler-output-file"); + let trace_output = matches.opt_str("profiler-trace-path"); + Some(ProfilerSettings { + output_options: if let Some(output_file) = profile_output { + OutputOptions::FileName(output_file) + } else { + OutputOptions::Stdout(profiler_interval) + }, + trace_path: trace_output, + }) + } else { + None + }; + let mut window_attributes = winit::window::Window::default_attributes(); let width = matches.opt_get::("width").unwrap_or_else(|e| { @@ -154,6 +199,7 @@ fn parse_cli_args() -> Result { no_panel, window_attributes, devtools_port, + profiler_settings, }) } @@ -169,6 +215,11 @@ impl Config { opts.devtools_port = devtools_port; } + if let Some(ref profiler_settings) = args.profiler_settings { + opts.time_profiling = Some(profiler_settings.output_options.clone()); + opts.time_profiler_trace_path = profiler_settings.trace_path.clone(); + } + Self { opts, resource_dir, From 41046016f3f7328b120e5258314a9e50b9e935df Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Thu, 14 Nov 2024 23:02:34 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Ngo Iok Ui (Wu Yu Wei) Signed-off-by: Tony <68118705+Legend-Master@users.noreply.github.com> --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index fa7c6c5..4b561d6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -73,7 +73,7 @@ fn parse_cli_args() -> Result { "1234", ); opts.optopt( - "", + "p", "profiler", "Launch Verso with servo time profiler enabled and output to stdout with an interval", "5",