From 1c62d6d061c4239889f95e64f37c7fdb40d68f65 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Mon, 6 Mar 2023 18:50:11 +0100 Subject: [PATCH] debug: Add actual profiling for rendeirng --- Cargo.lock | 137 +++++++++++++++++++++++++++++ Cargo.toml | 4 +- src/backend/render/cursor.rs | 5 ++ src/backend/render/mod.rs | 8 ++ src/input/mod.rs | 1 + src/shell/layout/floating/mod.rs | 6 ++ src/shell/layout/tiling/mod.rs | 9 ++ src/shell/mod.rs | 3 + src/shell/workspace.rs | 6 ++ src/wayland/handlers/screencopy.rs | 6 ++ 10 files changed, 184 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 6f11eda0..3ff1265f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -184,6 +184,15 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -277,6 +286,9 @@ name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cfg-if" @@ -415,6 +427,8 @@ dependencies = [ "log-panics", "ordered-float", "png", + "puffin", + "puffin_egui", "regex", "renderdoc", "ron 0.7.1", @@ -1663,6 +1677,7 @@ checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", + "serde", ] [[package]] @@ -1721,6 +1736,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.1.22" @@ -2076,6 +2100,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "natord" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308d96db8debc727c3fd9744aac51751243420e46edf401010908da7f8d5e57c" + [[package]] name = "ndk" version = "0.7.0" @@ -2635,6 +2665,39 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74605f360ce573babfe43964cbe520294dcb081afbf8c108fc6e23036b4da2df" +[[package]] +name = "puffin" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7b2c7a01f569fb03e2ff1f5376537f294001447bd23ce75ca51054fcd223fe4" +dependencies = [ + "anyhow", + "bincode", + "byteorder", + "instant", + "once_cell", + "parking_lot 0.12.1", + "ruzstd", + "serde", + "zstd", +] + +[[package]] +name = "puffin_egui" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba98235ecff9f174793e135d2c6860f917cc7cd419a630b9978f1ab5d6026a3c" +dependencies = [ + "egui", + "indexmap", + "instant", + "natord", + "once_cell", + "puffin", + "time", + "vec1", +] + [[package]] name = "quick-xml" version = "0.23.1" @@ -2992,6 +3055,17 @@ dependencies = [ "unicode-script", ] +[[package]] +name = "ruzstd" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffae8df4aa221781b715c27bbed0fac16b6f1e2643efb7af8a24dfc78d444493" +dependencies = [ + "byteorder", + "thiserror", + "twox-hash", +] + [[package]] name = "ryu" version = "1.0.12" @@ -3445,6 +3519,33 @@ dependencies = [ "weezl", ] +[[package]] +name = "time" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" +dependencies = [ + "itoa", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "time-macros" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" +dependencies = [ + "time-core", +] + [[package]] name = "tiny-skia" version = "0.6.6" @@ -3761,6 +3862,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vec1" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bda7c41ca331fe9a1c278a9e7ee055f4be7f5eb1c2b72f079b4ff8b5fce9d5c" + [[package]] name = "vec_map" version = "0.8.2" @@ -4483,6 +4590,36 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c110ba09c9b3a43edd4803d570df0da2414fed6e822e22b976a4e3ef50860701" +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.7+zstd.1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "zune-inflate" version = "0.2.50" diff --git a/Cargo.toml b/Cargo.toml index 17a3ac6a..ac586086 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,8 @@ glow = "0.11.2" tracing-subscriber = { version = "0.3.16", features = ["env-filter", "tracing-log"] } tracing-journald = "0.3.0" tracing = { version = "0.1.37", features = ["max_level_debug", "release_max_level_info"] } +puffin = { version = "0.14.3", optional = true } +puffin_egui = { version = "0.19.2", optional = true } [dependencies.smithay] version = "0.3" @@ -54,8 +56,8 @@ optional = true [features] default = ["systemd"] -debug = ["egui", "smithay-egui", "renderdoc", "anyhow/backtrace"] systemd = ["libsystemd"] +debug = ["egui", "smithay-egui", "renderdoc", "puffin", "puffin_egui", "anyhow/backtrace"] [profile.dev] lto = "thin" diff --git a/src/backend/render/cursor.rs b/src/backend/render/cursor.rs index 606b5fbb..4e430702 100644 --- a/src/backend/render/cursor.rs +++ b/src/backend/render/cursor.rs @@ -172,6 +172,9 @@ where R: Renderer + ImportAll, ::TextureId: 'static, { + #[cfg(feature = "debug")] + puffin::profile_function!(); + if get_role(&surface) != Some("dnd_icon") { warn!( ?surface, @@ -215,6 +218,8 @@ where R: Renderer + ImportMem + ImportAll, ::TextureId: Clone + 'static, { + #[cfg(feature = "debug")] + puffin::profile_function!(); // draw the cursor as relevant // reset the cursor if the surface is no longer alive let cursor_status = seat diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index bfc378b0..b940909d 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -168,6 +168,9 @@ where CosmicMappedRenderElement: RenderElement, E: From> + From>, { + #[cfg(feature = "debug")] + puffin::profile_function!(); + let scale = output.current_scale().fractional_scale(); let mut elements = Vec::new(); @@ -293,6 +296,9 @@ where CosmicMappedRenderElement: RenderElement, Source: Clone, { + #[cfg(feature = "debug")] + puffin::profile_function!(); + if let Some(ref mut fps) = fps { fps.start(); #[cfg(feature = "debug")] @@ -448,6 +454,8 @@ where std::ptr::null(), ); } + + puffin::GlobalProfiler::lock().new_frame(); } res diff --git a/src/input/mod.rs b/src/input/mod.rs index 3108f68d..fe9bd894 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -648,6 +648,7 @@ impl State { #[cfg(feature = "debug")] Action::Debug => { self.common.egui.active = !self.common.egui.active; + puffin::set_scopes_on(self.common.egui.active); for mapped in self .common .shell diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index c4f8c8fb..ddcb5f59 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -257,6 +257,9 @@ impl FloatingLayout { } pub fn refresh(&mut self) { + #[cfg(feature = "debug")] + puffin::profile_function!(); + self.space.refresh(); for element in self .space @@ -352,6 +355,9 @@ impl FloatingLayout { ::TextureId: 'static, CosmicMappedRenderElement: RenderElement, { + #[cfg(feature = "debug")] + puffin::profile_function!(); + let output_scale = output.current_scale().fractional_scale(); self.space .elements_for_output(output) diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 0f357287..e2b97cda 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -896,6 +896,9 @@ impl TilingLayout { } pub fn refresh<'a>(&mut self) { + #[cfg(feature = "debug")] + puffin::profile_function!(); + let dead_windows = self .mapped() .map(|(_, w, _)| w.clone()) @@ -1107,6 +1110,9 @@ impl TilingLayout { } fn update_space_positions(trees: &mut HashMap>, gaps: (i32, i32)) { + #[cfg(feature = "debug")] + puffin::profile_function!(); + let (outer, inner) = gaps; for (output, tree) in trees .iter_mut() @@ -1306,6 +1312,9 @@ impl TilingLayout { ::TextureId: 'static, CosmicMappedRenderElement: RenderElement, { + #[cfg(feature = "debug")] + puffin::profile_function!(); + let output_scale = output.current_scale().fractional_scale(); if !self.trees.contains_key(output) { diff --git a/src/shell/mod.rs b/src/shell/mod.rs index aa906326..7e50a175 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1008,6 +1008,9 @@ impl Shell { } pub fn refresh(&mut self) { + #[cfg(feature = "debug")] + puffin::profile_function!(); + self.popups.cleanup(); match &mut self.workspaces { diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index b6830828..1f292136 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -77,6 +77,9 @@ impl Workspace { } pub fn refresh(&mut self) { + #[cfg(feature = "debug")] + puffin::profile_function!(); + self.fullscreen.retain(|_, w| w.alive()); self.floating_layer.refresh(); self.tiling_layer.refresh(); @@ -443,6 +446,9 @@ impl Workspace { ::TextureId: 'static, CosmicMappedRenderElement: RenderElement, { + #[cfg(feature = "debug")] + puffin::profile_function!(); + let mut render_elements = Vec::new(); let output_scale = output.current_scale().fractional_scale(); diff --git a/src/wayland/handlers/screencopy.rs b/src/wayland/handlers/screencopy.rs index eb2e7dbb..ba0cebea 100644 --- a/src/wayland/handlers/screencopy.rs +++ b/src/wayland/handlers/screencopy.rs @@ -561,6 +561,9 @@ where DamageTrackedRendererError, >, { + #[cfg(feature = "debug")] + puffin::profile_function!(); + let mut dtr = session .user_data() .get::() @@ -861,6 +864,9 @@ pub fn render_window_to_buffer( params: BufferParams, window: &CosmicSurface, ) -> Result { + #[cfg(feature = "debug")] + puffin::profile_function!(); + let geometry = window.geometry(); let buffer_size = buffer_dimensions(¶ms.buffer).unwrap(); if buffer_size != geometry.size.to_buffer(1, Transform::Normal) {