We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
您可能想看看 MemProf。
You may want to take a look at MemProf.
如果您只想获取请求大量内存的位置,最简单的方法是修补
malloc
函数或创建一个具有malloc
调用和跟踪的新库大小来自malloc 函数
。我不是在谈论实现 malloc 调用。 LD_PRELOAD 这个库到您的应用程序。这是一个示例代码:
您可以很好地修改此代码以执行一些其他操作。
If you just want to get the location from where large amount of memory is requested, The easiest way would be to patch
malloc
function or create a new library havingmalloc
call and track the size form yourmalloc function
. I am not talking about implementing the malloc call. LD_PRELOAD this library to your application.here is a sample code:
You can very well modify this code to do some additional stuff.
Massif
确实显示哪些函数导致了内存使用,只要您使用调试信息(-g
)编译了程序。它甚至会显示行号。此信息在
ms_print
输出中的图表下的每个详细快照中以调用树形式给出。详细快照的频率可以通过 Massif 的--detailed-freq
选项进行控制。有关详细信息,请参阅Massif 手册第 9.2.6 节读取详细的快照信息。Massif
does show you which functions were responsible for the memory usage, as long as you've compiled your program with debugging info (-g
). It will even show you the line number.This information is given as a call tree in each detailed snapshot under the graph in the
ms_print
output. The frequency of detailed snapshots can be controlled with the--detailed-freq
option to massif. See Section 9.2.6 of the Massif manual for details on reading the detailed snapshot information.正如其他人指出的那样,Massif 提供了详尽的分析信息,但它大大减慢了该过程。
另一个选择是 Google 的 tcmalloc,它有一个嵌入式堆分析器,可以转储带有分配的调用图(请参阅 http://goog-perftools.sourceforge.net/doc/heap_profiler.html),也可以以图形方式可视化。
您可以在运行时使用
LD_PRELOAD
将其与您的程序链接起来,并且HEAPPROFILE
环境变量启用堆分析器。As others have pointed out Massif gives exhaustive profiling information, but it considerably slows down the process.
Another option is Google's tcmalloc, which has an embedded heap profiler that dumps the call graph with allocations (see http://goog-perftools.sourceforge.net/doc/heap_profiler.html), which can also be visualized graphically.
You can link it at runtime with your program with
LD_PRELOAD
, and theHEAPPROFILE
env variable enables the heap profiler.