【发布时间】:2020-05-27 00:24:54
【问题描述】:
我使用 valgrind massif 记录内存分配并使用 ms_print 创建一个快照文档,显示当前哪个调用堆栈拥有多少内存,对吧?
我想测量在整个程序运行过程中哪些调用堆栈分配得最多,这意味着在计算调用堆栈的权重时应该考虑释放的内存。
这可能吗?
问候
【问题讨论】:
我使用 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 可视化的文件。生成的文件详细信息 a.o.当前分配了什么,分配然后释放了什么。
见http://www.valgrind.org/docs/manual/manual-core.html#manual-core.xtree 了解更多详情。
【讨论】: