pub struct FrameHistogram { /* private fields */ }Expand description
Rolling 120-frame timing histogram.
Stores the last 120 frame timings in a fixed-size ring buffer
with zero heap allocation.
§Example
use martensite_devtools::hud::{FrameHistogram, FrameTiming};
let mut hist = FrameHistogram::new();
hist.record(FrameTiming {
layout_time_ns: 500_000,
paint_time_ns: 300_000,
gpu_wait_time_ns: 100_000,
total_time_ns: 900_000,
});
assert_eq!(hist.len(), 1);
let avg = hist.average();
assert_eq!(avg.total_time_ns, 900_000);Implementations§
Source§impl FrameHistogram
impl FrameHistogram
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty histogram.
§Example
use martensite_devtools::hud::FrameHistogram;
let hist = FrameHistogram::new();
assert!(hist.is_empty());Sourcepub fn record(&mut self, timing: FrameTiming)
pub fn record(&mut self, timing: FrameTiming)
Records a frame timing into the ring buffer.
§Example
use martensite_devtools::hud::{FrameHistogram, FrameTiming};
let mut hist = FrameHistogram::new();
hist.record(FrameTiming { total_time_ns: 16_000_000, ..Default::default() });
assert_eq!(hist.len(), 1);Sourcepub fn average(&self) -> FrameTiming
pub fn average(&self) -> FrameTiming
Returns the average frame timing across all recorded frames.
§Example
use martensite_devtools::hud::{FrameHistogram, FrameTiming};
let mut hist = FrameHistogram::new();
hist.record(FrameTiming { total_time_ns: 10_000_000, ..Default::default() });
hist.record(FrameTiming { total_time_ns: 20_000_000, ..Default::default() });
assert_eq!(hist.average().total_time_ns, 15_000_000);Sourcepub fn percentile(&self, p: f32) -> FrameTiming
pub fn percentile(&self, p: f32) -> FrameTiming
Returns the timing at the given percentile (0.0–100.0).
p=50 gives the median, p=99 gives the 99th percentile.
§Example
use martensite_devtools::hud::{FrameHistogram, FrameTiming};
let mut hist = FrameHistogram::new();
for i in 1..=100 {
hist.record(FrameTiming { total_time_ns: i * 1_000_000, ..Default::default() });
}
let p50 = hist.percentile(50.0);
assert!(p50.total_time_ns >= 49_000_000 && p50.total_time_ns <= 51_000_000);Sourcepub fn max(&self) -> FrameTiming
pub fn max(&self) -> FrameTiming
Returns the maximum recorded frame timing.
§Example
use martensite_devtools::hud::{FrameHistogram, FrameTiming};
let mut hist = FrameHistogram::new();
hist.record(FrameTiming { total_time_ns: 10_000_000, ..Default::default() });
hist.record(FrameTiming { total_time_ns: 30_000_000, ..Default::default() });
hist.record(FrameTiming { total_time_ns: 20_000_000, ..Default::default() });
assert_eq!(hist.max().total_time_ns, 30_000_000);Sourcepub fn frames(&self) -> &[FrameTiming]
pub fn frames(&self) -> &[FrameTiming]
Returns a slice of all recorded frame timings.
Note: After the ring buffer wraps (more than 120 frames recorded), the slice is in physical storage order, not chronological order. The newest frame may appear at any position. This is suitable for aggregation (average, max, percentile) but not for chronological display.
§Example
use martensite_devtools::hud::{FrameHistogram, FrameTiming};
let mut hist = FrameHistogram::new();
hist.record(FrameTiming::default());
assert_eq!(hist.frames().len(), 1);Trait Implementations§
Source§impl Clone for FrameHistogram
impl Clone for FrameHistogram
Source§fn clone(&self) -> FrameHistogram
fn clone(&self) -> FrameHistogram
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FrameHistogram
impl Debug for FrameHistogram
Auto Trait Implementations§
impl Freeze for FrameHistogram
impl RefUnwindSafe for FrameHistogram
impl Send for FrameHistogram
impl Sync for FrameHistogram
impl Unpin for FrameHistogram
impl UnsafeUnpin for FrameHistogram
impl UnwindSafe for FrameHistogram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more