2023-04-27 06:59:20 -04:00
|
|
|
//! This example demonstrates tokio's experimental taskdumping functionality.
|
|
|
|
|
|
|
|
|
|
#[cfg(all(
|
|
|
|
|
tokio_unstable,
|
|
|
|
|
tokio_taskdump,
|
|
|
|
|
target_os = "linux",
|
|
|
|
|
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
|
|
|
|
|
))]
|
2023-06-06 16:55:37 -04:00
|
|
|
#[tokio::main]
|
2023-04-27 06:59:20 -04:00
|
|
|
async fn main() {
|
|
|
|
|
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() {
|
2023-06-06 16:55:37 -04:00
|
|
|
loop {
|
|
|
|
|
tokio::task::yield_now().await;
|
|
|
|
|
}
|
2023-04-27 06:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
2023-06-06 16:55:37 -04:00
|
|
|
async fn dump() {
|
|
|
|
|
let handle = tokio::runtime::Handle::current();
|
|
|
|
|
let dump = handle.dump().await;
|
2023-04-27 06:59:20 -04:00
|
|
|
|
2023-06-06 16:55:37 -04:00
|
|
|
for (i, task) in dump.tasks().iter().enumerate() {
|
|
|
|
|
let trace = task.trace();
|
|
|
|
|
println!("task {i} trace:");
|
|
|
|
|
println!("{trace}\n");
|
|
|
|
|
}
|
2023-04-27 06:59:20 -04:00
|
|
|
}
|
2023-06-06 16:55:37 -04:00
|
|
|
|
|
|
|
|
tokio::select!(
|
|
|
|
|
biased;
|
|
|
|
|
_ = tokio::spawn(a()) => {},
|
|
|
|
|
_ = tokio::spawn(b()) => {},
|
|
|
|
|
_ = tokio::spawn(c()) => {},
|
|
|
|
|
_ = dump() => {},
|
|
|
|
|
);
|
2023-04-27 06:59:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(not(all(
|
|
|
|
|
tokio_unstable,
|
|
|
|
|
tokio_taskdump,
|
|
|
|
|
target_os = "linux",
|
|
|
|
|
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
|
|
|
|
|
)))]
|
|
|
|
|
fn main() {
|
|
|
|
|
println!("task dumps are not available")
|
|
|
|
|
}
|