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

not-perf is a sampling CPU profiler for Linux. It is currently the best CPU profiling tools for Rust applications for several reasons. It is easy to install and use. There's no special configuration required. Flamegraph (relying on Linux perf) is the hardest one to install, configure and use. Valgrind is also easy to install, configure and use. However, it is way too slower compared to not-perf.

samply

samply is a command line CPU profiler which uses the Firefox profiler as its UI.

pprof

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/criterion.rs 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

Valgrind is a another CPU profiling tool for Rust applications. The crate cargo-valgrind provides integration of valgrind and cargo.

FlameGraph

FlameGraph is another a CPU profiling tool based on Linux perf. It has integration support for cargo.

puffin

puffin is a friendly little instrumentation profiler for Rust.

Memory Profiling

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

bytehound

bytehound is a memory profiler for Linux.

dhat-rs

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

DHAT

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

heaptrack

heaptrack is a heap memory profiler for Linux

References

Comments