使用Massif在Valgrind中使用(out)运行程序的结果不同

时间:2019-03-22 04:28:20

标签: valgrind heap-memory massif

我正在为学校项目创建一个性能驱动程序,因此,我认为自己应该对程序的内存使用情况进行分析。

为此,我使用了带有或不带有Massif工具的Valgrind。使用每个测试的结果如下:

运行// Underscore runs after Lodash, so when the JS here runs initially, // _ refers to Underscore, but Underscore has saved a reference to the previous _, // which was Lodash, // in the variable name previousUnderscore that your question is asking about: // Underscore function - give _ back to Lodash: _.noConflict(); // Lodash function: _.noop() console.log('done');给了我上面的输出。知道了,总共约67MB的堆使用率,对吧?

enter image description here

enter image description here

但是后来我想知道程序在运行时分配了多少内存,因此我做了一些挖掘,找到了Massif工具,它确实可以做到这一点。

因此,我先运行<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"></script>,然后运行valgrind --leak-check=full -v ./main,其中valgrind --tool=massif ./main是执行我的程序的已死进程的进程ID。这为我提供了以上两张图片中显示的输出。

所以我的问题是,堆总使用量怎么可能约为67MB,但是Massif表示在某个时刻它达到了109.9MB的峰值?

1 个答案:

答案 0 :(得分:1)

Massif为分配的字节数给出2个数字:

  • 程序分配的字节的“逻辑数”。
  • “开销”

您的程序分配的每个块都意味着一定的开销,例如由于 对齐/填充。 在快照列表中,有用列(B)列显示您的程序 已要求。超堆(B)显示开销。

109MB是有用的+额外的堆。

您可以使用--heap-admin = size

调整开销