我使用 valgrind massif 记录内存分配,并使用 ms_print 创建一个快照文档,显示哪个调用堆栈当前拥有多少内存,对吧?
我想测量在整个程序运行过程中哪些调用堆栈分配得最多,这意味着在计算调用堆栈的权重时应该考虑释放的内存。
这可能吗?
问候
当某个工具(例如 memcheck、massif、...)替换内存分配函数(malloc、free、...)时,valgrind 提供了以下选项:
--xtree-memory=none|allocs|full profile heap memory in an xtree [none]
and produces a report at the end of the execution
none: no profiling, allocs: current allocated
size/blocks, full: profile current and cumulative
allocated size/blocks and freed size/blocks.
--xtree-memory-file=<file> xtree memory report file [xtmemory.kcg.%p]
所以,如果你使用 --xtree-memory=full,你会得到一个可以用 kcachegrind 可视化的文件。生成的文件详细说明了当前分配的内容,以及分配然后释放的内容。
有关详细信息,请参阅http://www.valgrind.org/docs/manual/manual-core.html#manual-core.xtree 。