pub fn trace_with<FN, FT, R>(f: FN, trace_leaf: FT) -> RAvailable on
tokio_unstable and crate feature taskdump and crate feature rt and Linux and (AArch64 or x86 or x86-64) only.Expand description
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);