-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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: instrument task wakers #3836
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use std::future::Future; | ||
|
||
pub(crate) trait InstrumentedFuture: Future { | ||
fn id(&self) -> Option<tracing::Id>; | ||
} | ||
|
||
impl<F: Future> InstrumentedFuture for tracing::instrument::Instrumented<F> { | ||
fn id(&self) -> Option<tracing::Id> { | ||
self.span().id() | ||
} | ||
} | ||
hawkw marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use crate::future::Future; | ||
use crate::runtime::task::harness::Harness; | ||
use crate::runtime::task::{Header, Schedule}; | ||
|
||
use std::future::Future; | ||
use std::marker::PhantomData; | ||
use std::mem::ManuallyDrop; | ||
use std::ops; | ||
|
@@ -44,12 +44,38 @@ impl<S> ops::Deref for WakerRef<'_, S> { | |
} | ||
} | ||
|
||
cfg_trace! { | ||
macro_rules! trace { | ||
hawkw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
($harness:expr, $op:expr) => { | ||
if let Some(id) = $harness.id() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like the intention here is to avoid emitting the event if the task is not being tracked? i wonder if we actually want to do this inside of the tracing event macro, to handle cases where the event is disabled by one of tracing's filtering fast paths. e.g., if the user compiles tracing with one of the "static_max_level_xxx" feature flags, the event macro will be completely empty and won't compile to any code, but we'll still dereference the trailer and check if it has a task ID. this is probably an unnecessary microoptimzation, though, and we could do it later --- moving it inside the macro will be much easier when tokio-rs/tracing#1393 is published, anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I'd really want to be to check tracing if the event would be emitted, and check if the ID is |
||
tracing::trace!( | ||
target: "tokio::task::waker", | ||
op = %$op, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i can see why this is a potential use-case for custom event names...we should definitely consider adding the option to override event names upstream, so that we can use custom names here rather than a field value...but, again, this is fine for now. |
||
task.id = id.into_u64(), | ||
); | ||
seanmonstar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} | ||
|
||
cfg_not_trace! { | ||
macro_rules! trace { | ||
($harness:expr, $op:expr) => { | ||
// noop | ||
let _ = &$harness; | ||
hawkw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
unsafe fn clone_waker<T, S>(ptr: *const ()) -> RawWaker | ||
where | ||
T: Future, | ||
S: Schedule, | ||
{ | ||
let header = ptr as *const Header; | ||
let ptr = NonNull::new_unchecked(ptr as *mut Header); | ||
let harness = Harness::<T, S>::from_raw(ptr); | ||
trace!(harness, "waker.clone"); | ||
(*header).state.ref_inc(); | ||
raw_waker::<T, S>(header) | ||
} | ||
|
@@ -61,6 +87,7 @@ where | |
{ | ||
let ptr = NonNull::new_unchecked(ptr as *mut Header); | ||
let harness = Harness::<T, S>::from_raw(ptr); | ||
trace!(harness, "waker.drop"); | ||
harness.drop_reference(); | ||
} | ||
|
||
|
@@ -71,6 +98,7 @@ where | |
{ | ||
let ptr = NonNull::new_unchecked(ptr as *mut Header); | ||
let harness = Harness::<T, S>::from_raw(ptr); | ||
trace!(harness, "waker.wake"); | ||
harness.wake_by_val(); | ||
} | ||
|
||
|
@@ -82,6 +110,7 @@ where | |
{ | ||
let ptr = NonNull::new_unchecked(ptr as *mut Header); | ||
let harness = Harness::<T, S>::from_raw(ptr); | ||
trace!(harness, "waker.wake_by_ref"); | ||
harness.wake_by_ref(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rename was mostly for convenience in all the other modules. But it could be that people find it too confusing, in which case I'll ditch the rename and just make the name change in all the other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change the public API of spawn methods to use a different trait, or is it only internal? I can't really tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesn't. And I checked in a playground, since the trait is
pub(crate)
the compiler will error if the bounds were used on apub
function.