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 4 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
给博士。内存一试。它基于 DynamoRIO 并与 Valgrind 共享许多功能。
Give Dr. Memory a try. It is based on DynamoRIO and shares many of the features with Valgrind.
TotalView 调试器(或者更准确地说,其 Memscope)具有与 Valgrind 类似的功能集。
您还可以尝试电围栏 (
原作者链接)(DUMA的起源)用于缓冲区溢出或touch-after-free情况(但不适用于不过,memleaks)。The TotalView debugger (or, more precisely, its Memscope) has a feature set similar to the one of Valgrind.
You can also try Electric Fence (
original author's link) (the origin of DUMA) for buffer overflows or touch-after-free cases (but not for memleaks, though).2020 年,要查找 Linux 上的内存泄漏,您可以尝试:
Address Sanitizers< /strong>
对于 GCC(4.8 以上)和 Clang(3.1 以上),都可以使用地址清理器,这很棒
该工具已被证明在 Chromium 和 Firefox 等大型项目中非常有用。
它比 Valgrind 等其他旧替代品要快得多。
ASan会提供非常详细的内存区域信息,这对于分析泄漏非常有帮助。
ASan 的缺点:您需要使用选项
-fsanitize=address
来构建程序;额外的内存成本要大得多。TCmalloc
TCmalloc 既可以与 LD_PRELOAD 一起使用,也可以直接链接使用到你的程序。结果可以通过 pprof 程序可视化,它既有漂亮的 Web UI 又有控制台文本模式,我如果地址清理程序不适用于您的环境(如果您有一个非常旧的编译器或您的 PC 运行 ASan 的内存非常有限),建议使用它。
TCmalloc也被用于大规模生产并被证明是健壮的。
Linux Perf 工具和 BCC
Linux Perf 工具也可用于查找内存泄漏,它是一个基于采样的工具。所以它不能很精确,但它仍然是帮助我们分析内存使用情况的一个很好的工具。
还有一个来自 bcc 工具的 脚本。
此类工具的优点:我们不需要重建程序,因此可以方便地分析一些在线服务。
In 2020, to find memory leaks on Linux, you may try:
Address Sanitizers
For both GCC(above 4.8) and Clang (above 3.1), the address sanitizer can be used, it's great
the tool has been proved useful in large projects such as Chromium and Firefox.
It's much faster than other old alternatives like Valgrind.
ASan will provide very detailed memory region information, which is very helpful for analysis of the leak.
The drawback for ASan: You need to build your program with the option
-fsanitize=address
; The extra memory cost is much bigger.TCmalloc
TCmalloc can be both used with LD_PRELOAD or directly link to your program. The result can be visualized with the pprof program, it has both beautiful web UI and consoles text mode, I suggest using it if address sanitizer is not applicable in your environment(If you have a very old compiler or your PC have very limited memory to run ASan).
TCmalloc is also used in large-scale production and proved to be robust.
Linux Perf tools and BCC
Linux perf tools can also be used to find memory leaks, it's a tool based on sampling. So it can not be precise, but it's still a great tool to help us analyze the usage of memory.
There is also a script from bcc's tools.
The pros of such tools: We don't need to rebuild our program, so it's handy for analyzing some online services.
Heapusage 是一个简单的运行时工具,用于查找 Linux 和 macOS 上的内存泄漏。泄漏的输出日志格式与 Valgrind 非常相似,但它只记录明确的泄漏(即终止时未释放的分配)。
全面披露:我编写 Heapusage 是为了在 Valgrind 不足的情况下使用(高性能应用程序,以及 Valgrind 不支持的 CPU 架构)。
Heapusage is a simple run-time tool for finding memory leaks on Linux and macOS. The output logging format for leaks is quite similar to Valgrind, but it only logs definite leaks (i.e. allocations not free'd at termination).
Full disclosure: I wrote Heapusage for usage in situations when Valgrind is inadequate (high performance applications, and also for CPU architectures not supported by Valgrind).