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

fix(subscriber): do not report excessive polling (#378) #440

Merged
merged 6 commits into from
Jul 3, 2023
Merged
Changes from 3 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
88 changes: 30 additions & 58 deletions console-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tracing_core::{
};
use tracing_subscriber::{
layer::Context,
registry::{Extensions, LookupSpan, SpanRef},
registry::{Extensions, LookupSpan},
Layer,
};

Expand Down Expand Up @@ -789,87 +789,59 @@ where
}

fn on_enter(&self, id: &span::Id, cx: Context<'_, S>) {
fn update<S: Subscriber + for<'a> LookupSpan<'a>>(
span: &SpanRef<S>,
at: Option<Instant>,
) -> Option<Instant> {
if let Some(span) = cx.span(id) {
let now = Instant::now();
let exts = span.extensions();
// if the span we are entering is a task or async op, record the
// poll stats.
if let Some(stats) = exts.get::<Arc<stats::TaskStats>>() {
let at = at.unwrap_or_else(Instant::now);
stats.start_poll(at);
Some(at)
stats.start_poll(now);
} else if let Some(stats) = exts.get::<Arc<stats::AsyncOpStats>>() {
let at = at.unwrap_or_else(Instant::now);
stats.start_poll(at);
Some(at)
stats.start_poll(now);
// otherwise, is the span a resource? in that case, we also want
// to enter it, although we don't care about recording poll
// stats.
} else if exts.get::<Arc<stats::ResourceStats>>().is_some() {
MatteoNardi marked this conversation as resolved.
Show resolved Hide resolved
Some(at.unwrap_or_else(Instant::now))
} else {
None
}
}
return;
};

if let Some(span) = cx.span(id) {
if let Some(now) = update(&span, None) {
if let Some(parent) = span.parent() {
update(&parent, Some(now));
}
self.current_spans
.get_or_default()
.borrow_mut()
.push(id.clone());

self.record(|| record::Event::Enter {
id: id.into_u64(),
at: self.base_time.to_system_time(now),
});
}
self.current_spans
.get_or_default()
.borrow_mut()
.push(id.clone());

self.record(|| record::Event::Enter {
id: id.into_u64(),
at: self.base_time.to_system_time(now),
});
}
}

fn on_exit(&self, id: &span::Id, cx: Context<'_, S>) {
fn update<S: Subscriber + for<'a> LookupSpan<'a>>(
span: &SpanRef<S>,
at: Option<Instant>,
) -> Option<Instant> {
if let Some(span) = cx.span(id) {
let exts = span.extensions();
let now = Instant::now();
// if the span we are entering is a task or async op, record the
// poll stats.
if let Some(stats) = exts.get::<Arc<stats::TaskStats>>() {
let at = at.unwrap_or_else(Instant::now);
stats.end_poll(at);
Some(at)
stats.end_poll(now);
} else if let Some(stats) = exts.get::<Arc<stats::AsyncOpStats>>() {
let at = at.unwrap_or_else(Instant::now);
stats.end_poll(at);
Some(at)
// otherwise, is the span a resource? in that case, we also want
// to enter it, although we don't care about recording poll
// stats.
stats.end_poll(now);
// otherwise, is the span a resource? in that case, we also want
// to enter it, although we don't care about recording poll
// stats.
} else if exts.get::<Arc<stats::ResourceStats>>().is_some() {
MatteoNardi marked this conversation as resolved.
Show resolved Hide resolved
Some(at.unwrap_or_else(Instant::now))
} else {
None
}
}
return;
};

if let Some(span) = cx.span(id) {
if let Some(now) = update(&span, None) {
if let Some(parent) = span.parent() {
update(&parent, Some(now));
}
self.current_spans.get_or_default().borrow_mut().pop(id);
self.current_spans.get_or_default().borrow_mut().pop(id);

self.record(|| record::Event::Exit {
id: id.into_u64(),
at: self.base_time.to_system_time(now),
});
}
self.record(|| record::Event::Exit {
id: id.into_u64(),
at: self.base_time.to_system_time(now),
});
}
}

Expand Down