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
-
std::mem::size_of returns the stack size of a type.
-
memuse contains traits for measuring the dynamic memory usage of Rust types.
-
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.
-
rustfilt demangles Rust symbol names using rustc-demangle .
CPU Profiling
not-perf
not-perf is a sampling CPU profiler for Linux.
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 great profiler for Rust applications. The crate cargo-valgrind provides integration of valgrind and cargo.
FlameGraph
FlameGraph is another good profiler for Rust applications which is has integration support for cargo.
Valgrind is preferred for several reasons.
-
Valgrind is easier to install, configure and use. Flamegraph relies on
perf
which is not user-friendly. -
The Flamegraph project is no longer in active development.
-
Valgrind is more powerful and flexible and can be used for profiling other porgramming languages too.
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
-
CPU Profiling of Rust Applications Using Valgrind | misc/content/2022/01/cpu-profiling-rust-valgrind/cpu-profiling-rust-valgrind.markdown
-
Profile Rust Applications Using Flamegraph | misc/content/2021/11/profile-rust-applications-using-flamegraph/profile-rust-applications-using-flamegraph.markdown