Add support for profiling using tracy

This commit is contained in:
Ian Douglas Scott 2023-10-07 19:15:44 -07:00 committed by Victoria Brekenfeld
parent 929f4fcb05
commit a1c8b3aa3e
18 changed files with 122 additions and 5 deletions

73
Cargo.lock generated
View file

@ -761,6 +761,7 @@ dependencies = [
"once_cell", "once_cell",
"ordered-float", "ordered-float",
"png", "png",
"profiling",
"puffin", "puffin",
"puffin_egui", "puffin_egui",
"regex", "regex",
@ -1888,6 +1889,19 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "generator"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e"
dependencies = [
"cc",
"libc",
"log",
"rustversion",
"windows 0.48.0",
]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.7" version = "0.14.7"
@ -2038,7 +2052,7 @@ dependencies = [
"presser", "presser",
"thiserror", "thiserror",
"winapi", "winapi",
"windows", "windows 0.51.1",
] ]
[[package]] [[package]]
@ -2883,6 +2897,19 @@ dependencies = [
"log", "log",
] ]
[[package]]
name = "loom"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e045d70ddfbc984eacfa964ded019534e8f6cbf36f6410aee0ed5cefa5a9175"
dependencies = [
"cfg-if",
"generator",
"scoped-tls",
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "lru" name = "lru"
version = "0.12.1" version = "0.12.1"
@ -3802,18 +3829,19 @@ dependencies = [
[[package]] [[package]]
name = "profiling" name = "profiling"
version = "1.0.13" version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d135ede8821cf6376eb7a64148901e1690b788c11ae94dc297ae917dbc91dc0e" checksum = "43d84d1d7a6ac92673717f9f6d1518374ef257669c24ebc5ac25d5033828be58"
dependencies = [ dependencies = [
"profiling-procmacros", "profiling-procmacros",
"tracy-client",
] ]
[[package]] [[package]]
name = "profiling-procmacros" name = "profiling-procmacros"
version = "1.0.13" version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b322d7d65c1ab449be3c890fcbd0db6e1092d0dd05d79dba2dd28032cebeb05" checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd"
dependencies = [ dependencies = [
"quote", "quote",
"syn 2.0.48", "syn 2.0.48",
@ -4220,6 +4248,12 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "rustversion"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]] [[package]]
name = "rustybuzz" name = "rustybuzz"
version = "0.12.1" version = "0.12.1"
@ -5017,6 +5051,26 @@ dependencies = [
"tracing-log", "tracing-log",
] ]
[[package]]
name = "tracy-client"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59fb931a64ff88984f86d3e9bcd1ae8843aa7fe44dd0f8097527bc172351741d"
dependencies = [
"loom",
"once_cell",
"tracy-client-sys",
]
[[package]]
name = "tracy-client-sys"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d104d610dfa9dd154535102cc9c6164ae1fa37842bc2d9e83f9ac82b0ae0882"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "ttf-parser" name = "ttf-parser"
version = "0.20.0" version = "0.20.0"
@ -5710,6 +5764,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets 0.48.5",
]
[[package]] [[package]]
name = "windows" name = "windows"
version = "0.51.1" version = "0.51.1"

View file

@ -58,6 +58,7 @@ xdg = "^2.1"
xdg-user = "0.2.1" xdg-user = "0.2.1"
xkbcommon = "0.7" xkbcommon = "0.7"
zbus = "3.15.0" zbus = "3.15.0"
profiling = { version = "1.0" }
[dependencies.id_tree] [dependencies.id_tree]
branch = "feature/copy_clone" branch = "feature/copy_clone"
@ -96,6 +97,7 @@ rev = "cdc652e0"
debug = ["egui", "egui_plot", "smithay-egui", "renderdoc", "puffin", "puffin_egui", "anyhow/backtrace"] debug = ["egui", "egui_plot", "smithay-egui", "renderdoc", "puffin", "puffin_egui", "anyhow/backtrace"]
default = ["systemd"] default = ["systemd"]
systemd = ["libsystemd"] systemd = ["libsystemd"]
profile-with-tracy = ["profiling/profile-with-tracy"]
[profile.dev] [profile.dev]
lto = "thin" lto = "thin"

View file

