aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/compositing/compositor.rs7
-rw-r--r--components/layout/Cargo.toml4
-rw-r--r--components/layout/parallel.rs5
-rw-r--r--components/layout_thread/Cargo.toml4
-rw-r--r--components/layout_thread/lib.rs20
-rw-r--r--components/layout_thread_2020/lib.rs6
-rw-r--r--components/script/Cargo.toml2
-rw-r--r--components/script/dom/globalscope.rs4
-rw-r--r--components/script/dom/servoparser/mod.rs48
-rw-r--r--components/script/script_thread.rs153
-rw-r--r--components/servo/Cargo.toml2
-rw-r--r--components/shared/profile/Cargo.toml4
-rw-r--r--components/shared/profile/ipc.rs6
-rw-r--r--components/shared/profile/lib.rs14
-rw-r--r--components/shared/profile/time.rs78
15 files changed, 275 insertions, 82 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs
index 08df16515cd..0a6d764c722 100644
--- a/components/compositing/compositor.rs
+++ b/components/compositing/compositor.rs
@@ -27,7 +27,8 @@ use ipc_channel::ipc::{self, IpcSharedMemory};
use libc::c_void;
use log::{debug, error, info, trace, warn};
use pixels::{CorsStatus, Image, PixelFormat};
-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_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent, TouchEvent, WheelEvent};
use script_traits::{
AnimationState, AnimationTickType, ConstellationControlMsg, MouseButton, MouseEventType,
@@ -2098,7 +2099,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
self.assert_gl_framebuffer_complete();
}
- profile(
+ time_profile!(
ProfilerCategory::Compositing,
None,
self.time_profiler_chan.clone(),
@@ -2214,7 +2215,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
})
},
CompositeTarget::PngFile(path) => {
- profile(
+ time_profile!(
ProfilerCategory::ImageSaving,
None,
self.time_profiler_chan.clone(),
diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml
index 797aac24cfa..cf7617790f8 100644
--- a/components/layout/Cargo.toml
+++ b/components/layout/Cargo.toml
@@ -13,6 +13,9 @@ path = "lib.rs"
test = true
doctest = false
+[features]
+tracing = ["dep:tracing"]
+
[dependencies]
app_units = { workspace = true }
atomic_refcell = { workspace = true }
@@ -47,6 +50,7 @@ servo_url = { path = "../url" }
smallvec = { workspace = true, features = ["union"] }
style = { workspace = true }
style_traits = { workspace = true }
+tracing = { workspace = true, optional = true }
unicode-bidi = { workspace = true, features = ["with_serde"] }
unicode-script = { workspace = true }
webrender_api = { workspace = true }
diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs
index 26d7d429a25..4b3f5c694c5 100644
--- a/components/layout/parallel.rs
+++ b/components/layout/parallel.rs
@@ -11,7 +11,8 @@
use std::sync::atomic::{AtomicIsize, Ordering};
use std::{mem, ptr};
-use profile_traits::time::{self, profile, TimerMetadata};
+use profile_traits::time::{self, TimerMetadata};
+use profile_traits::time_profile;
use servo_config::opts;
use smallvec::SmallVec;
@@ -229,7 +230,7 @@ pub fn reflow(
queue.install(move || {
rayon::scope_fifo(move |scope| {
- profile(
+ time_profile!(
time::ProfilerCategory::LayoutParallelWarmup,
profiler_metadata,
time_profiler_chan,
diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml
index e002ebbba0d..2920b0cd436 100644
--- a/components/layout_thread/Cargo.toml
+++ b/components/layout_thread/Cargo.toml
@@ -11,6 +11,9 @@ rust-version.workspace = true
name = "layout_thread_2013"
path = "lib.rs"
+[features]
+tracing = ["dep:tracing", "layout/tracing"]
+
[dependencies]
app_units = { workspace = true }
base = { workspace = true }
@@ -42,6 +45,7 @@ servo_url = { path = "../url" }
style = { workspace = true }
style_traits = { workspace = true }
time_03 = { workspace = true }
+tracing = { workspace = true, optional = true }
url = { workspace = true }
webrender_api = { workspace = true }
webrender_traits = { workspace = true }
diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs
index a1948f1ce65..61e718babde 100644
--- a/components/layout_thread/lib.rs
+++ b/components/layout_thread/lib.rs
@@ -55,10 +55,10 @@ use net_traits::image_cache::{ImageCache, UsePlaceholder};
use net_traits::ResourceThreads;
use parking_lot::RwLock;
use profile_traits::mem::{Report, ReportKind};
-use profile_traits::path;
use profile_traits::time::{
- self as profile_time, profile, TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType,
+ self as profile_time, TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType,
};
+use profile_traits::{path, time_profile};
use script::layout_dom::{ServoLayoutDocument, ServoLayoutElement, ServoLayoutNode};
use script_layout_interface::wrapper_traits::LayoutNode;
use script_layout_interface::{
@@ -528,7 +528,7 @@ impl Layout for LayoutThread {
fn reflow(&mut self, script_reflow: script_layout_interface::ScriptReflow) {
let mut result = ScriptReflowResult::new(script_reflow);
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutPerform,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
@@ -838,7 +838,7 @@ impl LayoutThread {
) {
let writing_mode = layout_root.base().writing_mode;
let (metadata, sender) = (self.profiler_metadata(), self.time_profiler_chan.clone());
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutDispListBuild,
metadata.clone(),
sender.clone(),
@@ -1103,7 +1103,7 @@ impl LayoutThread {
if token.should_traverse() {
// Recalculate CSS styles and rebuild flows and fragments.
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutStyleRecalc,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
@@ -1248,7 +1248,7 @@ impl LayoutThread {
FlowRef::deref_mut(root_flow),
);
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutRestyleDamagePropagation,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
@@ -1270,7 +1270,7 @@ impl LayoutThread {
}
// Resolve generated content.
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutGeneratedContent,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
@@ -1278,7 +1278,7 @@ impl LayoutThread {
);
// Guess float placement.
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutFloatPlacementSpeculation,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
@@ -1292,7 +1292,7 @@ impl LayoutThread {
.restyle_damage
.intersects(ServoRestyleDamage::REFLOW | ServoRestyleDamage::REFLOW_OUT_OF_FLOW)
{
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutMain,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
@@ -1316,7 +1316,7 @@ impl LayoutThread {
);
}
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutStoreOverflow,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs
index f61dd4d2e76..fb28b16a08f 100644
--- a/components/layout_thread_2020/lib.rs
+++ b/components/layout_thread_2020/lib.rs
@@ -43,10 +43,10 @@ use net_traits::image_cache::{ImageCache, UsePlaceholder};
use net_traits::ResourceThreads;
use parking_lot::{Mutex, RwLock};
use profile_traits::mem::{Report, ReportKind};
-use profile_traits::path;
use profile_traits::time::{
- self as profile_time, profile, TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType,
+ self as profile_time, TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType,
};
+use profile_traits::{path, time_profile};
use script::layout_dom::{ServoLayoutDocument, ServoLayoutElement, ServoLayoutNode};
use script_layout_interface::{
Layout, LayoutConfig, LayoutFactory, NodesFromPointQueryType, OffsetParentResponse,
@@ -500,7 +500,7 @@ impl Layout for LayoutThread {
fn reflow(&mut self, script_reflow: ScriptReflow) {
let mut result = ScriptReflowResult::new(script_reflow);
- profile(
+ time_profile!(
profile_time::ProfilerCategory::LayoutPerform,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
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()
};
diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml
index 1f04ee2cf30..cb9ab215f82 100644
--- a/components/servo/Cargo.toml
+++ b/components/servo/Cargo.toml
@@ -24,7 +24,7 @@ no-wgl = ["mozangle/egl", "mozangle/build_dlls", "surfman/sm-angle-default"]
dynamic_freetype = ["webrender/dynamic_freetype"]
profilemozjs = ["script/profilemozjs"]
refcell_backtrace = ["script/refcell_backtrace"]
-tracing = ["dep:tracing", "compositing/tracing", "constellation/tracing", "fonts/tracing", "layout_thread_2020/tracing"]
+tracing = ["dep:tracing", "compositing/tracing", "constellation/tracing", "fonts/tracing", "layout_thread_2013/tracing", "layout_thread_2020/tracing", "profile_traits/tracing", "script/tracing"]
webdriver = ["webdriver_server"]
webgl_backtrace = [
"script/webgl_backtrace",
diff --git a/components/shared/profile/Cargo.toml b/components/shared/profile/Cargo.toml
index ef18b8c20fa..37df0adf51d 100644
--- a/components/shared/profile/Cargo.toml
+++ b/components/shared/profile/Cargo.toml
@@ -11,6 +11,9 @@ rust-version.workspace = true
name = "profile_traits"
path = "lib.rs"
+[features]
+tracing = ["dep:tracing"]
+
[dependencies]
base = { workspace = true }
crossbeam-channel = { workspace = true }
@@ -20,3 +23,4 @@ serde = { workspace = true }
servo_config = { path = "../../config" }
signpost = { git = "https://github.com/pcwalton/signpost.git" }
time_03 = { workspace = true }
+tracing = { workspace = true, optional = true }
diff --git a/components/shared/profile/ipc.rs b/components/shared/profile/ipc.rs
index f9ee1a87141..ed7b2cd2a0a 100644
--- a/components/shared/profile/ipc.rs
+++ b/components/shared/profile/ipc.rs
@@ -7,8 +7,8 @@ use std::io::Error;
use ipc_channel::ipc;
use serde::{Deserialize, Serialize};
-use crate::time;
use crate::time::{ProfilerCategory, ProfilerChan};
+use crate::time_profile;
pub struct IpcReceiver<T>
where
@@ -23,7 +23,7 @@ where
T: for<'de> Deserialize<'de> + Serialize,
{
pub fn recv(&self) -> Result<T, ipc::IpcError> {
- time::profile(
+ time_profile!(
ProfilerCategory::IpcReceiver,
None,
self.time_profile_chan.clone(),
@@ -61,7 +61,7 @@ pub struct IpcBytesReceiver {
impl IpcBytesReceiver {
pub fn recv(&self) -> Result<Vec<u8>, ipc::IpcError> {
- time::profile(
+ time_profile!(
ProfilerCategory::IpcBytesReceiver,
None,
self.time_profile_chan.clone(),
diff --git a/components/shared/profile/lib.rs b/components/shared/profile/lib.rs
index 7be3d265d6c..fef2b255bea 100644
--- a/components/shared/profile/lib.rs
+++ b/components/shared/profile/lib.rs
@@ -11,3 +11,17 @@
pub mod ipc;
pub mod mem;
pub mod time;
+
+/// Measure the given callback with the time profiler and (if enabled) tracing.
+///
+/// `$category` must be const, because we use it to derive the span name.
+#[macro_export]
+macro_rules! time_profile {
+ ($category:expr, $meta:expr, $profiler_chan:expr, $($callback:tt)+) => {{
+ #[cfg(feature = "tracing")]
+ let span = tracing::info_span!($category.variant_name(), servo_profiling = true);
+ #[cfg(not(feature = "tracing"))]
+ let span = ();
+ $crate::time::profile($category, $meta, $profiler_chan, span, $($callback)+)
+ }};
+}
diff --git a/components/shared/profile/time.rs b/components/shared/profile/time.rs
index 62ac03f3e0f..f52b087095d 100644
--- a/components/shared/profile/time.rs
+++ b/components/shared/profile/time.rs
@@ -118,6 +118,71 @@ pub enum ProfilerCategory {
IpcBytesReceiver = 0x84,
}
+impl ProfilerCategory {
+ pub const fn variant_name(&self) -> &'static str {
+ match self {
+ ProfilerCategory::Compositing => "Compositing",
+ ProfilerCategory::LayoutPerform => "LayoutPerform",
+ ProfilerCategory::LayoutStyleRecalc => "LayoutStyleRecalc",
+ ProfilerCategory::LayoutTextShaping => "LayoutTextShaping",
+ ProfilerCategory::LayoutRestyleDamagePropagation => "LayoutRestyleDamagePropagation",
+ ProfilerCategory::LayoutNonIncrementalReset => "LayoutNonIncrementalReset",
+ ProfilerCategory::LayoutSelectorMatch => "LayoutSelectorMatch",
+ ProfilerCategory::LayoutTreeBuilder => "LayoutTreeBuilder",
+ ProfilerCategory::LayoutDamagePropagate => "LayoutDamagePropagate",
+ ProfilerCategory::LayoutGeneratedContent => "LayoutGeneratedContent",
+ ProfilerCategory::LayoutDisplayListSorting => "LayoutDisplayListSorting",
+ ProfilerCategory::LayoutFloatPlacementSpeculation => "LayoutFloatPlacementSpeculation",
+ ProfilerCategory::LayoutMain => "LayoutMain",
+ ProfilerCategory::LayoutStoreOverflow => "LayoutStoreOverflow",
+ ProfilerCategory::LayoutParallelWarmup => "LayoutParallelWarmup",
+ ProfilerCategory::LayoutDispListBuild => "LayoutDispListBuild",
+ ProfilerCategory::NetHTTPRequestResponse => "NetHTTPRequestResponse",
+ ProfilerCategory::PaintingPerTile => "PaintingPerTile",
+ ProfilerCategory::PaintingPrepBuff => "PaintingPrepBuff",
+ ProfilerCategory::Painting => "Painting",
+ ProfilerCategory::ImageDecoding => "ImageDecoding",
+ ProfilerCategory::ImageSaving => "ImageSaving",
+ ProfilerCategory::ScriptAttachLayout => "ScriptAttachLayout",
+ ProfilerCategory::ScriptConstellationMsg => "ScriptConstellationMsg",
+ ProfilerCategory::ScriptDevtoolsMsg => "ScriptDevtoolsMsg",
+ ProfilerCategory::ScriptDocumentEvent => "ScriptDocumentEvent",
+ ProfilerCategory::ScriptDomEvent => "ScriptDomEvent",
+ ProfilerCategory::ScriptEvaluate => "ScriptEvaluate",
+ ProfilerCategory::ScriptEvent => "ScriptEvent",
+ ProfilerCategory::ScriptFileRead => "ScriptFileRead",
+ ProfilerCategory::ScriptImageCacheMsg => "ScriptImageCacheMsg",
+ ProfilerCategory::ScriptInputEvent => "ScriptInputEvent",
+ ProfilerCategory::ScriptNetworkEvent => "ScriptNetworkEvent",
+ ProfilerCategory::ScriptParseHTML => "ScriptParseHTML",
+ ProfilerCategory::ScriptPlannedNavigation => "ScriptPlannedNavigation",
+ ProfilerCategory::ScriptResize => "ScriptResize",
+ ProfilerCategory::ScriptSetScrollState => "ScriptSetScrollState",
+ ProfilerCategory::ScriptSetViewport => "ScriptSetViewport",
+ ProfilerCategory::ScriptTimerEvent => "ScriptTimerEvent",
+ ProfilerCategory::ScriptStylesheetLoad => "ScriptStylesheetLoad",
+ ProfilerCategory::ScriptUpdateReplacedElement => "ScriptUpdateReplacedElement",
+ ProfilerCategory::ScriptWebSocketEvent => "ScriptWebSocketEvent",
+ ProfilerCategory::ScriptWorkerEvent => "ScriptWorkerEvent",
+ ProfilerCategory::ScriptServiceWorkerEvent => "ScriptServiceWorkerEvent",
+ ProfilerCategory::ScriptParseXML => "ScriptParseXML",
+ ProfilerCategory::ScriptEnterFullscreen => "ScriptEnterFullscreen",
+ ProfilerCategory::ScriptExitFullscreen => "ScriptExitFullscreen",
+ ProfilerCategory::ScriptWebVREvent => "ScriptWebVREvent",
+ ProfilerCategory::ScriptWorkletEvent => "ScriptWorkletEvent",
+ ProfilerCategory::ScriptPerformanceEvent => "ScriptPerformanceEvent",
+ ProfilerCategory::ScriptHistoryEvent => "ScriptHistoryEvent",
+ ProfilerCategory::ScriptPortMessage => "ScriptPortMessage",
+ ProfilerCategory::ScriptWebGPUMsg => "ScriptWebGPUMsg",
+ ProfilerCategory::TimeToFirstPaint => "TimeToFirstPaint",
+ ProfilerCategory::TimeToFirstContentfulPaint => "TimeToFirstContentfulPaint",
+ ProfilerCategory::TimeToInteractive => "TimeToInteractive",
+ ProfilerCategory::IpcReceiver => "IpcReceiver",
+ ProfilerCategory::IpcBytesReceiver => "IpcBytesReceiver",
+ }
+ }
+}
+
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
pub enum TimerMetadataFrameType {
RootWindow,
@@ -130,10 +195,17 @@ pub enum TimerMetadataReflowType {
FirstReflow,
}
+#[cfg(feature = "tracing")]
+pub type Span = tracing::Span;
+#[cfg(not(feature = "tracing"))]
+pub type Span = ();
+
pub fn profile<T, F>(
category: ProfilerCategory,
meta: Option<TimerMetadata>,
profiler_chan: ProfilerChan,
+ #[cfg(feature = "tracing")] span: Span,
+ #[cfg(not(feature = "tracing"))] _span: Span,
callback: F,
) -> T
where
@@ -143,7 +215,11 @@ where
signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]);
}
let start_time = CrossProcessInstant::now();
- let val = callback();
+ let val = {
+ #[cfg(feature = "tracing")]
+ let _enter = span.enter();
+ callback()
+ };
let end_time = CrossProcessInstant::now();
if opts::get().debug.signpost {