Skip to main content

FrameStats

Struct FrameStats 

Source
pub struct FrameStats { /* private fields */ }
Expand description

A rolling window of frame intervals, and the numbers read off it.

Fed from the frame clock’s render delta — the wall-clock time between the last two updates — so every number below traces to one measurement the engine already takes.

§FPS is the reciprocal of the mean, not the mean of the reciprocals

Given frames of 10 ms and 30 ms, the mean of 1/dt is (100 + 33.3)/2 = 67 FPS, which is faster than either frame. The window actually took 40 ms and contained 2 frames, so it ran at 50 FPS, which is what FrameStats::fps reports: count / total. The two agree only when every frame is the same length, and they disagree in exactly the case a profiler exists for.

Implementations§

Source§

impl FrameStats

Source

pub fn new() -> Self

A window of DEFAULT_FRAME_WINDOW frames.

Source

pub fn with_window(window: usize) -> Self

A window of window frames, clamped to at least one.

Source

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

Records one frame interval, evicting the oldest when the window is full.

A zero-length interval is not a frame and is dropped. FrameClock::update reports Duration::ZERO twice: on the very first update, which has no previous timestamp to subtract, and on any update whose timestamp went backwards. Neither is a frame that took no time, and keeping them would report a frame rate that never happened.

Source

pub fn len(&self) -> usize

How many frames are in the window.

Source

pub fn is_empty(&self) -> bool

Whether no frame has been recorded yet.

Source

pub const fn window(&self) -> usize

The window’s capacity in frames.

Source

pub const fn total(&self) -> Duration

The wall-clock time the window covers.

Source

pub fn mean(&self) -> Duration

The mean frame interval, or zero while the window is empty.

Source

pub fn fps(&self) -> f64

Frames per second over the window: frames divided by the time they took.

Zero while the window is empty, and zero if the window somehow covers no time at all — an infinite frame rate is not a more honest answer.

Source

pub fn last(&self) -> Option<Duration>

The most recent frame interval.

Source

pub fn best(&self) -> Option<Duration>

The shortest frame in the window.

Source

pub fn worst(&self) -> Option<Duration>

The longest frame in the window — the stall, if there was one.

Source

pub fn clear(&mut self)

Forgets every sample.

Trait Implementations§

Source§

impl Clone for FrameStats

Source§

fn clone(&self) -> Self

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 FrameStats

Source§

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

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

impl DebugModule for FrameStats

Source§

fn debug_section(&self, out: &mut DebugSection)

Writes this system’s title and rows into out.
Source§

impl Default for FrameStats

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.