euv-performance 0.46.1

Reproducible CPU, layout, rasterization, and allocation benchmarks for the cross-platform euv runtime.
Documentation
use super::*;

/// Inherent implementation of [`ObservabilityCoverage`].
impl ObservabilityCoverage {
    /// Returns the optional diagnostic reason explaining missing/unsupported coverage.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Coverage item reference.
    ///
    /// # Returns
    ///
    /// - `Option<&str>` - Reason text when present.
    #[must_use]
    pub fn reason_value(&self) -> Option<&str> {
        let Self { reason, .. } = self;
        reason.as_deref()
    }
}

/// Inherent implementation of [`ObservabilityMetric`].
impl ObservabilityMetric {
    /// Creates a measured common scalar metric conforming to `schemas/report-v1.schema.json`.
    ///
    /// # Arguments
    ///
    /// - `&str` - Canonical catalog metric ID.
    /// - `&str` - Coverage scope name.
    /// - `ObservabilityUnit` - Canonical metric unit.
    /// - `&str` - Sampling window label.
    /// - `ObservabilityStatistic` - Summary statistic tag.
    /// - `f64` - Measured scalar value.
    ///
    /// # Returns
    ///
    /// - `Self` - Measured common metric entry.
    #[must_use]
    pub fn measured_common(
        id: &str,
        scope: &str,
        unit: ObservabilityUnit,
        window: &str,
        statistic: ObservabilityStatistic,
        value: f64,
    ) -> Self {
        Self {
            id: id.to_string(),
            scope: scope.to_string(),
            unit,
            status: ObservabilityMetricStatus::Measured,
            window: window.to_string(),
            statistic,
            value: Some(value),
            baseline: None,
            after_drain: None,
            slope_per_cycle: None,
            samples: None,
            source: Some(OBS_SOURCE_EUV_PERF.to_string()),
            clock: Some(OBS_CLOCK_MONOTONIC.to_string()),
            sample_rate_hz: None,
            reason: None,
            evidence_refs: Vec::new(),
            threshold: None,
        }
    }

    /// Creates a measured leak/lifecycle metric carrying explicit `baseline`, `after_drain`, and `slope_per_cycle`.
    ///
    /// # Arguments
    ///
    /// - `&str` - Canonical catalog leak metric ID.
    /// - `&str` - Coverage scope name.
    /// - `ObservabilityUnit` - Canonical metric unit.
    /// - `&str` - Sampling window label.
    /// - `f64` - Post-warmup baseline value.
    /// - `f64` - Post-drain value.
    /// - `f64` - Linear slope per lifecycle cycle.
    ///
    /// # Returns
    ///
    /// - `Self` - Measured leak metric entry.
    #[must_use]
    pub fn measured_leak(
        id: &str,
        scope: &str,
        unit: ObservabilityUnit,
        window: &str,
        baseline: f64,
        after_drain: f64,
        slope_per_cycle: f64,
    ) -> Self {
        Self {
            id: id.to_string(),
            scope: scope.to_string(),
            unit,
            status: ObservabilityMetricStatus::Measured,
            window: window.to_string(),
            statistic: ObservabilityStatistic::LiveCount,
            value: None,
            baseline: Some(baseline),
            after_drain: Some(after_drain),
            slope_per_cycle: Some(slope_per_cycle),
            samples: None,
            source: Some(OBS_SOURCE_REACTIVE_ARENA.to_string()),
            clock: Some(OBS_CLOCK_MONOTONIC.to_string()),
            sample_rate_hz: None,
            reason: None,
            evidence_refs: Vec::new(),
            threshold: None,
        }
    }

    /// Attaches a sample count to this metric entry.
    ///
    /// # Arguments
    ///
    /// - `Self` - Metric builder.
    /// - `u64` - Sample count collected during the window.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated metric entry.
    #[must_use]
    pub fn with_samples(mut self, samples: u64) -> Self {
        let Self { samples: slot, .. } = &mut self;
        *slot = Some(samples);
        self
    }

    /// Attaches a budget threshold to this metric entry.
    ///
    /// # Arguments
    ///
    /// - `Self` - Metric builder.
    /// - `ObservabilityThreshold` - Budget threshold contract.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated metric entry.
    #[must_use]
    pub fn with_threshold(mut self, threshold: ObservabilityThreshold) -> Self {
        let Self {
            threshold: slot, ..
        } = &mut self;
        *slot = Some(threshold);
        self
    }

    /// Attaches linked evidence identifiers to this metric entry.
    ///
    /// # Arguments
    ///
    /// - `Self` - Metric builder.
    /// - `Vec<String>` - Evidence reference IDs.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated metric entry.
    #[must_use]
    pub fn with_evidence_refs(mut self, refs: Vec<String>) -> Self {
        let Self { evidence_refs, .. } = &mut self;
        *evidence_refs = refs;
        self
    }

    /// Returns the measured scalar value when present.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Metric reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Scalar value.
    #[must_use]
    pub fn scalar_value(&self) -> Option<f64> {
        let Self { value, .. } = *self;
        value
    }

    /// Returns the baseline leak measurement when present.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Metric reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Baseline value.
    #[must_use]
    pub fn baseline_value(&self) -> Option<f64> {
        let Self { baseline, .. } = *self;
        baseline
    }

    /// Returns the post-drain leak measurement when present.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Metric reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Post-drain value.
    #[must_use]
    pub fn after_drain_value(&self) -> Option<f64> {
        let Self { after_drain, .. } = *self;
        after_drain
    }

    /// Returns the per-cycle leak slope when present.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Metric reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Slope per cycle.
    #[must_use]
    pub fn slope_per_cycle_value(&self) -> Option<f64> {
        let Self {
            slope_per_cycle, ..
        } = *self;
        slope_per_cycle
    }

    /// Returns `true` if any numeric sample field (`value`, `baseline`, `after_drain`, `slope_per_cycle`) is populated.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Metric reference.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether numeric measurements are present.
    #[must_use]
    pub fn has_any_numeric_value(&self) -> bool {
        let Self {
            value,
            baseline,
            after_drain,
            slope_per_cycle,
            ..
        } = *self;
        value.is_some() || baseline.is_some() || after_drain.is_some() || slope_per_cycle.is_some()
    }
}