#[non_exhaustive]pub struct DerivedMetricDef {
pub name: &'static str,
pub ladder: ScaleLadder,
pub description: &'static str,
pub inputs: &'static [&'static str],
pub is_ratio: bool,
pub compute: fn(&BTreeMap<String, Aggregated>) -> Option<DerivedValue>,
pub section: Section,
}Expand description
Definition of a derived metric: a function that consumes the already-aggregated input metrics for a group and produces a single scalar (with its own unit and operator-facing description).
The compute fn returns None when an input metric is missing
from the group’s metrics map (capture-side gated by a kernel
CONFIG that wasn’t enabled, or jemalloc not linked) OR when
the formula would divide by zero. The renderer surfaces a
None cell as - so the operator can distinguish “not
computable” from “computed as zero”.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: &'static str§ladder: ScaleLadderAuto-scale ladder for the cell. ScaleLadder::None for
ratio rows (renders as a bare three-decimal scalar with
no suffix), ScaleLadder::Ns / ScaleLadder::Bytes /
etc. for unit-bearing derivations. The same closed-match
dispatch AggRule::ladder feeds.
description: &'static strOperator-facing one-line description; surfaced by the
ctprof metric-list subcommand.
inputs: &'static [&'static str]Names of input metrics from CTPROF_METRICS. Pure
documentation — surfaces in the metric-list output so
the operator sees what each derivation depends on.
is_ratio: boolRender-shape flag for dimensionless quantities. When true,
the renderer (1) suppresses the % (delta_pct) column,
(2) renders the value as N.NNN with three decimals
instead of routing through the auto-scale ladder, and
(3) renders the delta as +/-N.NNN (no scaled unit
suffix).
The [0, 1] interval is the common case where this flag
applies: cpu_efficiency, affine_success_ratio, and
involuntary_csw_ratio all live in [0, 1]. Delta on a
[0, 1] ratio reads as percentage points
(0.5 → 0.6 = +0.100 = +10pp), and delta / baseline as
a fraction (the % column) becomes confusing — +20% on
a [0, 1] ratio is already in percentage points, so a
percentage-of-percentage readout double-encodes the
signal.
disk_io_fraction (range [0, ∞)) carries is_ratio: true
for the rendering shape but does NOT satisfy the
percentage-points interpretation: a value of 1.5 is
possible (readahead pulls more block-device bytes than
the syscall requested), so a delta of +0.100 reads as
“ratio rose by 0.1” rather than “ratio rose by 10
percentage points.” The render shape is still correct
(suppress %, three decimals, no auto-scale) — only the
pp interpretation is invalid.
compute: fn(&BTreeMap<String, Aggregated>) -> Option<DerivedValue>The computation. Pulls input scalars from the group’s
metrics map via Aggregated::numeric() and produces the
derived scalar.
section: SectionSection this derived metric belongs to for the
--sections per-row filter, mirroring
CtprofMetricDef::section. Most derivations tag
Section::Derived; the 9 derivations whose inputs are
taskstats fields (the eight avg_*_delay_ns averages
plus total_offcpu_delay_ns) tag
Section::TaskstatsDelay so an operator running
--sections taskstats-delay gets a full taskstats view
— the 34 raw rows AND the 9 derivations that depend on
them — without dragging in unrelated derived metrics.
The ## Derived metrics table emitter checks
DisplayOptions::is_section_enabled per row before
rendering, and the outer-table gate opens whenever EITHER
section in the rendered set is enabled.
Trait Implementations§
Source§impl Clone for DerivedMetricDef
impl Clone for DerivedMetricDef
Source§fn clone(&self) -> DerivedMetricDef
fn clone(&self) -> DerivedMetricDef
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DerivedMetricDef
impl Debug for DerivedMetricDef
impl Copy for DerivedMetricDef
Auto Trait Implementations§
impl Freeze for DerivedMetricDef
impl RefUnwindSafe for DerivedMetricDef
impl Send for DerivedMetricDef
impl Sync for DerivedMetricDef
impl Unpin for DerivedMetricDef
impl UnwindSafe for DerivedMetricDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more