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
22 changes: 16 additions & 6 deletions tracing-subscriber/src/fmt/fmt_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,12 @@ where
let span = ctx.span(id).expect("Span not found, this is a bug");
let mut extensions = span.extensions_mut();
if let Some(timings) = extensions.get_mut::<Timings>() {
let now = Instant::now();
timings.idle += (now - timings.last).as_nanos() as u64;
timings.last = now;
if timings.entered_count == 0 {
let now = Instant::now();
timings.idle += (now - timings.last).as_nanos() as u64;
timings.last = now;
}
timings.entered_count += 1;
}

if self.fmt_span.trace_enter() {
Expand All @@ -911,9 +914,12 @@ where
let span = ctx.span(id).expect("Span not found, this is a bug");
let mut extensions = span.extensions_mut();
if let Some(timings) = extensions.get_mut::<Timings>() {
let now = Instant::now();
timings.busy += (now - timings.last).as_nanos() as u64;
timings.last = now;
timings.entered_count -= 1;
if timings.entered_count == 0 {
let now = Instant::now();
timings.busy += (now - timings.last).as_nanos() as u64;
timings.last = now;
}
}

if self.fmt_span.trace_exit() {
Expand All @@ -935,7 +941,9 @@ where
busy,
mut idle,
last,
entered_count,
} = *timing;
debug_assert_eq!(entered_count, 0);
idle += (Instant::now() - last).as_nanos() as u64;

let t_idle = field::display(TimingDisplay(idle));
Expand Down Expand Up @@ -1225,6 +1233,7 @@ struct Timings {
idle: u64,
busy: u64,
last: Instant,
entered_count: u64,
}

impl Timings {
Expand All @@ -1233,6 +1242,7 @@ impl Timings {
idle: 0,
busy: 0,
last: Instant::now(),
entered_count: 0,
}
}
}
Expand Down