@ -1153,6 +1153,7 @@ fn get_surface_dmabuf_feedback(
} }
impl Surface { impl Surface {
#[profiling::function]
pub fn render_output( pub fn render_output(
&mut self, &mut self,
api: &mut GpuManager<GbmGlesBackend<GlowRenderer, DrmDeviceFd>>, api: &mut GpuManager<GbmGlesBackend<GlowRenderer, DrmDeviceFd>>,
@ -1359,6 +1360,7 @@ impl KmsState {
self.session.change_vt(num).map_err(Into::into) self.session.change_vt(num).map_err(Into::into)
} }
#[profiling::function]
pub fn apply_config_for_output( pub fn apply_config_for_output(
&mut self, &mut self,
output: &Output, output: &Output,
@ -1587,6 +1589,7 @@ impl KmsState {
Err(last_err) Err(last_err)
} }
#[profiling::function]
pub fn schedule_render( pub fn schedule_render(
&mut self, &mut self,
loop_handle: &LoopHandle<'_, State>, loop_handle: &LoopHandle<'_, State>,
@ -1626,6 +1629,7 @@ impl KmsState {
) )
}, },
move |_time, _, state| { move |_time, _, state| {
profiling::scope!("render_timer");
let backend = state.backend.kms(); let backend = state.backend.kms();
let (mut device, mut other) = backend let (mut device, mut other) = backend
.devices .devices
@ -1666,6 +1670,8 @@ impl KmsState {
) )
}; };
profiling::finish_frame!();
match result { match result {
Ok(_) => { Ok(_) => {
trace!(?crtc, "Frame pending"); trace!(?crtc, "Frame pending");

View file

@ -184,6 +184,7 @@ where
) )
} }
#[profiling::function]
pub fn draw_dnd_icon<R>( pub fn draw_dnd_icon<R>(
renderer: &mut R, renderer: &mut R,
surface: &wl_surface::WlSurface, surface: &wl_surface::WlSurface,
@ -301,6 +302,7 @@ impl Default for CursorState {
} }
} }
#[profiling::function]
pub fn draw_cursor<R>( pub fn draw_cursor<R>(
renderer: &mut R, renderer: &mut R,
seat: &Seat<State>, seat: &Seat<State>,

View file

@ -389,6 +389,7 @@ pub enum CursorMode {
All, All,
} }
#[profiling::function]
pub fn cursor_elements<'frame, E, R>( pub fn cursor_elements<'frame, E, R>(
renderer: &mut R, renderer: &mut R,
state: &Common, state: &Common,
@ -464,6 +465,7 @@ where
elements elements
} }
#[profiling::function]
pub fn workspace_elements<R>( pub fn workspace_elements<R>(
_gpu: Option<&DrmNode>, _gpu: Option<&DrmNode>,
renderer: &mut R, renderer: &mut R,
@ -965,6 +967,7 @@ where
} }
} }
#[profiling::function]
pub fn render_output<R, Target, OffTarget, Source>( pub fn render_output<R, Target, OffTarget, Source>(
gpu: Option<&DrmNode>, gpu: Option<&DrmNode>,
renderer: &mut R, renderer: &mut R,
@ -1020,6 +1023,7 @@ where
result result
} }
#[profiling::function]
pub fn render_workspace<R, Target, OffTarget, Source>( pub fn render_workspace<R, Target, OffTarget, Source>(
gpu: Option<&DrmNode>, gpu: Option<&DrmNode>,
renderer: &mut R, renderer: &mut R,

View file

@ -51,6 +51,7 @@ pub struct WinitState {
} }
impl WinitState { impl WinitState {
#[profiling::function]
pub fn render_output(&mut self, state: &mut Common) -> Result<()> { pub fn render_output(&mut self, state: &mut Common) -> Result<()> {
self.backend self.backend
.bind() .bind()
@ -197,6 +198,7 @@ pub fn init_backend(
error!(?err, "Failed to render frame."); error!(?err, "Failed to render frame.");
render_ping.ping(); render_ping.ping();
} }
profiling::finish_frame!();
}) })
.map_err(|_| anyhow::anyhow!("Failed to init eventloop timer for winit"))?, .map_err(|_| anyhow::anyhow!("Failed to init eventloop timer for winit"))?,
); );

View file

