Skip to content

Commit

Permalink
Add support for puffin profiling
Browse files Browse the repository at this point in the history
This patch adds profiling support using puffin, allowing for easier
introspection into timing-related performance issues.
  • Loading branch information
chrisduerr committed Feb 16, 2024
1 parent c3cd0e1 commit b0e0323
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
101 changes: 101 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ edition = "2021"
[workspace]
members = ["catacomb_ipc"]

[features]
default = []
profiling = ["dep:profiling", "dep:puffin_http"]

[dependencies.smithay]
git = "https://github.com/chrisduerr/smithay"
rev = "805038526f4d300c1389fda7a860126b7fd94470"
Expand Down Expand Up @@ -40,3 +44,5 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
udev = "0.8.0"
zbus = { version = "3.11.0", default-features = false, features = ["tokio"] }
tracing-log = "0.2.0"
puffin_http = { version = "0.16.0", optional = true }
profiling = { version = "1.0.14", optional = true, features = ["profile-with-puffin"] }
1 change: 1 addition & 0 deletions src/catacomb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ impl Catacomb {
}

/// Handle everything necessary to draw a single frame.
#[cfg_attr(feature = "profiling", profiling::function)]
pub fn create_frame(&mut self) {
// Skip rendering while the screen is off.
if self.sleeping {
Expand Down
1 change: 1 addition & 0 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl Vector for Vector3D<f32> {
}
}

#[allow(unused)]
pub trait Vector: Sized {
/// Scale the size by a scaling factor.
fn scale(&self, scale: f64) -> Self;
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::{env, io, ptr};

use catacomb_ipc::{DpmsState, IpcMessage};
use clap::{self, Parser, Subcommand};
#[cfg(feature = "profiling")]
use profiling::puffin;
#[cfg(feature = "profiling")]
use puffin_http::Server;
use tracing::error;
use tracing_log::LogTracer;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
Expand Down Expand Up @@ -44,6 +48,12 @@ pub enum Subcommands {
}

pub fn main() {
#[cfg(feature = "profiling")]
let _server = {
puffin::set_scopes_on(true);
Server::new(&format!("0.0.0.0:{}", puffin_http::DEFAULT_PORT)).unwrap()
};

// Try to initialize log-compatibility shim.
let _ = LogTracer::init();

Expand Down
9 changes: 9 additions & 0 deletions src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::{env, io, mem, process, ptr};

use _linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1::TrancheFlags;
use libc::dev_t as DeviceId;
#[cfg(feature = "profiling")]
use profiling::puffin::GlobalProfiler;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::allocator::gbm::{GbmAllocator, GbmBuffer, GbmBufferFlags, GbmDevice};
use smithay::backend::allocator::{Format, Fourcc};
Expand Down Expand Up @@ -355,6 +357,10 @@ impl Udev {
// Mark the last frame as submitted.
trace_error(output_device.drm_compositor.frame_submitted());

// Signal new frame to profiler.
#[cfg(feature = "profiling")]
GlobalProfiler::lock().new_frame();

// Send presentation time feedback.
catacomb
.windows
Expand Down Expand Up @@ -575,6 +581,7 @@ impl OutputDevice {
/// Render a frame.
///
/// Will return `true` if something was rendered.
#[cfg_attr(feature = "profiling", profiling::function)]
fn render(
&mut self,
event_loop: &LoopHandle<'static, Catacomb>,
Expand Down Expand Up @@ -637,6 +644,7 @@ impl OutputDevice {
}

/// Copy a region of the framebuffer to a DMA buffer.
#[cfg_attr(feature = "profiling", profiling::function)]
fn copy_framebuffer_dma(
gles: &mut GlesRenderer,
scale: f64,
Expand All @@ -662,6 +670,7 @@ impl OutputDevice {
}

/// Copy a region of the framebuffer to an SHM buffer.
#[cfg_attr(feature = "profiling", profiling::function)]
fn copy_framebuffer_shm(
&mut self,
windows: &mut Windows,
Expand Down
2 changes: 2 additions & 0 deletions src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ impl Windows {
}

/// Import pending buffers for all windows.
#[cfg_attr(feature = "profiling", profiling::function)]
pub fn import_buffers(&mut self, renderer: &mut GlesRenderer) {
// Import XDG windows/popups.
for mut window in self.layouts.windows_mut() {
Expand All @@ -362,6 +363,7 @@ impl Windows {
}

/// Get all textures for rendering.
#[cfg_attr(feature = "profiling", profiling::function)]
pub fn textures(
&mut self,
renderer: &mut GlesRenderer,
Expand Down

0 comments on commit b0e0323

Please sign in to comment.