valgrind (memcheck) 的替代品在 Linux 上查找泄漏?

发布于 2024-12-05 00:16:05 字数 1539 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

尸血腥色 2024-12-12 00:16:05

博士。内存一试。它基于 DynamoRIO 并与 Valgrind 共享许多功能。

Give Dr. Memory a try. It is based on DynamoRIO and shares many of the features with Valgrind.

凉薄对峙 2024-12-12 00:16:05

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).

如梦初醒的夏天 2024-12-12 00:16:05

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 工具的 脚本

./memleak -p $(pidof allocs)
        Trace allocations and display a summary of "leaked" (outstanding)
        allocations every 5 seconds
./memleak -p $(pidof allocs) -t
        Trace allocations and display each individual allocator function call
./memleak -ap $(pidof allocs) 10
        Trace allocations and display allocated addresses, sizes, and stacks
        every 10 seconds for outstanding allocations
./memleak -c "./allocs"
        Run the specified command and trace its allocations
./memleak
        Trace allocations in kernel mode and display a summary of outstanding
        allocations every 5 seconds
./memleak -o 60000
        Trace allocations in kernel mode and display a summary of outstanding
        allocations that are at least one minute (60 seconds) old
./memleak -s 5
        Trace roughly every 5th allocation, to reduce overhead

此类工具的优点:我们不需要重建程序,因此可以方便地分析一些在线服务。

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).
enter image description here

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.

./memleak -p $(pidof allocs)
        Trace allocations and display a summary of "leaked" (outstanding)
        allocations every 5 seconds
./memleak -p $(pidof allocs) -t
        Trace allocations and display each individual allocator function call
./memleak -ap $(pidof allocs) 10
        Trace allocations and display allocated addresses, sizes, and stacks
        every 10 seconds for outstanding allocations
./memleak -c "./allocs"
        Run the specified command and trace its allocations
./memleak
        Trace allocations in kernel mode and display a summary of outstanding
        allocations every 5 seconds
./memleak -o 60000
        Trace allocations in kernel mode and display a summary of outstanding
        allocations that are at least one minute (60 seconds) old
./memleak -s 5
        Trace roughly every 5th allocation, to reduce overhead

The pros of such tools: We don't need to rebuild our program, so it's handy for analyzing some online services.

痴者 2024-12-12 00:16:05

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文