@ -38,6 +38,11 @@ pub mod utils;
pub mod wayland; pub mod wayland;
pub mod xwayland; pub mod xwayland;
#[cfg(feature = "profile-with-tracy")]
#[global_allocator]
static GLOBAL: profiling::tracy_client::ProfiledAllocator<std::alloc::System> =
profiling::tracy_client::ProfiledAllocator::new(std::alloc::System, 10);
fn main() -> Result<()> { fn main() -> Result<()> {
// setup logger // setup logger
logger::init_logger()?; logger::init_logger()?;
@ -80,6 +85,11 @@ fn main() -> Result<()> {
warn!(?err, "Failed to watch theme"); warn!(?err, "Failed to watch theme");
} }
#[cfg(feature = "profile-with-tracy")]
profiling::tracy_client::Client::start();
profiling::register_thread!("Main Thread");
// run the event loop // run the event loop
event_loop.run(None, &mut state, |state| { event_loop.run(None, &mut state, |state| {
// shall we shut down? // shall we shut down?

View file

@ -847,6 +847,7 @@ impl SpaceElement for CosmicMapped {
fn z_index(&self) -> u8 { fn z_index(&self) -> u8 {
SpaceElement::z_index(&self.element) SpaceElement::z_index(&self.element)
} }
#[profiling::function]
fn refresh(&self) { fn refresh(&self) {
SpaceElement::refresh(&self.element) SpaceElement::refresh(&self.element)
} }

View file

@ -641,6 +641,7 @@ impl SpaceElement for CosmicSurface {
SpaceElement::output_leave(&self.0, output) SpaceElement::output_leave(&self.0, output)
} }
#[profiling::function]
fn refresh(&self) { fn refresh(&self) {
SpaceElement::refresh(&self.0) SpaceElement::refresh(&self.0)
} }

View file

@ -490,11 +490,13 @@ impl SpaceElement for CosmicWindow {
}); });
} }
} }
#[profiling::function]
fn output_enter(&self, output: &Output, overlap: Rectangle<i32, Logical>) { fn output_enter(&self, output: &Output, overlap: Rectangle<i32, Logical>) {
SpaceElement::output_enter(&self.0, output, overlap); SpaceElement::output_enter(&self.0, output, overlap);
self.0 self.0
.with_program(|p| SpaceElement::output_enter(&p.window, output, overlap)); .with_program(|p| SpaceElement::output_enter(&p.window, output, overlap));
} }
#[profiling::function]
fn output_leave(&self, output: &Output) { fn output_leave(&self, output: &Output) {
SpaceElement::output_leave(&self.0, output); SpaceElement::output_leave(&self.0, output);
self.0 self.0
@ -512,6 +514,7 @@ impl SpaceElement for CosmicWindow {
fn z_index(&self) -> u8 { fn z_index(&self) -> u8 {
self.0.with_program(|p| SpaceElement::z_index(&p.window)) self.0.with_program(|p| SpaceElement::z_index(&p.window))
} }
#[profiling::function]
fn refresh(&self) { fn refresh(&self) {
SpaceElement::refresh(&self.0); SpaceElement::refresh(&self.0);
if self.0.with_program(|p| { if self.0.with_program(|p| {

View file

@ -61,6 +61,7 @@ pub struct MoveGrabState {
} }
impl MoveGrabState { impl MoveGrabState {
#[profiling::function]
pub fn render<I, R>( pub fn render<I, R>(
&self, &self,
renderer: &mut R, renderer: &mut R,

View file

@ -1095,6 +1095,7 @@ impl FloatingLayout {
self.mapped().flat_map(|e| e.windows().map(|(w, _)| w)) self.mapped().flat_map(|e| e.windows().map(|(w, _)| w))
} }
#[profiling::function]
pub fn refresh(&mut self) { pub fn refresh(&mut self) {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
puffin::profile_function!(); puffin::profile_function!();
@ -1150,6 +1151,7 @@ impl FloatingLayout {
self.refresh(); //fixup any out of bounds elements self.refresh(); //fixup any out of bounds elements
} }
#[profiling::function]
pub fn render<R>( pub fn render<R>(
&self, &self,
renderer: &mut R, renderer: &mut R,

View file

@ -2303,6 +2303,7 @@ impl TilingLayout {
self.queue.push_tree(tree, ANIMATION_DURATION, blocker); self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
} }
#[profiling::function]
pub fn refresh(&mut self) { pub fn refresh(&mut self) {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
puffin::profile_function!(); puffin::profile_function!();
@ -2934,6 +2935,7 @@ impl TilingLayout {
} }
} }
#[profiling::function]
fn update_positions( fn update_positions(
output: &Output, output: &Output,
tree: &mut Tree<Data>, tree: &mut Tree<Data>,
@ -3801,6 +3803,7 @@ impl TilingLayout {
} }
} }
#[profiling::function]
pub fn render<R>( pub fn render<R>(
&self, &self,
renderer: &mut R, renderer: &mut R,

View file

@ -1515,6 +1515,7 @@ impl Shell {
} }
} }
#[profiling::function]
pub fn refresh(&mut self) { pub fn refresh(&mut self) {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
puffin::profile_function!(); puffin::profile_function!();

View file

@ -286,6 +286,7 @@ impl Workspace {
} }
} }
#[profiling::function]
pub fn refresh(&mut self, xdg_activation_state: &XdgActivationState) { pub fn refresh(&mut self, xdg_activation_state: &XdgActivationState) {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
puffin::profile_function!(); puffin::profile_function!();
@ -1059,6 +1060,7 @@ impl Workspace {
} }
} }
#[profiling::function]
pub fn render<'a, R>( pub fn render<'a, R>(
&self, &self,
renderer: &mut R, renderer: &mut R,

View file

@ -353,7 +353,15 @@ impl State {
.with_context(|| "Failed to load languages") .with_context(|| "Failed to load languages")
.unwrap(); .unwrap();
#[cfg(feature = "profile-with-tracy")]
unsafe {
time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound);
}
let local_offset = UtcOffset::current_local_offset().expect("No yet multithreaded"); let local_offset = UtcOffset::current_local_offset().expect("No yet multithreaded");
#[cfg(feature = "profile-with-tracy")]
unsafe {
time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Sound);
}
let clock = Clock::new(); let clock = Clock::new();
let config = Config::load(&handle); let config = Config::load(&handle);
let compositor_state = CompositorState::new::<Self>(dh); let compositor_state = CompositorState::new::<Self>(dh);

View file

@ -358,6 +358,7 @@ impl<P: Program + Send + 'static + Clone> IcedElement<P> {
} }
impl<P: Program + Send + 'static> IcedElementInternal<P> { impl<P: Program + Send + 'static> IcedElementInternal<P> {
#[profiling::function]
fn update(&mut self, mut force: bool) -> Vec<Action<<P as Program>::Message>> { fn update(&mut self, mut force: bool) -> Vec<Action<<P as Program>::Message>> {
while let Ok(message) = self.rx.try_recv() { while let Ok(message) = self.rx.try_recv() {
self.state.queue_message(message); self.state.queue_message(message);
@ -691,6 +692,7 @@ impl<P: Program + Send + 'static> SpaceElement for IcedElement<P> {
RenderZindex::Shell as u8 RenderZindex::Shell as u8
} }
#[profiling::function]
fn refresh(&self) { fn refresh(&self) {
let mut internal = self.0.lock().unwrap(); let mut internal = self.0.lock().unwrap();
// makes partial borrows easier // makes partial borrows easier

View file

@ -593,6 +593,7 @@ where
Ok(()) Ok(())
} }
#[profiling::function]
pub fn render_session<F, R>( pub fn render_session<F, R>(
node: Option<DrmNode>, node: Option<DrmNode>,
renderer: &mut R, renderer: &mut R,
@ -637,6 +638,7 @@ where
} }
} }
#[profiling::function]
pub fn render_output_to_buffer( pub fn render_output_to_buffer(
state: &mut State, state: &mut State,
session: &Session, session: &Session,
@ -767,6 +769,7 @@ pub fn render_output_to_buffer(
} }
} }
#[profiling::function]
pub fn render_workspace_to_buffer( pub fn render_workspace_to_buffer(
state: &mut State, state: &mut State,
session: &Session, session: &Session,
@ -916,6 +919,7 @@ smithay::render_elements! {
CursorElement=cursor::CursorRenderElement<R>, CursorElement=cursor::CursorRenderElement<R>,
} }
#[profiling::function]
pub fn render_window_to_buffer( pub fn render_window_to_buffer(
state: &mut State, state: &mut State,
session: &Session, session: &Session,