Use perf to record instruction counts with stack traces, then convert the output to a flamegraph using flamegraph.pl.
- Build your Rust application in release mode with debug symbols enabled.
cargo build --release
- Record the performance data while running your binary, capturing the call graph.
sudo perf record -g -e instructions -- ./target/release/your_binary
- Generate a stack dump from the recorded data.
perf script | stackcollapse-perf.pl > out.stack
- Convert the stack dump into an SVG flamegraph.
flamegraph.pl out.stack > flamegraph.svg
Open flamegraph.svg in your browser to visualize the performance bottlenecks.