How to use:
1. valgrind --tool=massif prog
prog运行完后,输出:massif.out.<pid> // <pid>:process ID
另外:massif有2个设置选项:
--stacks=yes
By default, stack profiling is off as it slows Massif down greatly. Therefore, the stack
column is zero in the example. Stack profiling can be turned on with the --stacks=yes option.
--pages-as-heap=yes
if you wish to measure all the memory used by your program, you can use the --pages-asheap=
yes. When this option is enabled, Massif's normal heap block profiling is replaced by lower-level page profiling. Every page allocated via mmap and similar system calls is treated as a distinct block. This means that code, data and BSS segments are all measured, as they are just memory pages. Even the stack is measured, since it is ultimately allocated (and extended when necessary) via mmap; for this reason --stacks=yes is not allowed in conjunction with --pages-as-heap=yes.
2. ms_print massif.out.12345
Ms_print将生成显示(prog)程序执行期间内存消耗的图表,详细说明
有关方案中各点的负责分配地点的信息,包括峰值点内存分配。
2 摘抄自valgrind manual
Measuring All Memory in a Process
It is worth emphasising that by default Massif measures only heap memory, i.e. memory allocated with malloc,calloc, realloc, memalign, new, new[], and a few other, similar functions. (And it can optionally measure stack memory, of course.) This means it does not directly measure memory allocated with lower-level system calls such as mmap, mremap, and brk.
Heap allocation functions such as malloc are built on top of these system calls. For example, when needed, an allocator will typically call mmap to allocate a large chunk of memory, and then hand over pieces of that memory chunk to the client program in response to calls to malloc et al. Massif directly measures only these higher-level malloc et al calls, not the lower-level system calls.
Furthermore, a client program may use these lower-level system calls directly to allocate memory. By default, Massif does not measure these. Nor does it measure the size of code, data and BSS segments. Therefore, the numbers reported by Massif may be significantly smaller than those reported by tools such as top that measure a program's total size in memory.
However, if you wish to measure all the memory used by your program, you can use the --pages-asheap=yes. When this option is enabled, Massif's normal heap block profiling is replaced by lower-level page profiling. Every page allocated via mmap and similar system calls is treated as a distinct block. This means that code, data and BSS segments are all measured, as they are just memory pages. Even the stack is measured, since it is ultimately allocated (and extended when necessary) via mmap; for this reason --stacks=yes is not allowed in conjunction with --pages-as-heap=yes.