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>
impl<const N: usize> FrameStats<N>
Sourcepub const fn new() -> FrameStats<N>
pub const fn new() -> FrameStats<N>
An empty window; every readout is Duration::ZERO (or 0.0 for fps)
until the first record.
Sourcepub fn record(&mut self, delta: Duration)
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.
Sourcepub const fn frame_count(&self) -> u64
pub const fn frame_count(&self) -> u64
Total frames ever recorded via record, uncapped by N.
Sourcepub fn samples(&self) -> impl ExactSizeIterator
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.
Sourcepub const fn current(&self) -> Duration
pub const fn current(&self) -> Duration
The most recently recorded frame’s duration, unsmoothed. Duration::ZERO before the
first record.
Sourcepub fn avg(&self) -> Duration
pub fn avg(&self) -> Duration
The average frame duration over the current window. Duration::ZERO before the first
record.
Sourcepub fn min(&self) -> Duration
pub fn min(&self) -> Duration
The fastest (shortest) frame in the current window. Duration::ZERO before the first
record.
Sourcepub fn max(&self) -> Duration
pub fn max(&self) -> Duration
The slowest (longest) frame in the current window. Duration::ZERO before the first
record.
Trait Implementations§
Source§impl<const N: usize> Clone for FrameStats<N>
impl<const N: usize> Clone for FrameStats<N>
Source§fn clone(&self) -> FrameStats<N>
fn clone(&self) -> FrameStats<N>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const N: usize> Debug for FrameStats<N>
impl<const N: usize> Debug for FrameStats<N>
Source§impl<const N: usize> Default for FrameStats<N>
impl<const N: usize> Default for FrameStats<N>
Source§fn default() -> FrameStats<N>
fn default() -> FrameStats<N>
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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.