Ben Chuanlong Du's Blog

It is never too late to learn.

Profile Rust Applications

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips for Rust Optimization and Profiling

  1. std::mem::size_of returns the stack size of a type.

  2. memuse contains traits for measuring the dynamic memory usage of Rust types.

  3. The Rust Performance Book has a comprehensive guide on optimizing Rust code. Rust Performance Pitfalls discusses about some performance pitfalls that you want to avoid.

  4. rustfilt demangles Rust symbol names using rustc-demangle .

CPU Profiling


not-perf is a sampling CPU profiler for Linux.


Pprof is an internal perf tools for rust programs. It provides integration with Criterion which is the most popular benchmark tool in Rust. Please refer to pprof-rs/examples/ for such an example. However, Criterion performs measuring/benchmarking instead of profiling by default. To generate profiling report/visualization, you can run the following command.

cargo bench --bench bench_main name_of_benchmark -- --profile-time


Valgrind is a great profiler for Rust applications. The crate cargo-valgrind provides integration of valgrind and cargo.


FlameGraph is another good profiler for Rust applications which is has integration support for cargo.

Valgrind is preferred for several reasons.

  1. Valgrind is easier to install, configure and use. Flamegraph relies on perf which is not user-friendly.

  2. The Flamegraph project is no longer in active development.

  3. Valgrind is more powerful and flexible and can be used for profiling other porgramming languages too.


puffin is a friendly little instrumentation profiler for Rust.

Memory Profiling

bytehound is the best available memory profiling tool for Rust currently.


bytehound is a memory profiler for Linux.


dhat-rs provides heap profiling and ad hoc profiling capabilities to Rust programs, similar to those provided by DHAT .


DHAT is a dynamic heap analysis tool that comes with Valgrind.


heaptrack is a heap memory profiler for Linux