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() -> FrameStats<N>

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

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<(), Error>

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

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

Source§

fn default() -> FrameStats<N>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more