Using perf:
$ perf record -g binary
$ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg
This requires you have flamegraph available in your path. The rust-unmangle
script is optional but nice.
Using valgrind (massif) and massif-visualiser:
$ valgrind --tool=massif binary
Also check out heaptrack, it's similar to massif
but more useful out-of-the-box. It also has a nice gui experience:
$ heaptrack binary
Note that you have to use the system allocator:
#![feature(alloc_system, global_allocator, allocator_api)]
extern crate alloc_system;
use alloc_system::System;
#[global_allocator]
static A: System = System;
If you don't use it you'll get totally inaccurate results that show no heap usage.
$ rust-gdb binary
Namespaces are prefixed by the crate name, which is probably also the name of the binary. You can do stuff like:
break
to set breakpointsprint
to print a variablestep
,next
,finish
to step through calls