From 0f24b8c823ec57a6fad309dda4c36dbaab604e89 Mon Sep 17 00:00:00 2001 From: atbrakhi Date: Thu, 5 Sep 2024 14:11:12 +0200 Subject: [PATCH] Add tracing events (#33189) Signed-off-by: atbrakhi --- Cargo.lock | 3 +++ components/compositing/Cargo.toml | 1 + components/compositing/compositor.rs | 12 ++++++++++++ components/constellation/Cargo.toml | 1 + components/constellation/constellation.rs | 4 ++++ components/servo/Cargo.toml | 1 + components/servo/lib.rs | 1 + components/shared/compositing/lib.rs | 11 +++++++++++ 8 files changed, 34 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 84eb863e5d0..7df4ba904b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -911,6 +911,7 @@ dependencies = [ "style_traits", "surfman", "time 0.1.45", + "tracing", "webrender", "webrender_api", "webrender_traits", @@ -980,6 +981,7 @@ dependencies = [ "servo_rand", "servo_url", "style_traits", + "tracing", "webgpu", "webrender", "webrender_api", @@ -3991,6 +3993,7 @@ dependencies = [ "style", "style_traits", "surfman", + "tracing", "webdriver_server", "webgpu", "webrender", diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml index 954d8a40897..b35bcb330b5 100644 --- a/components/compositing/Cargo.toml +++ b/components/compositing/Cargo.toml @@ -41,6 +41,7 @@ servo_geometry = { path = "../geometry" } servo_url = { path = "../url" } style_traits = { workspace = true } time = { workspace = true } +tracing = { workspace = true } webrender = { workspace = true } webrender_api = { workspace = true } webrender_traits = { workspace = true } diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 6e6b403a1a9..931095e38b6 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -34,6 +34,7 @@ use script_traits::{ }; use servo_geometry::{DeviceIndependentPixel, FramebufferUintLength}; use style_traits::{CSSPixel, DevicePixel, PinchZoomFactor}; +use tracing::{span, Level}; use webrender::{CaptureBits, RenderApi, Transaction}; use webrender_api::units::{ DeviceIntPoint, DeviceIntSize, DevicePoint, DeviceRect, LayoutPoint, LayoutRect, LayoutSize, @@ -680,6 +681,7 @@ impl IOCompositor { /// Accept messages from content processes that need to be relayed to the WebRender /// instance in the parent process. + #[tracing::instrument(skip(self))] fn handle_webrender_message(&mut self, msg: ForwardedToCompositorMsg) { match msg { ForwardedToCompositorMsg::Layout(ScriptToCompositorMsg::SendInitialTransaction( @@ -767,6 +769,8 @@ impl IOCompositor { display_list_descriptor, ); + let span = span!(Level::TRACE, "ScriptToCompositorMsg::BuiltDisplayList"); + let _enter = span.enter(); let pipeline_id = display_list_info.pipeline_id; let details = self.pipeline_details(pipeline_id.into()); details.most_recent_display_list_epoch = Some(display_list_info.epoch); @@ -2053,6 +2057,7 @@ impl IOCompositor { /// Returns Ok if composition was performed or Err if it was not possible to composite for some /// reason. When the target is [CompositeTarget::SharedMemory], the image is read back from the /// GPU and returned as Ok(Some(png::Image)), otherwise we return Ok(None). + #[tracing::instrument(skip(self))] fn composite_specific_target( &mut self, target: CompositeTarget, @@ -2268,6 +2273,8 @@ impl IOCompositor { }, }; + let span = span!(Level::TRACE, "ConstellationMsg::ReadyToPresent"); + let _enter = span.enter(); // Notify embedder that servo is ready to present. // Embedder should call `present` to tell compositor to continue rendering. self.waiting_on_present = true; @@ -2292,7 +2299,10 @@ impl IOCompositor { .map(|info| info.framebuffer_id()) } + #[tracing::instrument(skip(self))] pub fn present(&mut self) { + let span = span!(Level::TRACE, "Compositor Present Surface"); + let _enter = span.enter(); if let Err(err) = self.rendering_context.present() { warn!("Failed to present surface: {:?}", err); } @@ -2354,6 +2364,7 @@ impl IOCompositor { ); } + #[tracing::instrument(skip(self))] pub fn receive_messages(&mut self) -> bool { // Check for new messages coming from the other threads in the system. let mut compositor_messages = vec![]; @@ -2380,6 +2391,7 @@ impl IOCompositor { true } + #[tracing::instrument(skip(self))] pub fn perform_updates(&mut self) -> bool { if self.shutdown_state == ShutdownState::FinishedShuttingDown { return false; diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index 0411ad9db12..783ea93fee1 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -48,6 +48,7 @@ webgpu = { path = "../webgpu" } webrender = { workspace = true } webrender_api = { workspace = true } webrender_traits = { workspace = true } +tracing = { workspace = true } webxr-api = { git = "https://github.com/servo/webxr", features = ["ipc"] } [target.'cfg(any(target_os="macos", all(not(target_os = "windows"), not(target_os = "ios"), not(target_os="android"), not(target_arch="arm"), not(target_arch="aarch64"))))'.dependencies] diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 9005f11a8db..8e14e8936b3 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -152,6 +152,7 @@ use servo_config::{opts, pref}; use servo_rand::{random, Rng, ServoRng, SliceRandom}; use servo_url::{Host, ImmutableOrigin, ServoUrl}; use style_traits::CSSPixel; +use tracing::{span, Level}; use webgpu::{self, WebGPU, WebGPURequest, WebGPUResponse}; use webrender::{RenderApi, RenderApiSender}; use webrender_api::DocumentId; @@ -1331,6 +1332,7 @@ where } } + #[tracing::instrument(skip(self))] fn handle_request_from_compositor(&mut self, message: FromCompositorMsg) { trace_msg_from_compositor!(message, "{message:?}"); match message { @@ -1543,6 +1545,8 @@ where self.set_webview_throttled(webview_id, throttled); }, FromCompositorMsg::ReadyToPresent(webview_ids) => { + let span = span!(Level::TRACE, "FromCompositorMsg::ReadyToPresent"); + let _enter = span.enter(); self.embedder_proxy .send((None, EmbedderMsg::ReadyToPresent(webview_ids))); }, diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index 3107e8c74ba..75a74703666 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -81,6 +81,7 @@ webgpu = { path = "../webgpu" } webrender = { workspace = true } webrender_api = { workspace = true } webrender_traits = { workspace = true } +tracing = { workspace = true } webxr = { git = "https://github.com/servo/webxr" } webxr-api = { git = "https://github.com/servo/webxr" } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 69a25aebd13..5231ce8010e 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -225,6 +225,7 @@ impl Servo where Window: WindowMethods + 'static + ?Sized, { + #[tracing::instrument(skip(embedder, window))] pub fn new( mut embedder: Box, window: Rc, diff --git a/components/shared/compositing/lib.rs b/components/shared/compositing/lib.rs index 171b0676c2d..ccf24d0aabe 100644 --- a/components/shared/compositing/lib.rs +++ b/components/shared/compositing/lib.rs @@ -145,6 +145,17 @@ pub enum ForwardedToCompositorMsg { Canvas(CanvasToCompositorMsg), } +impl Debug for ForwardedToCompositorMsg { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { + match self { + ForwardedToCompositorMsg::Layout(_) => write!(f, "Layout(ScriptToCompositorMsg)"), + ForwardedToCompositorMsg::Net(_) => write!(f, "Net(NetToCompositorMsg)"), + ForwardedToCompositorMsg::Font(_) => write!(f, "Font(FontToCompositorMsg)"), + ForwardedToCompositorMsg::Canvas(_) => write!(f, "Canvas(CanvasToCompositorMsg)"), + } + } +} + impl Debug for CompositorMsg { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { match *self {