flamegraph
Easy flamegraphs for Rust projects and everything else, without Perl or pipes <3
flamegraph is a Rust command-line tool that profiles any program and generates an interactive SVG chart showing which functions are consuming the most CPU time, integrated directly into the cargo build system.
flamegraph is a command-line tool for generating flamegraphs, which are visual charts that show where a program is spending its CPU time. In a flamegraph, each function call in the program appears as a horizontal bar. The wider the bar, the more time the CPU spent in that function. Bars are stacked to show which functions called which, so you can trace a slow path from the top-level code down to the specific operation taking time. The output is an interactive SVG file you can open in a browser.
The tool works by running your program under a system profiler (perf on Linux, xctrace on macOS, or a built-in library on Windows), collecting stack traces at regular intervals, and then converting those traces into the flamegraph image. It is written in Rust but can profile any executable, not just Rust programs.
For Rust developers, there is a cargo subcommand called cargo-flamegraph that integrates with the standard Rust build system. You can run cargo flamegraph instead of cargo run and the tool handles compiling with the right debug settings, running the binary under the profiler, and producing the output file. It also works with benchmarks, tests, examples, and already-running processes (by attaching to a process ID).
Installation is via cargo install flamegraph. Linux users need to install a system perf package separately; macOS and Windows support is built in. The README includes troubleshooting notes for common linker configurations that can cause incorrect profiling results on newer Linux toolchains.
Where it fits
- Profile a Rust binary with a single cargo flamegraph command and get an interactive SVG showing which functions are slowest
- Profile a Rust benchmark suite to catch performance regressions before they ship
- Attach to an already-running process by its PID to generate a live CPU flamegraph without restarting it