build_phase_buckets_with_stimulus

Function build_phase_buckets_with_stimulus 

Source
pub fn build_phase_buckets_with_stimulus(
    samples: &SampleSeries,
    stimulus_events: &[StimulusEvent],
) -> Vec<PhaseBucket>
Expand description

Build host-observed phase buckets attributed against the guest stimulus timeline.

Unlike the plain build_phase_buckets (which groups by the bridge-stamped step_index), this re-groups each periodic capture by the guest step whose stimulus window contains the capture’s workload-relative boundary offset (Sample::boundary_offset_ms). That offset is derived from the boundary schedule rather than the fire time, so it is immune to the deferred-fire burst that makes every capture stamp the same late CURRENT_STEP (the phases.len() == 1 collapse). Captures with no offset (on-demand / fixture) fall back to their stamped step_index. Because the bucket windows are then workload-relative, the run-relative monitor samples are shifted by the stimulus/monitor clock skew before windowing.

Additionally synthesizes a capture-free PhaseBucket (sample_count == 0) for any stimulus StepStart-step that captured no periodic samples — the uniform whole-workload boundary placement (compute_periodic_boundaries_ns) is step-agnostic, so a short interior step can land zero captures and otherwise leave no bucket. The synthesized bucket carries the step’s full stimulus window so in-window monitor metrics are still recovered. The returned vec holds one bucket per (captured phase ∪ StepStart-step), sorted by step_index — NOT one-per-captured-phase, so len() is no longer “number of captured phases”.

This function deliberately does not derive iteration_rate from StimulusEvent wall-clock deltas. After the guest per-cgroup phase carriers are joined to these buckets, derive_phase_metrics derives the canonical rate as iterations per delivered guest CPU-second. A bucket with no carrier therefore has no iteration_rate, rather than a second wall-throughput metric under the same name.

Live caller: evaluate_vm_result at src/test_support/eval/mod.rs — has both the SampleSeries and the stimulus_events vec in scope.