diff --git a/crates/flux-communication/src/timer.rs b/crates/flux-communication/src/timer.rs index 684ba0e..6a850df 100644 --- a/crates/flux-communication/src/timer.rs +++ b/crates/flux-communication/src/timer.rs @@ -143,6 +143,13 @@ impl Timer { self.emit_processing(); } + #[inline] + #[must_use = "the returned guard records on drop; binding it to `_` drops it immediately"] + pub fn record_scoped(&mut self) -> ScopedRecord<'_> { + self.start(); + ScopedRecord { timer: self } + } + /// Finish processing, then emit upstream latency. /// /// Processing interval: @@ -248,6 +255,17 @@ impl Timer { } } +pub struct ScopedRecord<'a> { + timer: &'a mut Timer, +} + +impl Drop for ScopedRecord<'_> { + #[inline] + fn drop(&mut self) { + self.timer.record_processing(); + } +} + /// Used by timeit macro #[allow(dead_code)] pub static TIMERS: LazyLock>> =