How to Use the Dhat or Valgrind Memory Profiler with Rust

Enable the dhat feature and wrap your main function with dhat::Profiler::new_heap() to profile Rust memory usage.

Use the dhat crate by enabling its feature flag and wrapping your binary's entry point with dhat::Profiler::new_heap() to generate a heap profile.

fn main() {
    let _profiler = dhat::Profiler::new_heap();
    // Your application code here
}

Add dhat = { version = "0.3.3", optional = true } to your Cargo.toml dependencies and enable it with cargo run --features dhat.