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
Great tutorial.
I'd like to point out that using
-g
withrecord
will, by default, use frame pointers, which are inaccurate in binaries where FPs are not preserved (the default on x86_64).Using
--call-graph dwarf
will use DWARF debug info which is much better.Alternatively,
--call-graph lbr
(Last Branch Record) can be used on some newer Intel processors, if the call stacks aren't too deep.Also, it's now possible to use the system allocator on stable:
use std::alloc::System;