Profiling with cargo flamegraph

2025-01-25

This will be a rather short blog post, because all I wanted to show off was this flamegraph, generated from one of the questions in the competitive programming course I’m taking:

flamegraph

(Note: the SVG file is actually interactive, but you do need to right-click on the image and open it in a new tab!)

I love looking at flamegraphs!

Side-note: getting cargo flamegraph running on Windows is slightly involved.

Windows Preparations

  1. If you have BitLocker enabled on your machine, back up the recovery key. You will need it in a sec. Most Windows machines nowadays ship with BitLocker enabled.
  2. Enable dtrace functionality by running bcdedit /set dtrace on in an elevated permissions terminal.
  3. Download and run the installer from Microsoft’s official dtrace repository.
  4. Set the _NT_SYMBOL_PATH system environment variable to the following (see details on why here):
srv*c:\symbols*https://msdl.microsoft.com/download/symbols
  1. Reboot your machine. Enter in the BitLocker recovery key when prompted.

Linux Preparations

On Linux, you do need the linux-tools packages for your specific kernel version. I’m using NixOS, so I just had to run nix shell nixpkgs#linuxKernel.packages.linux_latest_libre.perf to get just the perf package that flamegraph-rs requires. (No idea what the libre part is for, but there wasn’t one without that suffix…) Check out the official installation section of the README for distro-specific instructions.