PerfDeltaAssertion

Struct PerfDeltaAssertion 

Source
pub struct PerfDeltaAssertion { /* private fields */ }
Expand description

A per-test performance-regression assertion that cargo ktstr perf-delta --noise-adjust enforces when this test is compared across two commits — and that a normal cargo ktstr test run IGNORES.

Enforced ONLY under --noise-adjust. A declared gate is a CI-gating perf assertion; gating on a single-run scalar comparison would flip CI on noise, so the multi-run --noise-adjust path (Welch + disjoint-band separation) is the only statistically sound basis. Plain perf-delta (scalar) does NOT evaluate declared gates — it warns that they were skipped. Declaring a gate also REQUIRES performance_mode (validated at compile time by the macro and at discovery time by KtstrTestEntry::validate) so the compared data is pinned.

Inert-as-a-test / active-under-perf-delta is by CONSTRUCTION, not a runtime flag: the in-VM verdict path consults only crate::assert::Assert, never a PerfDeltaAssertion, so declaring one changes no normal-run verdict or exit code. It becomes active only because perf-delta serializes the declaration into the sidecar and consults it in the host-side --noise-adjust compare.

A declaration names a registry metric and OVERRIDES, for this test, the gate that decides a confident regression on it: a tighter relative threshold, an absolute floor, a pinned direction, and/or a phase scope. It LAYERS ON TOP of the --noise-adjust default all-metrics regression net (which still runs, to catch unknown-unknown regressions) — it is an explicit contract check, not a whitelist that narrows the net.

Declare by binding each gate to a const and listing it on the macro: const RPS_GATE: PerfDeltaAssertion = PerfDeltaAssertion::new("rps_p50").with_max_regression_pct(5.0); then #[ktstr_test(performance_mode = true, perf_delta_assertions = [RPS_GATE])]. Or directly on a programmatically-built KtstrTestEntry: perf_delta_assertions: &[&RPS_GATE] — bind the const first; a chained inline &PerfDeltaAssertion::new(..).with_*(..) does NOT rvalue-promote to 'static in a non-const KtstrTestEntry { .. } literal (E0716). Construct via PerfDeltaAssertion::new + the const fn with_* builders; fields are crate-private so every value passes the compile-time format gate. The type is Copy over a &'static str metric (no Drop, E0493-safe); the owned form the sidecar serializes is a separate internal mirror, crate::test_support::PerfDeltaAssertionRecord.

Implementations§

Source§

impl PerfDeltaAssertion

Source

pub const fn new(metric: &'static str) -> Self

Const constructor for use in static/const context. metric is a registry metric name (see cargo ktstr stats list-metrics); the remaining knobs default to the registry values and are set via the builders below.

§Panics

Panics at compile time when metric is empty, contains whitespace or a path separator (/, \), or a non-printable / high-bit byte. That the name RESOLVES in the metric registry is checked at run time by KtstrTestEntry::validate (the registry is not const-accessible).

Source

pub const fn with_max_regression_pct(self, pct: f64) -> Self

Override the relative-regression gate (percent) for this metric: a worsening move larger than pct% of the baseline gates. None (unset) inherits the registry default_rel. pct must be finite and >= 0 (enforced at discovery time by KtstrTestEntry::validate).

Source

pub const fn with_min_abs(self, min: f64) -> Self

Override the absolute-materiality floor for this metric: a move smaller than min in absolute units never gates, regardless of the relative threshold. None (unset) inherits the registry default_abs. min must be finite and >= 0 (enforced at discovery time by KtstrTestEntry::validate).

Source

pub const fn with_direction(self, polarity: Polarity) -> Self

Pin the regression DIRECTION for this metric instead of inheriting the registry polarity (e.g. assert a metric the registry treats as Informational as LowerBetter for this test).

§Panics

Panics at compile time on crate::test_support::Polarity::TargetValue: symmetric target-distance gating is not implemented, and the compare polarity path would silently treat it as increase-is-worse. Use HigherBetter, LowerBetter, or Informational.

Source

pub const fn with_phase(self, step_index: u16) -> Self

Scope the assertion to a single phase (step_index: 0 = BASELINE, 1..=N = scenario Step ordinals). None (unset) gates the aggregate (whole-run) value. Unlike the render-only per-phase spread tables, a phase-scoped assertion DOES contribute to the perf-delta --noise-adjust exit code (the scalar perf-delta path warns and skips all declared gates, phase-scoped included).

Source

pub const fn metric(&self) -> &'static str

The registry metric name this assertion gates.

Source

pub const fn direction(&self) -> Option<Polarity>

The pinned regression direction, or None to inherit the registry polarity.

Source

pub const fn max_regression_pct(&self) -> Option<f64>

The relative-regression override (percent), or None for the registry default_rel.

Source

pub const fn min_abs(&self) -> Option<f64>

The absolute-materiality override, or None for the registry default_abs.

Source

pub const fn phase(&self) -> Option<u16>

The phase scope (step_index), or None to gate the aggregate value.

Trait Implementations§

Source§

impl Clone for PerfDeltaAssertion

Source§

fn clone(&self) -> PerfDeltaAssertion

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PerfDeltaAssertion

Source§

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

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

impl From<&PerfDeltaAssertion> for PerfDeltaAssertionRecord

Source§

fn from(a: &PerfDeltaAssertion) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for PerfDeltaAssertion

Source§

fn eq(&self, other: &PerfDeltaAssertion) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for PerfDeltaAssertion

Source§

impl StructuralPartialEq for PerfDeltaAssertion

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,