From c8dd4dde77e83dfb0ae83dc2ec7f4099f3fe3c98 Mon Sep 17 00:00:00 2001 From: Bartosz Date: Thu, 21 May 2026 15:10:06 +0100 Subject: [PATCH 1/2] add Timer::record_scoped RAII guard Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/flux-communication/src/timer.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/flux-communication/src/timer.rs b/crates/flux-communication/src/timer.rs index 684ba0e..a8d8e9e 100644 --- a/crates/flux-communication/src/timer.rs +++ b/crates/flux-communication/src/timer.rs @@ -143,6 +143,12 @@ impl Timer { self.emit_processing(); } + #[inline] + pub fn record_scoped(&mut self) -> ScopedRecord<'_> { + self.start(); + ScopedRecord { timer: self } + } + /// Finish processing, then emit upstream latency. /// /// Processing interval: @@ -248,6 +254,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>> = From ba22488136598ccf03a679b8054de8c3714ebfea Mon Sep 17 00:00:00 2001 From: Bartosz Date: Thu, 21 May 2026 15:36:06 +0100 Subject: [PATCH 2/2] mark record_scoped as #[must_use] Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/flux-communication/src/timer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/flux-communication/src/timer.rs b/crates/flux-communication/src/timer.rs index a8d8e9e..6a850df 100644 --- a/crates/flux-communication/src/timer.rs +++ b/crates/flux-communication/src/timer.rs @@ -144,6 +144,7 @@ impl Timer { } #[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 }