Skip to content

Instantly share code, notes, and snippets.

@kenkoooo
Forked from KodrAus/Profile Rust on Linux.md
Created September 10, 2019 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenkoooo/438b2464699a00c7863a8fda6a513ac9 to your computer and use it in GitHub Desktop.
Save kenkoooo/438b2464699a00c7863a8fda6a513ac9 to your computer and use it in GitHub Desktop.
Profiling Rust Applications

Profiling performance

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.

Profiling heap memory

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

Debugging

$ 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 breakpoints
  • print to print a variable
  • step,next,finish to step through calls

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment