canvas: trace/instrument canvas messages processing (#38600)

Add some tracing/instrumenting for canvas messages processing.

Testing: We have not tests for tracing code.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-08-11 20:21:49 +02:00 committed by GitHub
parent 3f7f9ba6cd
commit 68ad03c40a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 23 additions and 4 deletions

2
Cargo.lock generated
View file

@ -1082,9 +1082,11 @@ dependencies = [
"pollster",
"range",
"raqote",
"servo-tracing",
"servo_arc",
"servo_config",
"stylo",
"tracing",
"unicode-script",
"vello",
"vello_cpu",

View file

@ -15,6 +15,7 @@ path = "lib.rs"
vello = ["dep:vello", "dep:pollster", "dep:futures-intrusive", "dep:peniko"]
vello_cpu = ["dep:vello_cpu", "dep:peniko"]
raqote = ["dep:raqote", "dep:font-kit"]
tracing = ["dep:tracing"]
[dependencies]
app_units = { workspace = true }
@ -43,3 +44,6 @@ vello = { workspace = true, optional = true }
vello_cpu = { workspace = true, optional = true }
pollster = { version = "0.4", optional = true }
futures-intrusive = { version = "0.5", optional = true }
tracing = { workspace = true, optional = true }
servo-tracing = { workspace = true }

View file

@ -641,7 +641,15 @@ impl<DrawTarget: GenericDrawTarget> CanvasData<DrawTarget> {
/// Update image in WebRender
pub(crate) fn update_image_rendering(&mut self) {
let (descriptor, data) = self.drawtarget.image_descriptor_and_serializable_data();
let (descriptor, data) = {
#[cfg(feature = "tracing")]
let _span = tracing::trace_span!(
"image_descriptor_and_serializable_data",
servo_profiling = true,
)
.entered();
self.drawtarget.image_descriptor_and_serializable_data()
};
self.compositor_api
.update_image(self.image_key, descriptor, data);
@ -732,7 +740,7 @@ impl<DrawTarget: GenericDrawTarget> CanvasData<DrawTarget> {
/// It reads image data from the canvas
/// canvas_size: The size of the canvas we're reading from
/// read_rect: The area of the canvas we want to read from
#[allow(unsafe_code)]
#[servo_tracing::instrument(skip_all)]
pub(crate) fn read_pixels(&mut self, read_rect: Option<Rect<u32>>) -> Snapshot {
let canvas_size = self.drawtarget.get_size().cast();

View file

@ -106,6 +106,7 @@ impl CanvasPaintThread {
(create_sender, ipc_sender)
}
#[servo_tracing::instrument(skip_all)]
pub fn create_canvas(&mut self, size: Size2D<u64>) -> Option<(CanvasId, ImageKey)> {
let canvas_id = self.next_canvas_id;
self.next_canvas_id.0 += 1;
@ -117,6 +118,10 @@ impl CanvasPaintThread {
Some((canvas_id, image_key))
}
#[servo_tracing::instrument(
skip_all,
fields(message = message.to_string())
)]
fn process_canvas_2d_message(&mut self, message: Canvas2dMsg, canvas_id: CanvasId) {
match message {
Canvas2dMsg::FillText(

View file

@ -14,7 +14,7 @@ path = "lib.rs"
[features]
bluetooth = ["bluetooth_traits"]
default = []
tracing = ["dep:tracing"]
tracing = ["dep:tracing", "canvas/tracing"]
webgpu = ["script_traits/webgpu"]
vello = ["canvas/vello"]
vello_cpu = ["canvas/vello_cpu"]

View file

@ -453,7 +453,7 @@ pub enum CanvasMsg {
Close(CanvasId),
}
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, strum::Display)]
pub enum Canvas2dMsg {
DrawImage(
IpcSnapshot,