pub enum Polarity {
HigherBetter,
LowerBetter,
TargetValue(f64),
Unknown,
Informational,
}Expand description
Regression direction for a metric.
Used by cargo ktstr test-stats to classify deltas between runs.
Declared explicitly on MetricHint; unhinted metrics default to
Polarity::Unknown and are recorded without regression
classification.
Variants§
HigherBetter
Bigger is better (throughput, IOPS, bogo_ops/sec). Regression = decrease from baseline.
LowerBetter
Smaller is better (latency percentiles, error rates). Regression = increase from baseline.
TargetValue(f64)
A target value that the metric should hover near. Regression
= absolute distance exceeds a threshold, symmetric in either
direction. The inner f64 MUST be finite (not NaN/inf);
construct via Polarity::target, which enforces this at
runtime in both debug and release.
Unknown
Direction not declared; the metric is recorded but not
classified as regression-relevant. This is the CONSERVATIVE
default for an UNCLASSIFIED metric: the comparison path treats
it as higher-is-worse (see MetricDef::higher_is_worse /
classify_direction) so a real regression in a metric someone
forgot to classify is still caught rather than silently ignored.
Informational
Deliberately directionless: the metric is recorded and DISPLAYED
in comparisons but is NEVER classified as a regression or
improvement and NEVER affects the exit code. Distinct from
Polarity::Unknown (the conservative higher-is-worse default
for unclassified metrics): Informational is the explicit
“this counter has no good/bad direction” choice — e.g. wakeup /
context-switch / yield counts, where more is neither inherently
better nor worse. classify_direction returns None for it.
Implementations§
Source§impl Polarity
impl Polarity
Sourcepub const fn from_higher_is_worse(higher_is_worse: bool) -> Polarity
pub const fn from_higher_is_worse(higher_is_worse: bool) -> Polarity
Map the legacy higher_is_worse: bool used by
MetricDef to a Polarity.
The sense is INVERSE: true (bigger values are regressions)
maps to Polarity::LowerBetter (we want the metric to go
down); false maps to Polarity::HigherBetter.
Sourcepub const fn classify_direction(&self) -> Option<bool>
pub const fn classify_direction(&self) -> Option<bool>
The regression direction of this polarity: Some(true) = an INCREASE is
a regression (LowerBetter / TargetValue / the conservative Unknown),
Some(false) = a DECREASE is a regression (HigherBetter), None =
directionless (Informational, never gates). The single source of truth
that MetricDef::classify_direction delegates to.
Sourcepub fn target(target: f64) -> Polarity
pub fn target(target: f64) -> Polarity
Construct a Polarity::TargetValue from a finite target.
§Panics
Panics in both debug and release builds when target is not
finite (NaN, +inf, -inf). Non-finite values produce
incorrect regression verdicts in the comparison pipeline, so
the check runs unconditionally rather than via
debug_assert!.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Polarity
impl<'de> Deserialize<'de> for Polarity
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Polarity
impl StructuralPartialEq for Polarity
Auto Trait Implementations§
impl Freeze for Polarity
impl RefUnwindSafe for Polarity
impl Send for Polarity
impl Sync for Polarity
impl Unpin for Polarity
impl UnwindSafe for Polarity
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