Use cargo flamegraph or cargo-timing to profile async Rust code, as standard profilers often miss async context. Install the tool and run your async binary with the --profile flag to generate a flame graph showing where time is spent.
cargo install cargo-flamegraph
cargo flamegraph --bin your_async_app
For detailed timing of specific async functions, use cargo-timing to see how long each task waits or computes.
cargo install cargo-timing
cargo timing --bin your_async_app
If you need to debug specific async hangs, add tokio-console to your dependencies and run your app with RUST_LOG=debug to inspect task states in real-time.
cargo add tokio-console
cargo run --bin your_async_app
For mdbook-based projects like the Rust book, ensure you build with cargo build before profiling to resolve dependencies correctly.
cargo build
cargo flamegraph --bin your_async_app