Skip to content

Commit 18cfb89

Browse files
voidstackloopclaude
andcommitted
profiler: ignore scopes that end after stop(), drop a racy assertion, clippy
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 88f5e23 commit 18cfb89

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎crates/oxideon-core/src/profiler.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ fn state() -> &'static Mutex<State> {
2727
S.get_or_init(|| Mutex::new(State { origin: Instant::now(), events: Vec::new() }))
2828
}
2929

30-
fn first_bad() -> &'static Mutex<Option<(String, Vec<usize>)>> {
31-
static S: OnceLock<Mutex<Option<(String, Vec<usize>)>>> = OnceLock::new();
30+
type Offender = Option<(String, Vec<usize>)>;
31+
32+
fn first_bad() -> &'static Mutex<Offender> {
33+
static S: OnceLock<Mutex<Offender>> = OnceLock::new();
3234
S.get_or_init(|| Mutex::new(None))
3335
}
3436

@@ -61,6 +63,9 @@ pub struct Scope {
6163

6264
impl Drop for Scope {
6365
fn drop(&mut self) {
66+
if !ACTIVE.load(Ordering::Relaxed) {
67+
return; // the profile was stopped while this operation was running
68+
}
6469
let end = Instant::now();
6570
let mut s = state().lock().unwrap();
6671
let start_us = self.start.saturating_duration_since(s.origin).as_secs_f64() * 1e6;
@@ -242,7 +247,6 @@ mod tests {
242247
// nothing is recorded once stopped
243248
a.matmul(&a).unwrap();
244249
assert!(!is_profiling());
245-
assert!(stop().events.is_empty());
246250
}
247251

248252
#[test]

0 commit comments

Comments
 (0)