Skip to content

Commit 56c4365

Browse files
authored
tokio: improve taskdump documentation (#5805)
- Add example trace output. - Add note on enabling unstable features. - Add note on performance overhead.
1 parent fb0d305 commit 56c4365

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

tokio/src/runtime/handle.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,26 @@ cfg_taskdump! {
406406
/// # }
407407
/// ```
408408
///
409+
/// This produces highly detailed traces of tasks; e.g.:
410+
///
411+
/// ```plain
412+
/// TASK 0:
413+
/// ╼ dump::main::{{closure}}::a::{{closure}} at /tokio/examples/dump.rs:18:20
414+
/// └╼ dump::main::{{closure}}::b::{{closure}} at /tokio/examples/dump.rs:23:20
415+
/// └╼ dump::main::{{closure}}::c::{{closure}} at /tokio/examples/dump.rs:28:24
416+
/// └╼ tokio::sync::barrier::Barrier::wait::{{closure}} at /tokio/tokio/src/sync/barrier.rs:129:10
417+
/// └╼ <tokio::util::trace::InstrumentedAsyncOp<F> as core::future::future::Future>::poll at /tokio/tokio/src/util/trace.rs:77:46
418+
/// └╼ tokio::sync::barrier::Barrier::wait_internal::{{closure}} at /tokio/tokio/src/sync/barrier.rs:183:36
419+
/// └╼ tokio::sync::watch::Receiver<T>::changed::{{closure}} at /tokio/tokio/src/sync/watch.rs:604:55
420+
/// └╼ tokio::sync::watch::changed_impl::{{closure}} at /tokio/tokio/src/sync/watch.rs:755:18
421+
/// └╼ <tokio::sync::notify::Notified as core::future::future::Future>::poll at /tokio/tokio/src/sync/notify.rs:1103:9
422+
/// └╼ tokio::sync::notify::Notified::poll_notified at /tokio/tokio/src/sync/notify.rs:996:32
423+
/// ```
424+
///
409425
/// # Requirements
410426
///
411427
/// ## Debug Info Must Be Available
428+
///
412429
/// To produce task traces, the application must **not** be compiled
413430
/// with split debuginfo. On Linux, including debuginfo within the
414431
/// application binary is the (correct) default. You can further ensure
@@ -419,9 +436,30 @@ cfg_taskdump! {
419436
/// split-debuginfo = "off"
420437
/// ```
421438
///
439+
/// ## Unstable Features
440+
///
441+
/// This functionality is **unstable**, and requires both the
442+
/// `tokio_unstable` and `tokio_taskdump` cfg flags to be set.
443+
///
444+
/// You can do this by setting the `RUSTFLAGS` environment variable
445+
/// before invoking `cargo`; e.g.:
446+
/// ```bash
447+
/// RUSTFLAGS="--cfg tokio_unstable --cfg tokio_taskdump" cargo run --example dump
448+
/// ```
449+
///
450+
/// Or by [configuring][cargo-config] `rustflags` in
451+
/// `.cargo/config.toml`:
452+
/// ```text
453+
/// [build]
454+
/// rustflags = ["--cfg tokio_unstable", "--cfg tokio_taskdump"]
455+
/// ```
456+
///
457+
/// [cargo-config]:
458+
/// https://doc.rust-lang.org/cargo/reference/config.html
459+
///
422460
/// ## Platform Requirements
423461
///
424-
/// Task dumps are supported on Linux atop x86 and x86_64.
462+
/// Task dumps are supported on Linux atop aarch64, x86 and x86_64.
425463
///
426464
/// ## Current Thread Runtime Requirements
427465
///
@@ -431,6 +469,14 @@ cfg_taskdump! {
431469
///
432470
/// # Limitations
433471
///
472+
/// ## Performance
473+
///
474+
/// Although enabling the `tokio_taskdump` feature imposes virtually no
475+
/// additional runtime overhead, actually calling `Handle::dump` is
476+
/// expensive. The runtime must synchronize and pause its workers, then
477+
/// re-poll every task in a special tracing mode. Avoid requesting dumps
478+
/// often.
479+
///
434480
/// ## Local Executors
435481
///
436482
/// Tasks managed by local executors (e.g., `FuturesUnordered` and

0 commit comments

Comments
 (0)