Function trace_with
pub fn trace_with<FN, FT, R>(f: FN, trace_leaf: FT) -> R
Available on
tokio_unstable and Linux and crate feature rt and crate feature taskdump and (AArch64 or s390x or x86 or x86-64) only.Runs f. If f hits a Tokio yield point trace_leaf will be invoked.
This allows taking a task dump with caller-provided task dump machinery. If f is the poll function of a future and that future returns Poll::Pending, then trace_leaf will be invoked. trace_leaf can then take a backtrace to determine exactly where the yield occurred.
Example
use std::future::Future;
use std::task::Poll;
use tokio::runtime::dump::{trace_with, Trace, TraceMeta};
fn my_trace_leaf(_meta: &TraceMeta, count: &mut u32) {
*count += 1;
}
let mut fut = std::pin::pin!(async {
tokio::task::yield_now().await;
});
let mut leaf_count = 0;
Trace::root(std::future::poll_fn(|cx| {
trace_with(
|| { let _ = fut.as_mut().poll(cx); },
|meta| my_trace_leaf(meta, &mut leaf_count),
);
Poll::Ready(())
})).await;
assert!(leaf_count > 0);
MIT License
Copyright © Tokio Contributors
https://docs.rs/tokio/1.53.1/tokio/runtime/dump/fn.trace_with.html