Easily generate [Instruments] traces for your rust crate.
cargo-instruments
is the glue between cargo and Xcode's bundled profiling
suite. It allows you to easily profile any binary in your crate, generating
files that can be viewed in the Instruments app.
bash
brew install cargo-instruments
First, ensure that you are running macOS, with Cargo, Xcode, and the Xcode Command Line Tools installed; then install with
bash
cargo install cargo-instruments
cargo-instruments
requires a binary target to run. By default, it will try to
build the current crate's main.rs
. You can specify an alternative binary by
using the --bin
or --example
flags, or a benchmark target with the --bench
flag.
Generate a new trace file (by default saved in /target/instruments
)
sh
$ cargo instruments [-t template] [--bin foo | --example bar] [--out out_file]
Open the file in Instruments.app (or pass --open
to open automatically)
sh
$ open target/instruments/my_bin_YYYY-MM-DD-THH:MM:SS.trace
When profiling the application in release mode the compiler doesn't provide debugging symbols in the default configuration.
To let the compiler generate the debugging symbols even in release mode you
can append the following section in your Cargo.toml
.
toml
[profile.release]
debug = true
Instruments has the concept of 'templates', which describe sets of dtrace probes
that can be enabled. cargo-instruments
will use the "Time
Profiler", which collects CPU core and thread use.
```sh
$ cargo instruments --help ```
```sh
$ cargo instruments -t alloc ```
```sh
$ cargo instruments --example my_example --limit 10000 --open ```
The best source of information about Instruments is likely the various WWDC sessions over the years: