euv-performance 0.46.0

Reproducible CPU, layout, rasterization, and allocation benchmarks for the cross-platform euv runtime.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
use super::*;

/// Resolves the current host platform enum and OS display name without dead-code cfg gaps.
///
/// # Returns
///
/// - `(ObservabilityPlatform, &'static str)` - Host platform enum and OS name.
#[must_use]
pub(crate) fn host_observability_platform() -> (ObservabilityPlatform, &'static str) {
    match OS {
        OBS_OS_KEY_MACOS => (ObservabilityPlatform::Macos, OBS_OS_MACOS),
        OBS_OS_KEY_WINDOWS => (ObservabilityPlatform::Windows, OBS_OS_WINDOWS),
        _ => (ObservabilityPlatform::Linux, OBS_OS_LINUX),
    }
}

/// Runs a deterministic reactive owner-dispose verification probe and returns remaining live subscribers.
///
/// # Returns
///
/// - `u64` - Remaining live destroyed-owner subscriber count (expected `0`).
#[must_use]
pub(crate) fn probe_destroyed_owner_live_objects() -> u64 {
    reset_reactive_runtime();
    let probe_sig: Signal<u32> = Signal::new(1);
    let (scope, _memo): (Scope, Memo<u32>) = Scope::run(|_: Scope| {
        let derived: Memo<u32> = Memo::new(move || probe_sig.get().wrapping_mul(3));
        let _: u32 = derived.get();
        derived
    });
    scope.dispose();
    if probe_sig.has_subscribers() { 1 } else { 0 }
}

