Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for profiling using tracy #209

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions 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 @@ -58,6 +58,7 @@ xdg = "^2.1"
xdg-user = "0.2.1"
xkbcommon = "0.7"
zbus = "3.15.0"
profiling = { version = "1.0" }

[dependencies.id_tree]
branch = "feature/copy_clone"
Expand Down Expand Up @@ -96,6 +97,7 @@ rev = "cdc652e0"
debug = ["egui", "egui_plot", "smithay-egui", "renderdoc", "puffin", "puffin_egui", "anyhow/backtrace"]
default = ["systemd"]
systemd = ["libsystemd"]
profile-with-tracy = ["profiling/profile-with-tracy"]

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

impl Surface {
#[profiling::function]
pub fn render_output(
&mut self,
api: &mut GpuManager<GbmGlesBackend<GlowRenderer, DrmDeviceFd>>,
Expand Down Expand Up @@ -1359,6 +1360,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 @@ -1587,6 +1589,7 @@ impl KmsState {
Err(last_err)
}

#[profiling::function]
pub fn schedule_render(
&mut self,
loop_handle: &LoopHandle<'_, State>,
Expand Down Expand Up @@ -1626,6 +1629,7 @@ impl KmsState {
)
},
move |_time, _, state| {
profiling::scope!("render_timer");
let backend = state.backend.kms();
let (mut device, mut other) = backend
.devices
Expand Down Expand Up @@ -1666,6 +1670,8 @@ impl KmsState {
)
};

profiling::finish_frame!();

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

#[profiling::function]
pub fn draw_dnd_icon<R>(
renderer: &mut R,
surface: &wl_surface::WlSurface,
Expand Down Expand Up @@ -301,6 +302,7 @@ impl Default for CursorState {
}
}

#[profiling::function]
pub fn draw_cursor<R>(
renderer: &mut R,
seat: &Seat<State>,
Expand Down
4 changes: 4 additions & 0 deletions src/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ pub enum CursorMode {
All,
}

#[profiling::function]
pub fn cursor_elements<'frame, E, R>(
renderer: &mut R,
state: &Common,
Expand Down Expand Up @@ -464,6 +465,7 @@ where
elements
}

#[profiling::function]
pub fn workspace_elements<R>(
_gpu: Option<&DrmNode>,
renderer: &mut R,
Expand Down Expand Up @@ -965,6 +967,7 @@ where
}
}

#[profiling::function]
pub fn render_output<R, Target, OffTarget, Source>(
gpu: Option<&DrmNode>,
renderer: &mut R,
Expand Down Expand Up @@ -1020,6 +1023,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 @@ -38,6 +38,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 @@ -80,6 +85,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
1 change: 1 addition & 0 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ impl SpaceElement for CosmicMapped {
fn z_index(&self) -> u8 {
SpaceElement::z_index(&self.element)
}
#[profiling::function]
fn refresh(&self) {
SpaceElement::refresh(&self.element)
}
Expand Down
1 change: 1 addition & 0 deletions src/shell/element/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ impl SpaceElement for CosmicSurface {
SpaceElement::output_leave(&self.0, output)
}

#[profiling::function]
fn refresh(&self) {
SpaceElement::refresh(&self.0)
}
Expand Down
3 changes: 3 additions & 0 deletions src/shell/element/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,13 @@ impl SpaceElement for CosmicWindow {
});
}
}
#[profiling::function]
fn output_enter(&self, output: &Output, overlap: Rectangle<i32, Logical>) {
SpaceElement::output_enter(&self.0, output, overlap);
self.0
.with_program(|p| SpaceElement::output_enter(&p.window, output, overlap));
}
#[profiling::function]
fn output_leave(&self, output: &Output) {
SpaceElement::output_leave(&self.0, output);
self.0
Expand All @@ -512,6 +514,7 @@ impl SpaceElement for CosmicWindow {
fn z_index(&self) -> u8 {
self.0.with_program(|p| SpaceElement::z_index(&p.window))
}
#[profiling::function]
fn refresh(&self) {
SpaceElement::refresh(&self.0);
if self.0.with_program(|p| {
Expand Down
1 change: 1 addition & 0 deletions src/shell/grabs/moving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct MoveGrabState {
}

impl MoveGrabState {
#[profiling::function]
pub fn render<I, R>(
&self,
renderer: &mut R,
Expand Down
2 changes: 2 additions & 0 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ impl FloatingLayout {
self.mapped().flat_map(|e| e.windows().map(|(w, _)| w))
}

#[profiling::function]
pub fn refresh(&mut self) {
#[cfg(feature = "debug")]
puffin::profile_function!();
Expand Down Expand Up @@ -1150,6 +1151,7 @@ impl FloatingLayout {
self.refresh(); //fixup any out of bounds elements
}

#[profiling::function]
pub fn render<R>(
&self,
renderer: &mut R,
Expand Down
3 changes: 3 additions & 0 deletions src/shell/layout/tiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,7 @@ impl TilingLayout {
self.queue.push_tree(tree, ANIMATION_DURATION, blocker);
}

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

#[profiling::function]
fn update_positions(
output: &Output,
tree: &mut Tree<Data>,
Expand Down Expand Up @@ -3801,6 +3803,7 @@ impl TilingLayout {
}
}

#[profiling::function]
pub fn render<R>(
&self,
renderer: &mut R,
Expand Down
1 change: 1 addition & 0 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@ impl Shell {
}
}

#[profiling::function]
pub fn refresh(&mut self) {
#[cfg(feature = "debug")]
puffin::profile_function!();
Expand Down
2 changes: 2 additions & 0 deletions src/shell/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ impl Workspace {
}
}

#[profiling::function]
pub fn refresh(&mut self, xdg_activation_state: &XdgActivationState) {
#[cfg(feature = "debug")]
puffin::profile_function!();
Expand Down Expand Up @@ -1059,6 +1060,7 @@ impl Workspace {
}
}

#[profiling::function]
pub fn render<'a, R>(
&self,
renderer: &mut R,
Expand Down
Loading