开发者

Calculating the maximum free store memory consumed by a process

开发者 https://www.devze.com 2023-03-09 02:40 出处:网络
I would like to compare the maximum amount of heap a set of processes dynamically allocate. Is there any system command in Linux or any application that automatically开发者_如何学Python does that? Som

I would like to compare the maximum amount of heap a set of processes dynamically allocate. Is there any system command in Linux or any application that automatically开发者_如何学Python does that? Something like a monitoring tool that runs a process and watches for how much memory is consumed by the process.

Unfortunately, the size(1) command only reflects on the text and data memory sections of the process and process accounting reports on the average memory used by the process.


Try with a memory profiler like valgrind massif.


pmap is not bad, but it only gives you a snapshot, not the maximum.

You might want to take a look at getrusage(). On new-ish kernels (2.6.32; not sure the exact cut-off), the ru_*rss fields are actually populated. (On older kernels, they always get set to zero...)

Also try "cat /proc/<pid>/status" and look at VmPeak (which shows the peak virtual memory usage) and VmHWM (which shows the peak resident set size). Those are both "high water marks", as in they go up during a process's lifetime but never down. If you can grab a snapshot of them at process termination, you can gather the data yourself.

I once wrote a .so to do just that; it worked by patching exit() (and you invoked it using LD_PRELOAD). But it was for work and I do not have a copy :-(.

0

精彩评论

暂无评论...
验证码 换一张
取 消