I am developing a project in c++ which is like real-time application continuously monitoring data of all critical devices. I try to use Valgrind to check memory leak in the application but when I try use Valgrind in real time testing it ridiculously slows down my application causing damage to my system performance.
我正在用c++开发一个项目,它就像实时应用,不断监控所有关键设备的数据。我尝试使用Valgrind来检查应用程序中的内存泄漏,但是当我尝试在实时测试中使用Valgrind时,它会非常荒谬地减慢应用程序的速度,从而对系统性能造成损害。
Is there any such method or tool which I can use to do memory leak check in Real time application?
是否有这样的方法或工具,我可以用来做内存泄漏检查实时应用?
2 个解决方案
#1
2
Some memory analysis tools such as valgrind, Dr. Memory and Intel Inspector uses binary execution engines which means they actually disassemble and then emulate the execution. They also employ a technique called shadow memory which helps them to track all read write accesses. They do this not only for spotting memory leaks but also buffer overflows, corruptions etc.
一些内存分析工具,如valgrind, Dr. memory和Intel Inspector使用二进制执行引擎,这意味着它们实际上是拆解,然后模仿执行。他们还使用一种称为影子记忆的技术,帮助他们跟踪所有的读写访问。它们不仅用于发现内存泄漏,而且还用于缓冲区溢出、瓦楞纸等。
However when it comes to only heap based leak finding, capturing calls to heap allocation funtions may be sufficient. This is basically done via a method called hooking.
但是,当只涉及到基于堆的查找泄漏时,捕获对堆分配功能的调用可能就足够了。这基本上是通过一种叫做挂钩的方法来实现的。
For Linux :
Linux:
1. Heaptrack : I haven`t used myself yet. But this one uses hooking and claims to be much faster than valgrind :
1。他:我还没有用过我自己。但这一款使用了挂钩,并声称比valgrind快得多:
Its page : http://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux
它的页面:http://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux。
Its CPPCon 2015 Video : https://www.youtube.com/watch?v=myDWLPBiHn0
它的CPPCon 2015视频:https://www.youtube.com/watch?v=myDWLPBiHn0
2. Address sanitizer : As you have access to source code and compile it, you can use with both GCC ( 4.8+ ) and Clang. As for GCC search for -fsanitize=leak
2。Address sanitizer:当您访问源代码并编译它时,您可以同时使用GCC(4.8+)和Clang。至于GCC搜索-fsanitize=泄漏。
3. GNU LIB C Hooking : You can also programatically hook GNU Lib C runtimes memory functions. For an example look at here : https://github.com/akhin/cpp_multithreaded_order_matching_engine/blob/master/source/memory/debugging/hook_gnu_libc.h
3所示。GNU LIB C挂钩:您还可以编程地钩住GNU LIB C运行时内存函数。例如:https://github.com/akhin/multithreaded_order_matching_engine/blob/master/source/memory/debugging/hook_gnu_libc.h
You can also combine this by using programatic breakpoints. For an example :
您还可以通过使用编程断点来合并它。一个例子:
https://github.com/akhin/cpp_multithreaded_order_matching_engine/blob/master/source/memory/debugging/hardware_breakpoint.h
I find this approach particularly useful as you can narrow down your search into a range allocation events.
我发现这种方法特别有用,因为您可以将搜索范围分配事件的范围缩小。
4. Using a 3rd party allocator : You can use a 3rd party allocator such as Google`s TCMalloc or Jemalloc in order to find leaks :
4所示。使用第三方分配器:您可以使用第三方分配器,如谷歌的TCMalloc或Jemalloc,以查找泄漏:
https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Leak-Checking
https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Leak-Checking
http://goog-perftools.sourceforge.net/doc/heap_checker.html
http://goog-perftools.sourceforge.net/doc/heap_checker.html
#2
0
Take a look at address sanitizer, leak sanitizer and other related tools: http://clang.llvm.org/docs/AddressSanitizer.html , http://clang.llvm.org/docs/LeakSanitizer.html
看看地址杀毒软件,泄漏消毒剂和其他相关工具:http://clang.llvm.org/docs/AddressSanitizer.html, http://clang.llvm.org/docs/LeakSanitizer.html。
#1
2
Some memory analysis tools such as valgrind, Dr. Memory and Intel Inspector uses binary execution engines which means they actually disassemble and then emulate the execution. They also employ a technique called shadow memory which helps them to track all read write accesses. They do this not only for spotting memory leaks but also buffer overflows, corruptions etc.
一些内存分析工具,如valgrind, Dr. memory和Intel Inspector使用二进制执行引擎,这意味着它们实际上是拆解,然后模仿执行。他们还使用一种称为影子记忆的技术,帮助他们跟踪所有的读写访问。它们不仅用于发现内存泄漏,而且还用于缓冲区溢出、瓦楞纸等。
However when it comes to only heap based leak finding, capturing calls to heap allocation funtions may be sufficient. This is basically done via a method called hooking.
但是,当只涉及到基于堆的查找泄漏时,捕获对堆分配功能的调用可能就足够了。这基本上是通过一种叫做挂钩的方法来实现的。
For Linux :
Linux:
1. Heaptrack : I haven`t used myself yet. But this one uses hooking and claims to be much faster than valgrind :
1。他:我还没有用过我自己。但这一款使用了挂钩,并声称比valgrind快得多:
Its page : http://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux
它的页面:http://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux。
Its CPPCon 2015 Video : https://www.youtube.com/watch?v=myDWLPBiHn0
它的CPPCon 2015视频:https://www.youtube.com/watch?v=myDWLPBiHn0
2. Address sanitizer : As you have access to source code and compile it, you can use with both GCC ( 4.8+ ) and Clang. As for GCC search for -fsanitize=leak
2。Address sanitizer:当您访问源代码并编译它时,您可以同时使用GCC(4.8+)和Clang。至于GCC搜索-fsanitize=泄漏。
3. GNU LIB C Hooking : You can also programatically hook GNU Lib C runtimes memory functions. For an example look at here : https://github.com/akhin/cpp_multithreaded_order_matching_engine/blob/master/source/memory/debugging/hook_gnu_libc.h
3所示。GNU LIB C挂钩:您还可以编程地钩住GNU LIB C运行时内存函数。例如:https://github.com/akhin/multithreaded_order_matching_engine/blob/master/source/memory/debugging/hook_gnu_libc.h
You can also combine this by using programatic breakpoints. For an example :
您还可以通过使用编程断点来合并它。一个例子:
https://github.com/akhin/cpp_multithreaded_order_matching_engine/blob/master/source/memory/debugging/hardware_breakpoint.h
I find this approach particularly useful as you can narrow down your search into a range allocation events.
我发现这种方法特别有用,因为您可以将搜索范围分配事件的范围缩小。
4. Using a 3rd party allocator : You can use a 3rd party allocator such as Google`s TCMalloc or Jemalloc in order to find leaks :
4所示。使用第三方分配器:您可以使用第三方分配器,如谷歌的TCMalloc或Jemalloc,以查找泄漏:
https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Leak-Checking
https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Leak-Checking
http://goog-perftools.sourceforge.net/doc/heap_checker.html
http://goog-perftools.sourceforge.net/doc/heap_checker.html
#2
0
Take a look at address sanitizer, leak sanitizer and other related tools: http://clang.llvm.org/docs/AddressSanitizer.html , http://clang.llvm.org/docs/LeakSanitizer.html
看看地址杀毒软件,泄漏消毒剂和其他相关工具:http://clang.llvm.org/docs/AddressSanitizer.html, http://clang.llvm.org/docs/LeakSanitizer.html。