Skip to content

Instantly share code, notes, and snippets.

@klochowicz
Last active May 5, 2022 05:53
Show Gist options
  • Save klochowicz/99e846b59b31105bdd102e16311de690 to your computer and use it in GitHub Desktop.
Save klochowicz/99e846b59b31105bdd102e16311de690 to your computer and use it in GitHub Desktop.
Profiling Rust projects under macOS

Using Instruments with Rust

Cargo package - not working

In the past, there was a super-convenient package `carge-instruments` that made running Instruments for your binary a breeze. Unfortunately, ever since Big Sur got introduced, tt doesn’t work; we’re hitting this error instead: cmyr/cargo-instruments#40 Everything binary now needs to be signed, even if it’s just an ad-hoc signature.

Signing your binary

Create entitlements file for debug signing

Paste the following content in ~~/debug.plist~ file.

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.security.get-task-allow</key><true/></dict></plist>

sign the binary

codesign -s - -f --entitlements ~/debug.plist target/debug/maker

verify it’s signed

codesign -dvvv target/debug/maker

Instrumenting Instruments

xcrun xctrace record --template 'Leaks' --launch -- target/debug/maker testnet

Note: you can choose from different Instruments templates, depending on your debugging needs. You can also create your own ones. You can find the template names inside Instruments - when you open it, you will be prompted to pick one. Type the desired one instead of “Leaks” in the above command.

You can stop collecting data by pressing Ctrl+c

Opening Instruments

Navigate to the new *.trace file that appeared in your working directory. You can quickly open the trace in new instance of Instruments for analysis by typing open before the filename, e.g.

open Launch_maker_2022-05-05_13.51.31_F7D754B8.trace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment