Plumb time profiler output into tracing (#34238)

* Plumb time profiler output into tracing

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

* Enter the span tightly around the callback

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

* Use `info_span!()` shorthand

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

---------

Signed-off-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
Delan Azabani 2024-11-15 17:10:01 +08:00 committed by GitHub
parent 495cceb7de
commit aa7116c75d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 279 additions and 82 deletions

View file

@ -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()
};