Skip to main content

strata/runtime/
profile.rs

1//! Per-phase frame profiling: rebuild, layout, compile, raster and present.
2
3use std::time::Duration;
4
5/// Wall-clock cost of each frame phase since the last [`FrameProfile::take`].
6///
7/// Phases accumulate, so a frame that rebuilds twice reports both costs.
8#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
9pub struct FrameProfile {
10    /// Blueprint to layout-tree rebuild, including style resolution.
11    pub rebuild: Duration,
12    /// Layout computation.
13    pub layout: Duration,
14    /// Display-list compilation (compositor, scrollbars, path batch).
15    pub compile: Duration,
16    /// Rasterization, recorded by the presenting backend.
17    pub raster: Duration,
18    /// Presentation to the surface, recorded by the presenting backend.
19    pub present: Duration,
20}
21
22impl FrameProfile {
23    /// Sum of all phases.
24    pub fn total(&self) -> Duration {
25        self.rebuild + self.layout + self.compile + self.raster + self.present
26    }
27}
28
29/// Receives a completed [`FrameProfile`] each time a frame is presented.
30pub struct FrameProfileHook(pub Box<dyn FnMut(&FrameProfile)>);
31
32impl std::fmt::Debug for FrameProfileHook {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        f.write_str("FrameProfileHook(..)")
35    }
36}