Memory consumption

What are the strategies for accounting for the memory consumed by a process? For example, I have a program, and in the old version its memory usage was suboptimal, and it was not released at the right time, which meant that it was kept in the distribution longer than necessary. Notice, I do not mean that he leaked. The new version of the program has reworked the algorithm, and now the memory is freed first of all in the life of the program. How can I track this? Some of the ways that come to mind are: write a malloc / new replacement library that wraps libc / libstdc ++, somehow use valgrind to do this, or try the memory used by the process using ps and plot ?

+4
source share
2 answers

If you do not want to use a third-party (some of AMD, Intel, valgrind must have the massif tool), you could look in Mtrace .

To a large extent, you plan on allocating memory.

I'd rather recommend you use the valgrinds massif tool, it does not have a decent gui / graph, but the procentuals are pretty accurate.

+6
source

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

But while you're fine with ps restrictions, you can use crontab to create a task that runs every N seconds / minutes ... add ps aux results to a file ... and then you can use spreadsheet software to display memory results over time.

I have had success in the past.

However Valgrind is probably better: http://valgrind.org/docs/manual/quick-start.html

You can do something very similar to this.

+2
source

Source: https://habr.com/ru/post/1436166/


All Articles