

In general the built in templates have always worked for me. Instruments is able to perform a bunch of different tasks, called ‘templates’. Depending on what you’re debuging you may wish to use a debug or a release build, in which case the cargo docs explain what to do: if you’re happy with a debug build, then a bare cargo build will be fine. To profile you will need to bulid your executable. Command line profiling Build your executable I included the parent crate to the Cargo.toml dependencies section, with parent =, and then I added a very simple main function that called some library functions that I suspected might have been leaking memory. Note -vcs none is because I don’t want this crate to have it’s own git repo. You will also need an executable to run: I wanted to profile a library, so I added a new binary crate inside my library crate with cargo new -vcs none -bin memcheck.

Then just add the following two lines to your crate root: ! # extern crate alloc_system Thanks to rustup this is painless, and you can easily switch back to stable when you’re done: this is as easy as rustup default nightly and rustup default stable. To get around this, you will need to switch to the system allocator. There is one big initial barrier to using instruments to profile Rust: Rust ships with its own memory allocator, which means Instruments cannot do fine-grained analysis.
Rust for mac os install#
To use Instruments you will need to install Xcode and the Xcode command line tools. I’ve been especially happy with the community, and with how easy it is to find helpful people & information, and in that spirit I wanted to quickly explore something I wasn’t able to find elsewhere: memory profiling of a Rust application using Instruments, which is part of Apple’s Developer Tools. I’ve been playing around with Rust for the past month, and really enjoying myself. Profiling Rust memory usage on with Instruments on macOS
