Callgrind

Callgrind will show statistics about the most-used functions in your program. To run it, you will need to run cargo profiler callgrind {args}, where args are the arguments to your executable. There is an interesting issue here though. Rust uses jemalloc as the default allocator, but Valgrind will try to use its own allocator to detect calls. There is a way to use Valgrind's allocator, but it will only work in nightly Rust.

You will need to add the following lines to your main.rs file:

#![feature(alloc_system)]extern crate alloc_system;

This will force Rust to use the system allocator. You might need to add #![allow(unused_extern_crates)] to the file so that it doesn't alert you for an unused crate. An interesting flag for Valgrind ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.