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

View file

@ -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>>,
@ -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,
@ -1587,6 +1589,7 @@ impl KmsState {
Err(last_err)
}
#[profiling::function]
pub fn schedule_render(
&mut self,
loop_handle: &LoopHandle<'_, State>,
@ -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
@ -1666,6 +1670,8 @@ impl KmsState {
)
};
profiling::finish_frame!();
match result {
Ok(_) => {
trace!(?crtc, "Frame pending");

View file

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

View file

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

View file

@ -51,6 +51,7 @@ pub struct WinitState {
}
impl WinitState {
#[profiling::function]
pub fn render_output(&mut self, state: &mut Common) -> Result<()> {
self.backend
.bind()
@ -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"))?,
);

View file

@ -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()?;
@ -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?

View file

@ -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)
}

View file

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

View file

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

View file

@ -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!();
@ -1150,6 +1151,7 @@ impl FloatingLayout {
self.refresh(); //fixup any out of bounds elements
}
#[profiling::function]
pub fn render<R>(
&self,
renderer: &mut R,

View file

@ -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!();
@ -2934,6 +2935,7 @@ impl TilingLayout {
}
}
#[profiling::function]
fn update_positions(
output: &Output,
tree: &mut Tree<Data>,
@ -3801,6 +3803,7 @@ impl TilingLayout {
}
}
#[profiling::function]
pub fn render<R>(
&self,
renderer: &mut R,

View file

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

View file

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

View file

@ -353,7 +353,15 @@ impl State {
.with_context(|| "Failed to load languages")
.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");
#[cfg(feature = "profile-with-tracy")]
unsafe {
time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Sound);
}
let clock = Clock::new();
let config = Config::load(&handle);
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> {
#[profiling::function]
fn update(&mut self, mut force: bool) -> Vec<Action<<P as Program>::Message>> {
while let Ok(message) = self.rx.try_recv() {
self.state.queue_message(message);
@ -691,6 +692,7 @@ impl<P: Program + Send + 'static> SpaceElement for IcedElement<P> {
RenderZindex::Shell as u8
}
#[profiling::function]
fn refresh(&self) {
let mut internal = self.0.lock().unwrap();
// makes partial borrows easier

View file

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