/// Converts a `StressMatrixReport` into a schema-v1 `ObservabilityReportV1` matching `schemas/report-v1.schema.json`.
///
/// # Arguments
///
/// - `&StressMatrixReport` - Completed stress-matrix benchmark report.
/// - `&str` - Git commit SHA or label (falls back to `OBSERVABILITY_DEFAULT_COMMIT` when empty).
/// - `&str` - Build profile string (falls back to `OBSERVABILITY_DEFAULT_PROFILE` when empty).
///
/// # Returns
///
/// - `ObservabilityReportV1` - Validatable observability report with honest scope coverage and zero fabricated metrics.
#[must_use]
pub fn emit_stress_observability_report(
    report: &StressMatrixReport,
    commit: &str,
    profile: &str,
) -> ObservabilityReportV1 {
    let (platform, os_name): (ObservabilityPlatform, &'static str) = host_observability_platform();
    let resolved_commit: String = if commit.trim().is_empty() {
        OBSERVABILITY_DEFAULT_COMMIT.to_string()
    } else {
        commit.trim().to_string()
    };
    let resolved_profile: String = if profile.trim().is_empty() {
        OBSERVABILITY_DEFAULT_PROFILE.to_string()
    } else {
        profile.trim().to_string()
    };
    let total_cycles: u64 = report
        .get_entries()
        .iter()
        .map(|entry: &StressMatrixEntry| entry.get_latency().get_iterations() as u64)
        .sum();
    let primary_latency: LatencyDistribution = report
        .partial_damage_ab()
        .map(PartialDamageAbSummary::get_candidate_partial_damage)
        .or_else(|| {
            report
                .get_entries()
                .first()
                .map(StressMatrixEntry::get_latency)
        })
        .unwrap_or_default();
    let primary_iters: u64 = primary_latency.get_iterations().max(1) as u64;
    let frame_p95_ms: f64 = primary_latency.get_p95_us() / 1_000.0;
    let dirty_ratio: f64 = primary_latency.get_mean_dirty_area_ratio().clamp(0.0, 1.0);
    let full_redraws: u64 = primary_latency.get_full_redraw_count() as u64;
    let destroyed_live: u64 = probe_destroyed_owner_live_objects();
    let ev_refs: Vec<String> = vec![OBS_EVIDENCE_ID_STRESS.to_string()];
    let mut findings: Vec<ObservabilityFinding> = Vec::new();
    let mut failed: bool = false;
    if let Some(ab) = report.partial_damage_ab()
        && !ab.get_bit_exact_parity()
    {
        failed = true;
        findings.push(ObservabilityFinding::new(
            ObservabilityFindingClass::BudgetViolation,
            Some(OBS_OWNER_PARTIAL_DAMAGE.to_string()),
            Some(OBS_FINDING_PARITY_MISMATCH.to_string()),
            ev_refs.clone(),
        ));
    }
    if frame_p95_ms > OBS_THRESHOLD_FRAME_P95_MS || destroyed_live > 0 {
        failed = true;
    }
    let metrics: Vec<ObservabilityMetric> = vec![
        ObservabilityMetric::measured_common(
            OBS_METRIC_FRAME_INTERVAL,
            OBS_SCOPE_FRAME,
            ObservabilityUnit::Ms,
            OBS_WINDOW_STRESS_ITERS,
            ObservabilityStatistic::P95,
            frame_p95_ms,
        )
        .with_samples(primary_iters)
        .with_threshold(ObservabilityThreshold::new(
            ObservabilityThresholdRule::Max,
            Some(OBS_THRESHOLD_FRAME_P95_MS),
            OBS_UNIT_MS.to_string(),
            OBSERVABILITY_BUDGET_VERSION_V1.to_string(),
        ))
        .with_evidence_refs(ev_refs.clone()),
        ObservabilityMetric::measured_common(
            OBS_METRIC_FRAME_COUNT,
            OBS_SCOPE_FRAME,
            ObservabilityUnit::Count,
            OBS_WINDOW_STRESS_ITERS,
            ObservabilityStatistic::Total,
            total_cycles as f64,
        )
        .with_samples(total_cycles)
        .with_evidence_refs(ev_refs.clone()),
        ObservabilityMetric::measured_common(
            OBS_METRIC_LAYOUT_INVALIDATIONS,
            OBS_SCOPE_LAYOUT,
            ObservabilityUnit::Count,
            OBS_WINDOW_STRESS_ITERS,
            ObservabilityStatistic::Total,
            primary_iters as f64,
        )
        .with_samples(primary_iters)
        .with_evidence_refs(ev_refs.clone()),
        ObservabilityMetric::measured_common(
            OBS_METRIC_LAYOUT_PASSES,
            OBS_SCOPE_LAYOUT,
            ObservabilityUnit::Count,
            OBS_WINDOW_STRESS_ITERS,
            ObservabilityStatistic::Total,
            primary_iters as f64,
        )
        .with_samples(primary_iters)
        .with_evidence_refs(ev_refs.clone()),
        ObservabilityMetric::measured_common(
            OBS_METRIC_LAYOUT_CHANGED_PASSES,
            OBS_SCOPE_LAYOUT,
            ObservabilityUnit::Count,
            OBS_WINDOW_STRESS_ITERS,
            ObservabilityStatistic::Total,
            primary_iters as f64,
        )
        .with_samples(primary_iters)
        .with_evidence_refs(ev_refs.clone()),
        ObservabilityMetric::measured_common(
            OBS_METRIC_LAYOUT_CHANGED_NODES,
            OBS_SCOPE_LAYOUT,
            ObservabilityUnit::Count,
            OBS_WINDOW_STRESS_ITERS,
            ObservabilityStatistic::Total,
            primary_iters as f64,
        )
        .with_samples(primary_iters)
        .with_evidence_refs(ev_refs.clone()),
        ObservabilityMetric::measured_common(
            OBS_METRIC_DIRTY_AREA_RATIO,
            OBS_SCOPE_LAYOUT,
            ObservabilityUnit::Ratio,
            OBS_WINDOW_STRESS_ITERS,
            ObservabilityStatistic::Mean,
            dirty_ratio,
        )
        .with_samples(primary_iters)
        .with_threshold(ObservabilityThreshold::new(
            ObservabilityThresholdRule::Max,
            Some(OBS_THRESHOLD_DIRTY_RATIO_MAX),
            OBS_UNIT_RATIO.to_string(),
            OBSERVABILITY_BUDGET_VERSION_V1.to_string(),
        ))
        .with_evidence_refs(ev_refs.clone()),
        ObservabilityMetric::measured_common(
            OBS_METRIC_FULL_REDRAW_COUNT,
            OBS_SCOPE_LAYOUT,
            ObservabilityUnit::Count,
            OBS_WINDOW_STRESS_ITERS,
            ObservabilityStatistic::Total,
            full_redraws as f64,
        )
        .with_samples(primary_iters)
        .with_threshold(ObservabilityThreshold::new(
            ObservabilityThresholdRule::Max,
            Some(OBS_THRESHOLD_FULL_REDRAW_MAX),
            OBS_UNIT_COUNT.to_string(),
            OBSERVABILITY_BUDGET_VERSION_V1.to_string(),
        ))
        .with_evidence_refs(ev_refs.clone()),
        ObservabilityMetric::measured_leak(
            OBS_METRIC_DESTROYED_OWNERS,
            OBS_SCOPE_LIFECYCLE,
            ObservabilityUnit::Count,
            OBS_WINDOW_POST_DRAIN,
            0.0,
            destroyed_live as f64,
            0.0,
        )
        .with_samples(1)
        .with_threshold(ObservabilityThreshold::new(
            ObservabilityThresholdRule::MaxDestroyedOwnerCount,
            Some(OBS_THRESHOLD_DESTROYED_OWNERS_MAX),
            OBS_UNIT_COUNT.to_string(),
            OBSERVABILITY_BUDGET_VERSION_V1.to_string(),
        ))
        .with_evidence_refs(ev_refs),
    ];
    let status: ObservabilityStatus = if failed {
        ObservabilityStatus::Fail
    } else {
        ObservabilityStatus::Pass
    };
    ObservabilityReportV1 {
        schema_version: OBSERVABILITY_SCHEMA_VERSION_V1.to_string(),
        target: ObservabilityTarget::new(
            platform,
            os_name.to_string(),
            OBS_DEVICE_HEADLESS_HOST.to_string(),
            OBS_BACKEND_SOFTWARE.to_string(),
            OBS_MODE_HEADLESS_STRESS.to_string(),
            Some(ObservabilityExecutionKind::Headless),
        ),
        build: ObservabilityBuild::new(
            resolved_commit,
            resolved_profile,
            Some(OBS_TOOL_VERSION.to_string()),
        ),
        tools: vec![ObservabilityTool::new(
            OBS_TOOL_NAME.to_string(),
            OBS_TOOL_VERSION.to_string(),
            OBS_TOOL_SCOPE.to_string(),
        )],
        workload: ObservabilityWorkload::new(
            OBS_FIXTURE_STRESS_MATRIX.to_string(),
            total_cycles,
            OBS_CHECKPOINT_POST_DRAIN.to_string(),
            Some(0),
            Some(0),
        ),
        status,
        coverage: vec![
            ObservabilityCoverage::new(
                OBS_SCOPE_FRAME.to_string(),
                true,
                ObservabilityCoverageStatus::Measured,
                None,
            ),
            ObservabilityCoverage::new(
                OBS_SCOPE_LAYOUT.to_string(),
                true,
                ObservabilityCoverageStatus::Measured,
                None,
            ),
            ObservabilityCoverage::new(
                OBS_SCOPE_LIFECYCLE.to_string(),
                true,
                ObservabilityCoverageStatus::Measured,
                None,
            ),
            ObservabilityCoverage::new(
                OBS_SCOPE_GPU.to_string(),
                false,
                ObservabilityCoverageStatus::NotApplicable,
                Some(OBS_REASON_NO_GPU_HEADLESS.to_string()),
            ),
            ObservabilityCoverage::new(
                OBS_SCOPE_NATIVE_HEAP.to_string(),
                false,
                ObservabilityCoverageStatus::Missing,
                Some(OBS_REASON_NO_EXT_HEAP_PROFILER.to_string()),
            ),
        ],
        metrics,
        findings,
        evidence: vec![ObservabilityEvidence::new(
            OBS_EVIDENCE_ID_STRESS.to_string(),
            OBS_EVIDENCE_ARTIFACT_STRESS.to_string(),
            None,
            true,
            Some(OBS_EVIDENCE_DESC_STRESS.to_string()),
        )],
    }
}

/// Serializes an `ObservabilityReportV1` into formatted JSON conforming to `schemas/report-v1.schema.json`.
///
/// # Arguments
///
/// - `&ObservabilityReportV1` - Observability report to serialize.
///
/// # Returns
///
/// - `String` - Pretty-printed JSON payload.
#[must_use]
pub fn observability_report_to_json(report: &ObservabilityReportV1) -> String {
    to_string_pretty(report).unwrap_or_default()
}

/// Performs in-process structural and semantic validation mirroring `.agents/skills/euv-performance/scripts/validate_report.py`.
///
/// # Arguments
///
/// - `&ObservabilityReportV1` - Candidate observability report.
///
/// # Returns
///
/// - `Result<(), Vec<String>>` - `Ok(())` when valid, or list of semantic/structural diagnostics.
pub fn validate_observability_report(report: &ObservabilityReportV1) -> Result<(), Vec<String>> {
    let mut errors: Vec<String> = Vec::new();
    if report.get_schema_version().as_str() != OBSERVABILITY_SCHEMA_VERSION_V1 {
        errors.push(OBS_ERR_SCHEMA_VERSION.to_string());
    }
    if report.get_tools().is_empty() {
        errors.push(OBS_ERR_EMPTY_TOOLS.to_string());
    }
    if report.get_coverage().is_empty() {
        errors.push(OBS_ERR_EMPTY_COVERAGE.to_string());
    }
    let evidence_ids: HashSet<&str> = report
        .get_evidence()
        .iter()
        .map(|ev: &ObservabilityEvidence| ev.get_id().as_str())
        .collect();
    let mut coverage_status: HashMap<&str, ObservabilityCoverageStatus> = HashMap::new();
    let mut missing_required: bool = false;
    for cov in report.get_coverage().iter() {
        let _: Option<ObservabilityCoverageStatus> =
            coverage_status.insert(cov.get_scope().as_str(), cov.get_status());
        if cov.get_required() && cov.get_status() != ObservabilityCoverageStatus::Measured {
            missing_required = true;
        }
    }
    let mut measured_ids: HashSet<&str> = HashSet::new();
    let mut layout_passes: Option<f64> = None;
    let mut layout_changed: Option<f64> = None;
    for metric in report.get_metrics().iter() {
        let scope_state: Option<ObservabilityCoverageStatus> =
            coverage_status.get(metric.get_scope().as_str()).copied();
        let scope_unmeasured: bool = matches!(
            scope_state,
            Some(
                ObservabilityCoverageStatus::Missing
                    | ObservabilityCoverageStatus::Unsupported
                    | ObservabilityCoverageStatus::NotApplicable
            )
        );
        if (metric.get_status() != ObservabilityMetricStatus::Measured || scope_unmeasured)
            && metric.has_any_numeric_value()
        {
            errors.push(format!("{}: {}", OBS_ERR_FAKE_ZERO, metric.get_id()));
        }
        for ev_ref in metric.get_evidence_refs().iter() {
            if !evidence_ids.contains(ev_ref.as_str()) {
                errors.push(format!("{}: {ev_ref}", OBS_ERR_BROKEN_EVIDENCE));
            }
        }
        if metric.get_status() == ObservabilityMetricStatus::Measured && !scope_unmeasured {
            let mid: &str = metric.get_id().as_str();
            let _: bool = measured_ids.insert(mid);
            if mid == OBS_METRIC_DESTROYED_OWNERS {
                if metric.baseline_value().is_none() || metric.after_drain_value().is_none() {
                    errors.push(OBS_ERR_LEAK_MISSING_BOUNDS.to_string());
                }
            } else if metric.scalar_value().is_none() {
                errors.push(format!("{}: {mid}", OBS_ERR_COMMON_MISSING_VALUE));
            }
            if mid == OBS_METRIC_LAYOUT_PASSES {
                layout_passes = metric.scalar_value();
            } else if mid == OBS_METRIC_LAYOUT_CHANGED_PASSES {
                layout_changed = metric.scalar_value();
            }
        }
    }
    if let (Some(passes), Some(changed)) = (layout_passes, layout_changed)
        && changed > passes
    {
        errors.push(OBS_ERR_LAYOUT_INVARIANT.to_string());
    }
    let mut has_blocking_finding: bool = false;
    for finding in report.get_findings().iter() {
        for ev_ref in finding.get_evidence_refs().iter() {
            if !evidence_ids.contains(ev_ref.as_str()) {
                errors.push(format!("{}: {ev_ref}", OBS_ERR_BROKEN_EVIDENCE));
            }
        }
        if matches!(
            finding.get_classification(),
            ObservabilityFindingClass::UnexpectedLeak
                | ObservabilityFindingClass::BudgetViolation
                | ObservabilityFindingClass::UnattributedGrowth
        ) {
            has_blocking_finding = true;
        }
    }
    if report.get_status() == ObservabilityStatus::Pass {
        if missing_required {
            errors.push(OBS_ERR_PASS_MISSING_COVERAGE.to_string());
        }
        if has_blocking_finding {
            errors.push(OBS_ERR_PASS_BLOCKING_FINDING.to_string());
        }
        if coverage_status.get(OBS_SCOPE_FRAME) == Some(&ObservabilityCoverageStatus::Measured)
            && !measured_ids.contains(OBS_METRIC_FRAME_INTERVAL)
        {
            errors.push(format!(
                "{}: {OBS_METRIC_FRAME_INTERVAL}",
                OBS_ERR_PASS_MISSING_REQUIRED_METRIC
            ));
        }
        if coverage_status.get(OBS_SCOPE_LAYOUT) == Some(&ObservabilityCoverageStatus::Measured) {
            for req in [
                OBS_METRIC_LAYOUT_INVALIDATIONS,
                OBS_METRIC_LAYOUT_PASSES,
                OBS_METRIC_LAYOUT_CHANGED_PASSES,
                OBS_METRIC_LAYOUT_CHANGED_NODES,
            ] {
                if !measured_ids.contains(req) {
                    errors.push(format!("{}: {req}", OBS_ERR_PASS_MISSING_REQUIRED_METRIC));
                }
            }
        }
        if coverage_status.get(OBS_SCOPE_LIFECYCLE) == Some(&ObservabilityCoverageStatus::Measured)
            && !measured_ids.contains(OBS_METRIC_DESTROYED_OWNERS)
        {
            errors.push(format!(
                "{}: {OBS_METRIC_DESTROYED_OWNERS}",
                OBS_ERR_PASS_MISSING_REQUIRED_METRIC
            ));
        }
    }
    if errors.is_empty() {
        Ok(())
    } else {
        Err(errors)
    }
}