Skip to main content

Module tick_profile

Module tick_profile 

Source
Expand description

Fixed-window latency profiling for the phases inside crate::NativeRuntime::tick.

Before this module existed, “the node burns CPU with zero live PTY sessions” had no number attached to it anywhere in the process – tick() ran six distinct pieces of work every call (drain observations, drain ingress, reduce the control plane, dispatch effects, publish the step, and walk the provider supervisors) and none of them were timed. This module gives each of those six phases its own always-on reading.

Two contracts every series here honours, mirrored from hatchery-tui’s profile.rs (that crate is a different workspace and is not a dependency of this one, so the types are re-derived here rather than imported – see that module’s own doc comment for the same reasoning spelled out for the TUI’s redraw loop):

  • Distributions, not an average. A mean spreads one expensive tick across 255 idle ones and reports a number nobody can act on. Every phase keeps the last SAMPLE_WINDOW samples in a fixed ring (RingStats) and reports p50/p95/max plus the sample count, computed on demand rather than tracked incrementally.
  • Always-on cheap, no allocation after construction. push is an array write and an index bump. The O(N log N) sort behind stats() only runs when something actually reads a snapshot (an HTTP /metrics request), never once per tick – so this stays cheap enough to leave enabled unconditionally, which is the only way it can ever catch the stall it exists to find.

Structs§

Distribution
One windowed phase’s current reading: nearest-rank p50/p95/max over whatever RingStats currently holds, plus count – the denominator a reader must check alongside the three numbers, since count below SAMPLE_WINDOW means “the process hasn’t produced a full window yet,” not “the window is smaller than advertised.”
RingStats
Fixed-size ring buffer of u32 samples. push overwrites the oldest entry once full – the only state this holds is values/len/next, all stack-sized by the const generic N, so a profiler holding several of these never allocates past its own construction.
TickPhaseProfiler
Owns the six per-phase rings NativeRuntime::tick writes into every call. Lives on NativeRuntime itself (not a side channel) so the timing and the work it describes can never drift apart.
TickProfileSnapshot
One snapshot of every phase’s current distribution – what crate::NativeRuntime::tick_profile_snapshot returns.

Constants§

SAMPLE_WINDOW
Ring capacity shared by every phase below – “the last 256 ticks,” never an average across the process lifetime. At the ~10ms drive-loop cadence this is a little over 2.5 seconds of tick history, enough to catch a transient stall without growing unbounded.

Functions§

duration_micros
Clamped Duration -> microsecond sample: a tick phase measured in hours would mean the process already hung far worse than this profiler needs to describe, so this saturates at u32::MAX rather than panicking or widening every sample to a u128.