Skip to main content

StageStats

Struct StageStats 

Source
pub struct StageStats {
    pub count: u64,
    pub sum_ns: u64,
    pub min_ns: u64,
    pub max_ns: u64,
    pub same_instant: u64,
    pub backwards: u64,
    pub unstamped: u64,
    pub histogram: [u64; 960],
}
Expand description

Fixed-size, non-allocating per-stage statistics: count, total, min, max, plus an HDR-style sub-bucketed histogram for percentile estimation, plus the three non-sample tallies that say why an observation produced no number at all.

count, sum_ns, min_ns and max_ns are exact. Quantiles are estimated from the histogram and carry at most 3.125% relative error (exactly, for deltas below 32 ns); see HISTOGRAM_BUCKETS.

§Not Copy

The histogram dominates the struct — a StageStats is HISTOGRAM_BUCKETS × 8 bytes plus a handful of counters, several kilobytes in total. It was Copy once, which made every by-value use a silent multi-kilobyte memcpy; it is Clone-only now so a copy has to be asked for. Reach for summary when all you want is the numbers — a HopStats is small and genuinely Copy.

Fields§

§count: u64

Number of measured deltas recorded for this stage — strictly positive ones. Exact. See same_instant for the zero-delta observations, which are counted but not measured.

§sum_ns: u64

Total of every recorded delta, in nanoseconds; saturating. Exact. Divide by count for the mean.

§min_ns: u64

Smallest delta seen, in nanoseconds. Exact. u64::MAX before the first observation.

§max_ns: u64

Largest delta seen, in nanoseconds. Exact. Zero before the first observation.

§same_instant: u64

Observations where both stamps were present and identical, i.e. the two stages ran in the same engine cycle and shared Ctx::wall_time’s per-cycle snap.

These are deliberately not folded into the histogram as 0 ns samples. A hop that is structurally unmeasurable is not a hop that took under a nanosecond, and recording it as one drags min, mean and p50 to zero — which is exactly how a report can read count 120, min 0, p99 0 for a pair of stages that were never separately timed at all. Stamp with Stamping::Precise to turn these into real measurements.

§backwards: u64

Observations rejected because the later stage’s stamp preceded the earlier one’s. In one process this cannot happen; across processes it is the signature of unsynchronised clocks, and a non-zero tally here is the difference between “this hop is fast” and “these numbers are meaningless”.

§unstamped: u64

Observations skipped because one of the two stamps was never written (still zero). Distinguishes “this hop is not instrumented” from “this hop is instrumented and every sample was thrown away”.

§histogram: [u64; 960]

Sub-bucketed delta counts; see HISTOGRAM_BUCKETS for the layout. Read quantiles out of it with StageStats::quantile_ns rather than indexing it directly — the bucket layout is not part of the API contract.

Implementations§

Source§

impl StageStats

Source

pub fn record(&mut self, delta_ns: u64)

Fold one stage delta in: bumps count/sum_ns, widens the min/max, and increments the histogram bucket it falls in. Allocation-free, so it is safe on the graph path.

Source

pub fn mean_ns(&self) -> u64

Mean delta in nanoseconds, or 0 if no samples recorded.

Source

pub fn quantile_ns(&self, q: f64) -> u64

Estimate the value at quantile q in [0.0, 1.0], or 0 if no samples have been recorded. q outside [0, 1] is clamped.

The rank is located in the histogram and then interpolated within its bucket, so the estimate sits inside the bucket rather than at its edge, and the result is clamped to the exactly-tracked [min_ns, max_ns]. Two properties follow, both of which the previous log2 implementation broke: the result is always a value the stage could actually have observed, and it is monotonic in q.

Source

pub fn reset(&mut self)

Drop every sample and tally, returning the stage to its zeroed state.

The building block of a windowed report: read a summary, reset, and the next read describes only the period since. Cumulative-since-start statistics cannot do that — one outlier pins the p99 for the rest of the process’s life, which is the difference between a gauge that tracks the system and one that records its worst moment forever.

Source

pub fn observations(&self) -> u64

Every observation this stage saw, measured or not: count + same_instant + backwards + unstamped.

Equal to the number of messages the report sink observed, for a stage index that exists on the record — so a count well below it says a large share of observations produced no measurement, and the three tallies say which kind.

Source

pub fn summary(&self, from: &'static str, to: &'static str) -> HopStats

A small, Copy snapshot of this stage’s numbers, labelled with the hop it describes.

Quantiles are evaluated once, here, rather than on every read — which is what makes a HopStats cheap to pass around and to hold in a stream value, where a StageStats would drag its whole histogram along.

Source

pub fn summary_unlabelled(&self) -> HopStats

summary with empty labels — for an aggregator whose stage names are runtime strings rather than &'static str (the Python bindings), which applies its own labels afterwards. Keeping the numbers here means the sentinel rule and the quantile set exist in one place.

Trait Implementations§

Source§

impl Clone for StageStats

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 StageStats

Source§

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

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

impl Default for StageStats

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.