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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With