Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing-subscriber: count numbers of enters in Timings #2944

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions tracing-subscriber/src/fmt/fmt_subscriber.rs
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