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
Jep, thanks to @KodrAus and @GabrielMajeri for your infos on using perf for rust binaries. In the spirit of this gist, I just posted my own more detailed walk-through as a gist after getting flamegraphing to work for my rust project:
https://gist.github.com/dlaehnemann/df31787c41bd50c0fe223df07cf6eb89
Two additions in that walk-through are:
c++filt
for demangling (apparently Rust uses someC++
name mangling) further stuff, thatrust-unmangle
doesn't seem to catchdwarf
stack size to accommodate deeper stacks and avoid mis-collapsing of stacks