digitalTrilunaire
digitalTrilunaire

Reputation: 105

Detailed RAM report and usage of running program on linux

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

Answers (2)

Mikel Rychliski
Mikel Rychliski

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

Fatih
Fatih

Reputation: 1

Check pmap :

pmap <PID>  

With pmap , you can see all of resources which using by process. And in here there are many other techniques.

Upvotes: 0

Related Questions