Skip to content
Latchkey

cargo flamegraph: One-Command Rust Profiling

cargo flamegraph builds a Rust target and runs it under a sampling profiler, emitting flamegraph.svg without manual perf plumbing.

cargo-flamegraph wraps the perf-plus-FlameGraph pipeline into one cargo subcommand. It handles the build flags for good symbols and produces the SVG directly.

What it does

cargo flamegraph compiles the chosen target (with debug symbols even in release via a profile override), runs it under perf on Linux or dtrace on macOS, and renders flamegraph.svg. It removes the manual perf record, perf script, and FlameGraph steps.

Common usage

Terminal
cargo install flamegraph
cargo flamegraph --bin my-app
# profile a specific benchmark
cargo flamegraph --bench my_bench
# pass args to the program after --
cargo flamegraph --bin my-app -- --input big.json

Options

FlagWhat it does
--bin <name>Profile a specific binary target
--bench <name>Profile a benchmark target
--example <name>Profile an example target
-o <file>Output SVG path (default flamegraph.svg)
-- <args>Arguments passed through to the program

In CI

It relies on perf under the hood, so the runner must allow perf sampling: lower kernel.perf_event_paranoid on the host, and in containers add --cap-add SYS_ADMIN or --cap-add PERFMON. Upload flamegraph.svg as an artifact for review.

Common errors in CI

"perf_event_paranoid ... permission" is the same kernel block perf hits; adjust the sysctl or run outside the container restriction. "could not find perf" means the linux-perf tools are not installed. Missing symbols in the graph mean the debug-info override did not apply; ensure the [profile.release] debug=true setting cargo-flamegraph injects is not overridden.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →