Skip to content

Commit

Permalink
Add support for profiling using tracy
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Dec 12, 2023
1 parent f70d33d commit 2d4845c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 1 deletion.
65 changes: 64 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ libc = "0.2.149"
xdg-user = "0.2.1"
time = { version = "0.3.30", features = ["macros", "formatting", "local-offset"] }
sanitize-filename = "0.5.0"
profiling = { version = "1.0" }

[dependencies.id_tree]
git = "https://github.com/Drakulix/id-tree.git"
Expand All @@ -79,6 +80,7 @@ optional = true
default = ["systemd"]
systemd = ["libsystemd"]
debug = ["egui", "egui_plot", "smithay-egui", "renderdoc", "puffin", "puffin_egui", "anyhow/backtrace"]
profile-with-tracy = ["profiling/profile-with-tracy"]

[profile.dev]
lto = "thin"
Expand Down
5 changes: 5 additions & 0 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ fn get_surface_dmabuf_feedback(
}

impl Surface {
#[profiling::function]
pub fn render_output(
&mut self,
api: &mut GpuManager<GbmGlesBackend<GlowRenderer>>,
Expand Down Expand Up @@ -1383,6 +1384,7 @@ impl KmsState {
self.session.change_vt(num).map_err(Into::into)
}

#[profiling::function]
pub fn apply_config_for_output(
&mut self,
output: &Output,
Expand Down Expand Up @@ -1595,6 +1597,7 @@ impl KmsState {
unreachable!()
}

#[profiling::function]
pub fn schedule_render(
&mut self,
loop_handle: &LoopHandle<'_, State>,
Expand Down Expand Up @@ -1677,6 +1680,8 @@ impl KmsState {
)
};

profiling::finish_frame!();

match result {
Ok(_) => {
trace!(?crtc, "Frame pending");
Expand Down
2 changes: 2 additions & 0 deletions src/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ where
}
}

#[profiling::function]
pub fn render_output<R, Target, OffTarget, Source>(
gpu: Option<&DrmNode>,
renderer: &mut R,
Expand Down Expand Up @@ -890,6 +891,7 @@ where
result
}

#[profiling::function]
pub fn render_workspace<R, Target, OffTarget, Source>(
gpu: Option<&DrmNode>,
renderer: &mut R,
Expand Down
2 changes: 2 additions & 0 deletions src/backend/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct WinitState {
}

impl WinitState {
#[profiling::function]
pub fn render_output(&mut self, state: &mut Common) -> Result<()> {
self.backend
.bind()
Expand Down Expand Up @@ -197,6 +198,7 @@ pub fn init_backend(
error!(?err, "Failed to render frame.");
render_ping.ping();
}
profiling::finish_frame!();
})
.map_err(|_| anyhow::anyhow!("Failed to init eventloop timer for winit"))?,
);
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub mod utils;
pub mod wayland;
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<()> {
// setup logger
logger::init_logger()?;
Expand Down Expand Up @@ -60,6 +65,11 @@ fn main() -> Result<()> {
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
event_loop.run(None, &mut state, |state| {
// shall we shut down?
Expand Down
4 changes: 4 additions & 0 deletions src/wayland/handlers/screencopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ where
Ok(())
}

#[profiling::function]
pub fn render_session<F, R>(
node: Option<DrmNode>,
renderer: &mut R,
Expand Down Expand Up @@ -634,6 +635,7 @@ where
}
}

#[profiling::function]
pub fn render_output_to_buffer(
state: &mut State,
session: &Session,
Expand Down Expand Up @@ -764,6 +766,7 @@ pub fn render_output_to_buffer(
}
}

#[profiling::function]
pub fn render_workspace_to_buffer(
state: &mut State,
session: &Session,
Expand Down Expand Up @@ -913,6 +916,7 @@ smithay::render_elements! {
CursorElement=cursor::CursorRenderElement<R>,
}

#[profiling::function]
pub fn render_window_to_buffer(
state: &mut State,
session: &Session,
Expand Down

0 comments on commit 2d4845c

Please sign in to comment.