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
impl Profiler
Sourcepub fn push(&mut self, timing: FrameTiming, records: &[ScopeRecord])
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.
Sourcepub fn next_index(&self) -> u64
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.
Sourcepub fn set_gpu(&mut self, index: u64, timing: GpuTiming) -> bool
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.
Sourcepub fn frames(&self) -> impl ExactSizeIterator<Item = ProfiledFrame<'_>> + '_
pub fn frames(&self) -> impl ExactSizeIterator<Item = ProfiledFrame<'_>> + '_
The frames it holds, the oldest first.
Sourcepub fn frame(&self, index: u64) -> Option<ProfiledFrame<'_>>
pub fn frame(&self, index: u64) -> Option<ProfiledFrame<'_>>
The frame numbered index, if it holds it.
Sourcepub fn frame_rate(&self) -> f32
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.
Sourcepub fn set_paused(&mut self, paused: bool)
pub fn set_paused(&mut self, paused: bool)
Pauses it, or lets it record again.
Sourcepub fn selected(&self) -> Option<u64>
pub fn selected(&self) -> Option<u64>
The number of the frame whose scopes the window shows, if any.
Sourcepub fn select(&mut self, index: Option<u64>)
pub fn select(&mut self, index: Option<u64>)
Shows the scopes of the frame numbered index, or of none.
Sourcepub fn set_note(&mut self, note: impl Display)
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.
Sourcepub fn show(&mut self, ui: &mut Ui<'_>) -> ProfilerResponse
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.
Sourcepub fn trace_json(&self) -> String
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.