mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-22 00:00:11 +02:00
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.
56 lines
1.1 KiB
Rust
56 lines
1.1 KiB
Rust
#![cfg(all(
|
|
tokio_unstable,
|
|
tokio_taskdump,
|
|
target_os = "linux",
|
|
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
|
|
))]
|
|
|
|
use std::hint::black_box;
|
|
use tokio::runtime;
|
|
|
|
#[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
|
|
}
|
|
|
|
#[test]
|
|
fn test() {
|
|
let rt = runtime::Builder::new_current_thread()
|
|
.enable_all()
|
|
.build()
|
|
.unwrap();
|
|
|
|
rt.spawn(a());
|
|
|
|
let handle = rt.handle();
|
|
|
|
assert_eq!(handle.dump().tasks().iter().count(), 0);
|
|
|
|
let dump = rt.block_on(async {
|
|
handle.spawn(a());
|
|
handle.dump()
|
|
});
|
|
|
|
let tasks: Vec<_> = dump.tasks().iter().collect();
|
|
|
|
assert_eq!(tasks.len(), 2);
|
|
|
|
for task in tasks {
|
|
let trace = task.trace().to_string();
|
|
assert!(trace.contains("dump_current_thread::a"));
|
|
assert!(trace.contains("dump_current_thread::b"));
|
|
assert!(trace.contains("dump_current_thread::c"));
|
|
assert!(trace.contains("tokio::task::yield_now"));
|
|
}
|
|
}
|