Skip to main content

FrameStats

Struct FrameStats 

Source
pub struct FrameStats<const N: usize = 120> { /* private fields */ }
Expand description

A fixed-size ring buffer of recent per-frame durations, plus the min/max/average/fps readouts derived from it.

N bounds memory and how far back the window looks; the default, 120 samples (about two seconds at 60fps), is a reasonable window for a live overlay. Every reducer (avg, min, max, fps) is computed on demand from the current window rather than maintained incrementally, since a live overlay only calls them once per rendered frame, not once per sample.

Readouts are Duration, not a pre-chosen unit: a caller formats with whatever precision it needs (as_millis(), as_secs_f32(), …) rather than being handed milliseconds it then has to convert back if it wants something else. current is the single most recent sample, unsmoothed: pair it with the windowed min/max for a “current, min, max” readout, and samples for a frame-time graph (feed it, converted to milliseconds, straight into Sparkline).

Implementations§

Source§

impl<const N: usize> FrameStats<N>

Source

pub const fn new() -> Self

An empty window; every readout is Duration::ZERO (or 0.0 for fps) until the first record.

Source

pub fn record(&mut self, delta: Duration)

Records one frame’s wall-clock duration.

Call once per rendered frame with Frame::delta. A no-op if N is 0 (frame count still advances) rather than panicking: a zero-capacity window is a degenerate but harmless configuration, not a caller error worth crashing over.

Source

pub const fn frame_count(&self) -> u64

Total frames ever recorded via record, uncapped by N.

Source

pub fn samples(&self) -> impl ExactSizeIterator<Item = Duration> + '_

Recorded frame durations, oldest first (so the most recent frame is last): the order a sparkline/histogram wants so new data enters on the right.

Source

pub const fn current(&self) -> Duration

The most recently recorded frame’s duration, unsmoothed. Duration::ZERO before the first record.

Source

pub fn avg(&self) -> Duration

The average frame duration over the current window. Duration::ZERO before the first record.

Source

pub fn min(&self) -> Duration

The fastest (shortest) frame in the current window. Duration::ZERO before the first record.

Source

pub fn max(&self) -> Duration

The slowest (longest) frame in the current window. Duration::ZERO before the first record.

Source

pub fn fps(&self) -> f32

Frames per second, derived from avg over the current window. 0.0 before the first record (rather than dividing by zero).

Trait Implementations§

Source§

impl<const N: usize> Clone for FrameStats<N>

Source§

fn clone(&self) -> FrameStats<N>

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<const N: usize> Debug for FrameStats<N>

Source§

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

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

impl<const N: usize> Default for FrameStats<N>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<const N: usize> Freeze for FrameStats<N>

§

impl<const N: usize> RefUnwindSafe for FrameStats<N>

§

impl<const N: usize> Send for FrameStats<N>

§

impl<const N: usize> Sync for FrameStats<N>

§

impl<const N: usize> Unpin for FrameStats<N>

§

impl<const N: usize> UnsafeUnpin for FrameStats<N>

§

impl<const N: usize> UnwindSafe for FrameStats<N>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.