Skip to content

Instantly share code, notes, and snippets.

@indiv0
Forked from KodrAus/Profile Rust on Linux.md
Created November 23, 2017 14:32
Show Gist options
  • Save indiv0/8f9f690caf2da4a6e5d15ce794230ee7 to your computer and use it in GitHub Desktop.
Save indiv0/8f9f690caf2da4a6e5d15ce794230ee7 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

This requires you have flamegraph available in your path. The rust-unmangle script is optional but nice.

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

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.

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