rustriff_lib/domain/dto/execution_timing_dto.rs
1//! DTO for the CPU execution cost of a single DSP processor.
2//!
3//! Produced by [`AudioLatencyMeasurementService::measure_all_dsp_timings`] and
4//! serialised across the Tauri IPC boundary to the developer-mode UI overlay.
5//!
6//! [`AudioLatencyMeasurementService::measure_all_dsp_timings`]: crate::services::audio_latency_measurement_service::AudioLatencyMeasurementService::measure_all_dsp_timings
7
8use serde::{Deserialize, Serialize};
9
10/// CPU execution cost contributed by one processor in the DSP signal chain.
11///
12/// The value is the *net* added cost — a zero-work passthrough baseline has already been
13/// subtracted — so it represents only the work the processor itself performs, not
14/// timer-call or loop overhead. The result is clamped to `≥ 0` to avoid negative
15/// readings from measurement noise.
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(crate = "serde")]
18pub struct ExecutionTimingDto {
19 /// Name of the DSP processor (e.g. `"Gain"`, `"Tone Stack"`, `"Master Volume"`).
20 pub processor_name: String,
21
22 /// Net CPU cost of this processor in **microseconds per sample** (µs/sample).
23 ///
24 /// Multiply by the sample rate (Hz) to obtain the percentage of a 1-second
25 /// CPU budget consumed by this processor alone.
26 pub execution_us_per_sample: f64,
27}
28
29impl ExecutionTimingDto {
30 /// Creates a new timing entry for the named processor.
31 ///
32 /// # Arguments
33 ///
34 /// * `processor_name` — Human-readable processor identifier.
35 /// * `execution_us_per_sample` — Net execution cost in µs/sample (should be `≥ 0`).
36 pub fn new(processor_name: impl Into<String>, execution_us_per_sample: f64) -> Self {
37 Self {
38 processor_name: processor_name.into(),
39 execution_us_per_sample,
40 }
41 }
42}