AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Interpret your resultsįrom your terminal, open ace (where allocations is the path you passed with the -D flag above) will launch the instruments GUI, and you’ll have a window that looks something like this: The last argument is just the path to your executable. The -t flag specifies which template to run, and -D specifies a place to store the generated trace. In my case I wanted to capture the entire execution of my program, so I used instruments -t Allocations -D allocations. There are various ways of invoking the instruments command line tool for a good overview check out Profiling an Application in Mac OS X. The first tracks a process’s use of anonymmous virtual memory and the heap, and provides a really useful call tree that shows where in your program allocations occur. For memory usage, there are two templates in particular that are useful: Allocations and Leaks. 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. 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
0 Comments
Read More
Leave a Reply. |