简体   繁体   中英

accounting for memory consumption

What are the strategies to account for memory consumed by a process? For example I have a program and in an old version its usage of memory was suboptimal and it wasn't being released at the right time, which meant that it held onto the allocation for longer than it should. Note that I don't mean it leaked. A new version of the program revised the algorithm and now memory is released sooner in the program's lifetime. How can one track this? Some ways that come to mind are: write a malloc/new replacement library that wraps libc/libstdc++, somehow use valgrind to do it or sample the memory used by the process using ps and plot a graph?

If you don't want to use a third party one (there are some from AMD, Intel, valgrind should have "massif" tool) you could have a look into Mtrace .

Does pretty much what you planned for memory allocation.

Id rather recommend you using valgrinds massif tool, it doesnt have a decent gui/graph but shows procentuals pretty accurate

Before using ps to analyze the memory used... see this awesome sof question: How to measure actual memory usage of an application or process?

But as long as you're ok with ps's limitations, you can use crontab to create a job that runs every N seconds/minutes... append the results of the ps aux to a file... and then you can use spreadsheet software to plot the results of the memory over time.

I've had success doing this in the past.

Valgrind, however, is probably a better bet: http://valgrind.org/docs/manual/quick-start.html

You can do something very similar with this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM