diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/Cargo.toml | 2 | ||||
-rw-r--r-- | components/script/dom/globalscope.rs | 4 | ||||
-rw-r--r-- | components/script/dom/servoparser/mod.rs | 48 | ||||
-rw-r--r-- | components/script/script_thread.rs | 153 |
4 files changed, 148 insertions, 59 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index d663f62c415..67f56c5e760 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -16,6 +16,7 @@ path = "lib.rs" debugmozjs = ['js/debugmozjs'] jitspew = ['js/jitspew'] profilemozjs = ['js/profilemozjs'] +tracing = ["dep:tracing"] webgl_backtrace = ["canvas_traits/webgl_backtrace"] js_backtrace = [] refcell_backtrace = ["accountable-refcell"] @@ -111,6 +112,7 @@ swapper = "0.1" tempfile = "3" tendril = { version = "0.4.1", features = ["encoding_rs"] } time_03 = { workspace = true } +tracing = { workspace = true, optional = true } unicode-bidi = { workspace = true } unicode-segmentation = { workspace = true } url = { workspace = true } diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 811e9f03eaa..ca5d66deb94 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -52,7 +52,7 @@ use net_traits::{ fetch_async, CoreResourceMsg, CoreResourceThread, FetchResponseListener, IpcSend, ReferrerPolicy, ResourceThreads, }; -use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time}; +use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time, time_profile}; use script_traits::serializable::{BlobData, BlobImpl, FileBlob}; use script_traits::transferable::MessagePortImpl; use script_traits::{ @@ -2686,7 +2686,7 @@ impl GlobalScope { iframe: profile_time::TimerMetadataFrameType::RootWindow, incremental: profile_time::TimerMetadataReflowType::FirstReflow, }; - profile_time::profile( + time_profile!( profile_time::ProfilerCategory::ScriptEvaluate, Some(metadata), self.time_profiler_chan().clone(), diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs index ca1c20aaf03..82128477f33 100644 --- a/components/script/dom/servoparser/mod.rs +++ b/components/script/dom/servoparser/mod.rs @@ -27,8 +27,9 @@ use net_traits::{ ResourceTimingType, }; use profile_traits::time::{ - profile, ProfilerCategory, TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType, + ProfilerCategory, TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType, }; +use profile_traits::time_profile; use script_traits::DocumentActivity; use servo_config::pref; use servo_url::ServoUrl; @@ -521,17 +522,32 @@ impl ServoParser { iframe: TimerMetadataFrameType::RootWindow, incremental: TimerMetadataReflowType::FirstReflow, }; - let profiler_category = self.tokenizer.profiler_category(); - profile( - profiler_category, - Some(metadata), - self.document - .window() - .upcast::<GlobalScope>() - .time_profiler_chan() - .clone(), - || self.do_parse_sync(can_gc), - ) + let profiler_chan = self + .document + .window() + .upcast::<GlobalScope>() + .time_profiler_chan() + .clone(); + match self.tokenizer { + Tokenizer::Html(_) => time_profile!( + ProfilerCategory::ScriptParseHTML, + Some(metadata), + profiler_chan, + || self.do_parse_sync(can_gc), + ), + Tokenizer::AsyncHtml(_) => time_profile!( + ProfilerCategory::ScriptParseHTML, + Some(metadata), + profiler_chan, + || self.do_parse_sync(can_gc), + ), + Tokenizer::Xml(_) => time_profile!( + ProfilerCategory::ScriptParseXML, + Some(metadata), + profiler_chan, + || self.do_parse_sync(can_gc), + ), + } } fn do_parse_sync(&self, can_gc: CanGc) { @@ -720,14 +736,6 @@ impl Tokenizer { Tokenizer::Xml(_) => unimplemented!(), } } - - fn profiler_category(&self) -> ProfilerCategory { - match *self { - Tokenizer::Html(_) => ProfilerCategory::ScriptParseHTML, - Tokenizer::AsyncHtml(_) => ProfilerCategory::ScriptParseHTML, - Tokenizer::Xml(_) => ProfilerCategory::ScriptParseXML, - } - } } /// The context required for asynchronously fetching a document diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 6d747b8111d..3d000e23cd5 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -74,7 +74,8 @@ use net_traits::{ }; use percent_encoding::percent_decode; use profile_traits::mem::{self as profile_mem, OpaqueSender, ReportsChan}; -use profile_traits::time::{self as profile_time, profile, ProfilerCategory}; +use profile_traits::time::{self as profile_time, ProfilerCategory}; +use profile_traits::time_profile; use script_layout_interface::{ node_id_from_scroll_id, LayoutConfig, LayoutFactory, ReflowGoal, ScriptThreadFactory, }; @@ -2165,48 +2166,126 @@ impl ScriptThread { self.notify_activity_to_hang_monitor(&category); let start = Instant::now(); let value = if self.profile_script_events { - let profiler_cat = match category { - ScriptThreadEventCategory::AttachLayout => ProfilerCategory::ScriptAttachLayout, - ScriptThreadEventCategory::ConstellationMsg => { - ProfilerCategory::ScriptConstellationMsg + let profiler_chan = self.time_profiler_chan.clone(); + match category { + ScriptThreadEventCategory::AttachLayout => { + time_profile!(ProfilerCategory::ScriptAttachLayout, None, profiler_chan, f) }, - ScriptThreadEventCategory::DevtoolsMsg => ProfilerCategory::ScriptDevtoolsMsg, - ScriptThreadEventCategory::DocumentEvent => ProfilerCategory::ScriptDocumentEvent, - ScriptThreadEventCategory::DomEvent => ProfilerCategory::ScriptDomEvent, - ScriptThreadEventCategory::FileRead => ProfilerCategory::ScriptFileRead, - ScriptThreadEventCategory::FormPlannedNavigation => { - ProfilerCategory::ScriptPlannedNavigation + ScriptThreadEventCategory::ConstellationMsg => time_profile!( + ProfilerCategory::ScriptConstellationMsg, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::DevtoolsMsg => { + time_profile!(ProfilerCategory::ScriptDevtoolsMsg, None, profiler_chan, f) }, - ScriptThreadEventCategory::HistoryEvent => ProfilerCategory::ScriptHistoryEvent, - ScriptThreadEventCategory::ImageCacheMsg => ProfilerCategory::ScriptImageCacheMsg, - ScriptThreadEventCategory::InputEvent => ProfilerCategory::ScriptInputEvent, - ScriptThreadEventCategory::NetworkEvent => ProfilerCategory::ScriptNetworkEvent, - ScriptThreadEventCategory::PortMessage => ProfilerCategory::ScriptPortMessage, - ScriptThreadEventCategory::Resize => ProfilerCategory::ScriptResize, - ScriptThreadEventCategory::ScriptEvent => ProfilerCategory::ScriptEvent, - ScriptThreadEventCategory::SetScrollState => ProfilerCategory::ScriptSetScrollState, - ScriptThreadEventCategory::UpdateReplacedElement => { - ProfilerCategory::ScriptUpdateReplacedElement + ScriptThreadEventCategory::DocumentEvent => time_profile!( + ProfilerCategory::ScriptDocumentEvent, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::DomEvent => { + time_profile!(ProfilerCategory::ScriptDomEvent, None, profiler_chan, f) }, - ScriptThreadEventCategory::StylesheetLoad => ProfilerCategory::ScriptStylesheetLoad, - ScriptThreadEventCategory::SetViewport => ProfilerCategory::ScriptSetViewport, - ScriptThreadEventCategory::TimerEvent => ProfilerCategory::ScriptTimerEvent, - ScriptThreadEventCategory::WebSocketEvent => ProfilerCategory::ScriptWebSocketEvent, - ScriptThreadEventCategory::WorkerEvent => ProfilerCategory::ScriptWorkerEvent, - ScriptThreadEventCategory::WorkletEvent => ProfilerCategory::ScriptWorkletEvent, - ScriptThreadEventCategory::ServiceWorkerEvent => { - ProfilerCategory::ScriptServiceWorkerEvent + ScriptThreadEventCategory::FileRead => { + time_profile!(ProfilerCategory::ScriptFileRead, None, profiler_chan, f) }, - ScriptThreadEventCategory::EnterFullscreen => { - ProfilerCategory::ScriptEnterFullscreen + ScriptThreadEventCategory::FormPlannedNavigation => time_profile!( + ProfilerCategory::ScriptPlannedNavigation, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::HistoryEvent => { + time_profile!(ProfilerCategory::ScriptHistoryEvent, None, profiler_chan, f) }, - ScriptThreadEventCategory::ExitFullscreen => ProfilerCategory::ScriptExitFullscreen, - ScriptThreadEventCategory::PerformanceTimelineTask => { - ProfilerCategory::ScriptPerformanceEvent + ScriptThreadEventCategory::ImageCacheMsg => time_profile!( + ProfilerCategory::ScriptImageCacheMsg, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::InputEvent => { + time_profile!(ProfilerCategory::ScriptInputEvent, None, profiler_chan, f) }, - ScriptThreadEventCategory::WebGPUMsg => ProfilerCategory::ScriptWebGPUMsg, - }; - profile(profiler_cat, None, self.time_profiler_chan.clone(), f) + ScriptThreadEventCategory::NetworkEvent => { + time_profile!(ProfilerCategory::ScriptNetworkEvent, None, profiler_chan, f) + }, + ScriptThreadEventCategory::PortMessage => { + time_profile!(ProfilerCategory::ScriptPortMessage, None, profiler_chan, f) + }, + ScriptThreadEventCategory::Resize => { + time_profile!(ProfilerCategory::ScriptResize, None, profiler_chan, f) + }, + ScriptThreadEventCategory::ScriptEvent => { + time_profile!(ProfilerCategory::ScriptEvent, None, profiler_chan, f) + }, + ScriptThreadEventCategory::SetScrollState => time_profile!( + ProfilerCategory::ScriptSetScrollState, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::UpdateReplacedElement => time_profile!( + ProfilerCategory::ScriptUpdateReplacedElement, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::StylesheetLoad => time_profile!( + ProfilerCategory::ScriptStylesheetLoad, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::SetViewport => { + time_profile!(ProfilerCategory::ScriptSetViewport, None, profiler_chan, f) + }, + ScriptThreadEventCategory::TimerEvent => { + time_profile!(ProfilerCategory::ScriptTimerEvent, None, profiler_chan, f) + }, + ScriptThreadEventCategory::WebSocketEvent => time_profile!( + ProfilerCategory::ScriptWebSocketEvent, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::WorkerEvent => { + time_profile!(ProfilerCategory::ScriptWorkerEvent, None, profiler_chan, f) + }, + ScriptThreadEventCategory::WorkletEvent => { + time_profile!(ProfilerCategory::ScriptWorkletEvent, None, profiler_chan, f) + }, + ScriptThreadEventCategory::ServiceWorkerEvent => time_profile!( + ProfilerCategory::ScriptServiceWorkerEvent, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::EnterFullscreen => time_profile!( + ProfilerCategory::ScriptEnterFullscreen, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::ExitFullscreen => time_profile!( + ProfilerCategory::ScriptExitFullscreen, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::PerformanceTimelineTask => time_profile!( + ProfilerCategory::ScriptPerformanceEvent, + None, + profiler_chan, + f + ), + ScriptThreadEventCategory::WebGPUMsg => { + time_profile!(ProfilerCategory::ScriptWebGPUMsg, None, profiler_chan, f) + }, + } } else { f() }; |