Using perf:
$ perf record -g binary
$ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg
NOTE: See @GabrielMajeri's comments below about the
-g
option.
This requires you have flamegraph available in your path. The rust-unmangle
script is optional but nice.
Also check out @dlaehnemann's more detailed walkthrough about generating flamegraphs here.
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
$ 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
@KodrAus Thank you for this post. @hcpl Since Rust 1.32 (January 2019) you no longer need to change the system allocator for heap memory profiling with heaptrack and can use an unmodified binary with heaptrack. I wrote a little tutorial about this: https://gist.github.com/HenningTimm/ab1e5c05867e9c528b38599693d70b35