How to know memory usage of current Rust program?


#1

I am wondering if there is any crate that provides such a method to tell the current and peak memory usage of current Rust program (either from Rust runtime or abstracting over the OS). Thanks.


#2

Rust doesn’t have enough of a runtime to answer that question, since memory you allocate goes directly to jemalloc or the system allocator. It might be possible to get some of what you want from jemalloc’s mallctl; otherwise you’ll need to hit the OS (which you’d need anyway to account for non-heap memory usage). I don’t know offhand of a crate for that. (Anyone else?)

What OS(es) do you need to support?


#3

Thanks. I do mind the memory usage for stacks. I was in hope that there might be some crate that can abstract over the OS so I don’t need to worry about portability.