Reputation: 105
I would like to know how to monitor a specific program (with its pid) and get a report of it's RAM used, like with perf record -p <PID> sleep 15 && perf report
, giving me instruction using the most of the memory.
I already heard about top commands, but it is not what I want.
Upvotes: 2
Views: 737
Reputation: 3597
Massif is a heap profiler included in the valgrind suite, and can provide some of this information.
Start it with valgrind --tool=massif <you program>
. This will create a massif.out file that contains various "snapshots" of heap memory usage while the program ran. A simpler viewer ms_print
is included and will dump all the snapshots with stack traces.
For example:
83.83% (10,476B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->30.03% (3,752B) 0x4E6079B: _nl_make_l10nflist (l10nflist.c:241)
| ->24.20% (3,024B) 0x4E608E7: _nl_make_l10nflist (l10nflist.c:285)
| | ->12.10% (1,512B) 0x4E5A091: _nl_find_locale (findlocale.c:218)
| | | ->12.10% (1,512B) 0x4E5978B: setlocale (setlocale.c:340)
| | | ->12.10% (1,512B) 0x4016BA: main (sleep.c:106)
| | |
| | ->12.10% (1,512B) 0x4E608E7: _nl_make_l10nflist (l10nflist.c:285)
| | ->09.41% (1,176B) 0x4E5A091: _nl_find_locale (findlocale.c:218)
| | | ->09.41% (1,176B) 0x4E5978B: setlocale (setlocale.c:340)
| | | ->09.41% (1,176B) 0x4016BA: main (sleep.c:106)
| | |
| | ->02.69% (336B) 0x4E608E7: _nl_make_l10nflist (l10nflist.c:285)
| | ->02.69% (336B) 0x4E5A091: _nl_find_locale (findlocale.c:218)
| | ->02.69% (336B) 0x4E5978B: setlocale (setlocale.c:340)
| | ->02.69% (336B) 0x4016BA: main (sleep.c:106)
| |
| ->05.83% (728B) 0x4E5A091: _nl_find_locale (findlocale.c:218)
| ->05.83% (728B) 0x4E5978B: setlocale (setlocale.c:340)
| ->05.83% (728B) 0x4016BA: main (sleep.c:106)
Upvotes: 1