How to profile memory usage on OSX


Hello! I’m trying to measure the memory consumption of one of my Rust programs to figure out what consumes the most memory (and maybe find out why).

For software written in other programming languages, my understanding is that I could usually build a “profiling executable” that produces memory profiles when it runs so that I can later examine these profiles with something like qcachegrind. I did not find a way to do this for Rust programs yet, though.

For time profiling, the native OSX app Instruments (part of XCode) proved quite helpful, but I was not able to get any useful information on detailed memory consumption for my program with Instruments.

Could you please give me some hints on how to do memory profiling of Rust applications in general, and on an OSX (10.13 and later, no valgrind :/) host in particular?


If the application does not have any macOS-specific dependencies, you should be able to build and profile it on Linux in a VM or docker container. I did this for my project, before I found flame for CPU profiling. Now I can do it natively.

I don’t know specifically how to help with memory profiling, though. My project only uses ~22MB memory… And I didn’t even know that until I looked just now.

Edit: I just remembered this thread on the internals forum, which has a lot of relevant information. Some of it might be useful, e.g. the jemalloc profiling.


Thanks for the hints! My current approach is to do the memory profiling inside a virtual machine which I’m planning to define and start in Vagrant and use bcc in there. I could not get it working yet, but bcc seems like a perfect fit.

EDIT: I’ve opened this issue on the bcc GitHub page describing my problem, if anyone is interested.