在Linux上轻量级内存泄漏调试 [英] Lightweight memory leak debugging on linux

查看:490
本文介绍了在Linux上轻量级内存泄漏调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了第一个存在的答案,看到的 Valgrind的的是大家最喜欢在Linux上的内存泄漏调试工具。不幸的 Valgrind的的似乎不是我的目的工作。我会尽量解释为什么。

I looked for existing answers first and saw that Valgrind is everyone’s favorite tool for memory leak debugging on linux. Unfortunately Valgrind does not seem to work for my purposes. I will try to explain why.

约束:


  • 泄漏只是再现了客户的使用环境。由于某些
    法律限制我们必须与现有的二进制工作。没有的重建。

  • 在常规环境下我们的应用程序消耗〜10%的CPU。就是说,我们可以
    容忍高达10倍的CPU使用率增加。的 Valgrind的的使用默认的 MEMCHECK
    设置确实差很多让我们的应用程序没有响应长
    的时间段。

  • The leak reproduces only in customer’s environment. Due to certain legal restrictions we have to work with existing binary. No rebuilds.
  • In regular environment our application consumes ~10% CPU. Say, we can tolerate up to 10x CPU usage increase. Valgrind with default memcheck settings does much worse making our application unresponsive for long periods of time.

我需要的是一个相当于微软的 UMDH 的:打开堆栈跟踪每个堆分配,然后在一定的时间点转储通过堆栈分组,按降序排列按分配计数下令所有分配。我们的应用程序船舶在Windows和Linux平台上,所以我知道在Windows上,业绩的 UMDH 的仍然是可以忍受的。

What I need is an equivalent of Microsoft’s UMDH: turn on stack tracing for each heap allocation, then at certain point of time dump all allocations grouped by stacks and ordered by allocation count in descending order. Our app ships on both Windows and Linux platforms, so I know that performance on Windows under UMDH is still tolerable.

下面是工具/我认为方法

Here are the tools/methods I considered


  • Valgrind的的的的 -memcheck 的和的 -massif 的工具,他们做的比需​​要(如扫描整个过程内存分配每多
    指针),它们是太慢了,他们还是没有做什么我结果
    需要(由数排序转储调用栈),所以我必须写一些
    脚本解析输出

  • dmalloc 的库(dmalloc.com)需要新的二进制

  • LeakTracer( http://www.andreasen.org/LeakTracer/ )用C只能++
    新/删除的(我需要的的malloc /免费的为好),没有组由堆栈
    和排序功能

  • 使用自己实施工具,.so库LD_ preLOAD
    机制
    (<一href=\"http://stackoverflow.com/questions/6083337/overriding-malloc-using-the-ld-$p$pload-mechanism\">Overriding malloc的'使用LD_ preLOAD机制)
    这将需要至少一个星期给我的编码换Linux技能和感觉
    就像发明一种自行车。

  • Valgrind's -memcheck and –massif tools They do much more than needed (like scanning whole process memory for every allocation pointer), they are too slow, and they still don’t do exactly what I
    need (dump callstacks sorted by counts), so I will have to write some scripts parsing the output
  • dmalloc library (dmalloc.com) requires new binary
  • LeakTracer (http://www.andreasen.org/LeakTracer/) Works only with C++ new/delete (I need malloc/free as well), does not have group-by-stack and sort functionality
  • Implementing the tool myself as .so library using LD_PRELOAD mechanism (Overriding 'malloc' using the LD_PRELOAD mechanism) That will take at least a week given my coding-for-Linux skills and it feels like inventing a bicycle.

我错过了什么?是否有任何轻量级的 Valgrind的的选项或现有的LD_ preLOAD工具?

Did I miss anything? Are there any lightweight Valgrind options or existing LD_PRELOAD tool?

推荐答案

奇怪的是,我无法找到像微软在开源领域或可立即下载UMDH什么。 (我也看了一下谷歌堆泄漏检查但它更像Valgrind的而不是UMDH)。所以,我结束了使用的malloc仪表项目作为参考点书写工具自己:

Surprisingly, I was unable to find anything like Microsoft's UMDH in open-source domain or available for immediate download. (I also looked at Google Heap Leak Checker but it is more like Valgrind rather than to UMDH). So I ended up writing the tool myself using malloc instrumentation project as a reference point:

https://github.com/glagolig/heapwatch

该工具有局限性的数量,但它的工作就好了,我的目的。

The tool has number of limitations, but it worked just fine for my purposes.

这篇关于在Linux上轻量级内存泄漏调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