Rust Profiling
Purpose
Guide agents through Rust performance profiling: flamegraphs via cargo-flamegraph, binary size analysis, monomorphization bloat measurement, Criterion microbenchmarks, and interpreting profiling results with inlined Rust frames.
Triggers
- "How do I generate a flamegraph for a Rust program?"
- "My Rust binary is huge — how do I find what's causing it?"
- "How do I write Criterion benchmarks?"
- "How do I measure monomorphization bloat?"
- "Rust performance is worse than expected — how do I profile it?"
- "How do I use perf with Rust?"
Workflow
1. Build for profiling
2. Flamegraphs with cargo-flamegraph
Custom flamegraph options:
3. Binary size analysis with cargo-bloat
Typical output:
4. Monomorphization bloat with cargo-llvm-lines
Typical output:
High Copies count = monomorphization expansion. Fix:
5. Criterion microbenchmarks
6. perf with Rust (Linux)
Rust-specific perf tips:
- Build with
debug = 1(line tables only) for faster builds with line-level attribution - Use
RUSTFLAGS="-C force-frame-pointers=yes"for better call graphs without DWARF unwinding - Disable ASLR for reproducible addresses:
setarch $(uname -m) -R ./myapp
7. heaptrack / DHAT for allocations
For flamegraph setup and Criterion configuration, see references/cargo-flamegraph-setup.md [blocked].
Related skills
- Use
skills/rust/rustc-basicsfor build configuration (debug symbols, profiles) - Use
skills/profilers/linux-perffor perf fundamentals - Use
skills/profilers/flamegraphsfor reading and interpreting flamegraph SVGs - Use
skills/profilers/valgrindfor allocation profiling with massif/DHAT


