pub struct FrameProfiler { /* private fields */ }Expand description
Named-stage, per-frame profiler with independent EMA smoothing per
stage — the generic mechanism behind the source app’s own
FrameProfile. Stage names are caller-supplied &'static str keys
(e.g. "grid", "scene_build", "overlay"), not a fixed enum, so
any app’s own frame-phase vocabulary ports over unchanged.
Clock-free by design (module doc) — the caller measures each stage
with whatever monotonic clock its platform has and feeds the elapsed
milliseconds into FrameProfiler::record_ms.
Implementations§
Source§impl FrameProfiler
impl FrameProfiler
Sourcepub const DEFAULT_ALPHA: f64 = 0.08
pub const DEFAULT_ALPHA: f64 = 0.08
The source app’s own smoothing constant
(previous * 0.92 + sample * 0.08).
Sourcepub fn new(alpha: f64) -> Self
pub fn new(alpha: f64) -> Self
A profiler smoothing every stage at alpha (see EmaF64::update).
Sourcepub fn record_ms(&mut self, stage: &'static str, sample_ms: f64)
pub fn record_ms(&mut self, stage: &'static str, sample_ms: f64)
Record a caller-measured sample in milliseconds for stage,
folding it into that stage’s own running EMA — the stage’s
tracker is created (uninitialized) on first use, so its own first
sample wins outright rather than blending against a synthetic
0.0.
Sourcepub fn stage_ms(&self, stage: &str) -> f64
pub fn stage_ms(&self, stage: &str) -> f64
Current smoothed value (ms) for stage, or 0.0 if it has never
been recorded.
Sourcepub fn stages(&self) -> impl Iterator<Item = (&'static str, f64)> + '_
pub fn stages(&self) -> impl Iterator<Item = (&'static str, f64)> + '_
Every currently-tracked stage’s smoothed value — iteration order
is NOT guaranteed (backed by a HashMap); a caller that needs a
fixed field order should read FrameProfiler::stage_ms per
named stage instead.
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Total frames FrameProfiler::end_frame has been called for.