堆分析:heap profiler tool: massif

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值