-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tokio: introduce
Handle::dump
and impl for current-thread runtime
Task dumps are snapshots of runtime state. Taskdumps are collected by instrumenting Tokio's leaves to conditionally collect backtraces, which are then coalesced per-task into execution tree traces. This initial implementation only supports collecting taskdumps from within the context of a current-thread runtime, and only `yield_now()` is instrumented.
- Loading branch information
Showing
20 changed files
with
751 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! This example demonstrates tokio's experimental taskdumping functionality. | ||
use std::hint::black_box; | ||
|
||
#[inline(never)] | ||
async fn a() { | ||
black_box(b()).await | ||
} | ||
|
||
#[inline(never)] | ||
async fn b() { | ||
black_box(c()).await | ||
} | ||
|
||
#[inline(never)] | ||
async fn c() { | ||
black_box(tokio::task::yield_now()).await | ||
} | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
tokio::spawn(a()); | ||
tokio::spawn(b()); | ||
tokio::spawn(c()); | ||
|
||
let handle = tokio::runtime::Handle::current(); | ||
let dump = handle.dump(); | ||
|
||
for (i, task) in dump.tasks().iter().enumerate() { | ||
let trace = task.trace(); | ||
println!("task {i} trace:"); | ||
println!("{trace}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//! Snapshots of runtime state. | ||
use std::fmt; | ||
|
||
/// A snapshot of a runtime's state. | ||
#[derive(Debug)] | ||
|
||
pub struct Dump { | ||
tasks: Tasks, | ||
} | ||
|
||
/// Snapshots of tasks. | ||
#[derive(Debug)] | ||
|
||
pub struct Tasks { | ||
tasks: Vec<Task>, | ||
} | ||
|
||
/// A snapshot of a task. | ||
#[derive(Debug)] | ||
|
||
pub struct Task { | ||
trace: Trace, | ||
} | ||
|
||
/// An execution trace of a task's last poll. | ||
#[derive(Debug)] | ||
pub struct Trace { | ||
inner: super::task::trace::Trace, | ||
} | ||
|
||
impl Dump { | ||
pub(crate) fn new(tasks: Vec<Task>) -> Self { | ||
Self { | ||
tasks: Tasks { tasks }, | ||
} | ||
} | ||
|
||
/// Tasks in this snapshot. | ||
pub fn tasks(&self) -> &Tasks { | ||
&self.tasks | ||
} | ||
} | ||
|
||
impl Tasks { | ||
/// Iterate over tasks. | ||
pub fn iter(&self) -> impl Iterator<Item = &Task> { | ||
self.tasks.iter() | ||
} | ||
} | ||
|
||
impl Task { | ||
pub(crate) fn new(trace: super::task::trace::Trace) -> Self { | ||
Self { | ||
trace: Trace { inner: trace }, | ||
} | ||
} | ||
|
||
/// A trace of this task's state. | ||
pub fn trace(&self) -> &Trace { | ||
&self.trace | ||
} | ||
} | ||
|
||
impl fmt::Display for Trace { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.inner.fmt(f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.