Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions crates/flux-communication/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[must_use]

just in case :)

self.start();
ScopedRecord { timer: self }
}

/// Finish processing, then emit upstream latency.
///
/// Processing interval:
Expand Down Expand Up @@ -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<Mutex<HashMap<&'static str, Timer>>> =
Expand Down
Loading