Skip to main content

Profiler

Struct Profiler 

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

The last PROFILER_FRAMES frames’ timings and scopes, which Profiler::show draws as graphs of each frame’s processor time and GPU time and, for the frame clicked, its scopes as a tree, and Profiler::trace_json writes as a Chrome trace.

The engine pushes each frame with the scopes that nadir_core::profile::take_frame collected, and gives a frame it held the GPU’s time over its drawing when that is read back, frames later (Profiler::set_gpu). The records of all the frames share one pool of PROFILER_RECORDS, made at the first push: a push after that allocates nothing. While paused, it keeps what it holds, and counts the frames and their rate on.

Implementations§

Source§

impl Profiler

Source

pub fn new() -> Self

A profiler holding no frame, not paused.

Source

pub fn push(&mut self, timing: FrameTiming, records: &[ScopeRecord])

Adds a frame, with its scopes, and drops the oldest frames to make room for it. While paused, it only counts the frame and its length.

Source

pub fn next_index(&self) -> u64

The number the next frame pushed gets: the frames pushed so far, paused or not. While a frame runs, before it is pushed, its own.

Source

pub fn set_gpu(&mut self, index: u64, timing: GpuTiming) -> bool

Gives the frame numbered index the GPU’s time over its drawing, which the GPU’s timers give frames after the frame is pushed. Returns whether it holds that frame: a frame dropped, or pushed while paused, keeps nothing.

Source

pub fn len(&self) -> usize

How many frames it holds.

Source

pub fn is_empty(&self) -> bool

Whether it holds no frame.

Source

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

The frames it holds, the oldest first.

Source

pub fn frame(&self, index: u64) -> Option<ProfiledFrame<'_>>

The frame numbered index, if it holds it.

Source

pub fn frame_rate(&self) -> f32

The frames a second, over the last 60 frames pushed, paused or not: 0 before the first, or while they take no time.

Source

pub fn paused(&self) -> bool

Whether it is paused: holding its frames while the game runs on.

Source

pub fn set_paused(&mut self, paused: bool)

Pauses it, or lets it record again.

Source

pub fn selected(&self) -> Option<u64>

The number of the frame whose scopes the window shows, if any.

Source

pub fn select(&mut self, index: Option<u64>)

Shows the scopes of the frame numbered index, or of none.

Source

pub fn set_note(&mut self, note: impl Display)

Sets the line the window shows under its buttons, such as where a trace was written; an empty one shows nothing.

Source

pub fn show(&mut self, ui: &mut Ui<'_>) -> ProfilerResponse

Fills a window: a checkbox that pauses it, a “Write trace” button, the note, graphs of each frame’s processor time and of its GPU time on one scale, 0 to 33 ms (the oldest on the left, a frame with no GPU time a gap), which say the frame under the pointer and select the one clicked, and the selected frame’s GPU passes, and its scopes as a tree, each with how long it took.

Source

pub fn trace_json(&self) -> String

The frames it holds as Chrome trace event JSON, which Perfetto UI and chrome://tracing open: {"traceEvents": [...]}, a name for the thread, main, then for each frame a complete event ("ph": "X") named frame, with its number and processor time as arguments, and one for each of its scopes, in the order they started, a parent before its children.

When a frame it holds has its GPU time, a second track, named gpu, holds for each such frame an event frame, with its number and GPU time as arguments, over its passes, world then output. The GPU’s timers measure how long, not when: each frame’s passes are placed one after the other from when its drawing started, or from the end of the frame before on the track if that is later, as a GPU does one frame’s work after another’s. So their lengths are the GPU’s, and where they start an estimate. Taking the timers’ times as exact, a frame’s start is never before its drawing started, nor after the GPU started its world pass’s timer; a frame placed from its drawing’s start is early by at least the time until the renderer began timing its world pass, and one placed after the frame before by at least as much as that one, less up to a microsecond for the rounding below.

Times are whole microseconds from the oldest frame’s start, each start and end rounded down, so that, for a reader that converts them to nanoseconds, a scope stays inside its parent’s event, two in a row never overlap, and a frame ends where the next starts, exactly. A scope shorter than a microsecond may become an instant, which at its parent’s end a reader may show beside it. A scope that started before the oldest frame starts at 0, and ends where it ended.

Trait Implementations§

Source§

impl Default for Profiler

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