Skip to main content

FrameHistogram

Struct FrameHistogram 

Source
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

Source

pub fn new() -> Self

Creates a new empty histogram.

§Example
use martensite_devtools::hud::FrameHistogram;

let hist = FrameHistogram::new();
assert!(hist.is_empty());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

pub fn len(&self) -> usize

Returns the number of recorded frames.

Source

pub fn is_empty(&self) -> bool

Returns true if no frames have been recorded.

Source

pub fn clear(&mut self)

Clears all recorded frames.

Trait Implementations§

Source§

impl Clone for FrameHistogram

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for FrameHistogram

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FrameHistogram

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.