All Projects → WuBingzheng → Memleax

WuBingzheng / Memleax

Licence: gpl-2.0
debugs memory leak of running process. Not maintained anymore, try `libleak` please.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Memleax

Libleak
detect memory leak by LD_PRELOAD, without changing the target program
Stars: ✭ 139 (-75.35%)
Mutual labels:  debugger, memory-leak
Vuetron
A tool for testing and debugging your Vue + Vuex applications. 是一個可以幫助您 Vue.js 的項目測試及偵錯的工具, 也同時支持 Vuex及 Vue-Router.
Stars: ✭ 531 (-5.85%)
Mutual labels:  debugger
Go Debug
🐛 A go debugger for atom using delve.
Stars: ✭ 390 (-30.85%)
Mutual labels:  debugger
Snoop
A powerful set of Python debugging tools, based on PySnooper
Stars: ✭ 467 (-17.2%)
Mutual labels:  debugger
Re Frisk
Take full control of re-frame app
Stars: ✭ 396 (-29.79%)
Mutual labels:  debugger
Processhacker
A free, powerful, multi-purpose tool that helps you monitor system resources, debug software and detect malware.
Stars: ✭ 6,285 (+1014.36%)
Mutual labels:  debugger
Laravel Tracy
A Laravel Package to integrate Nette Tracy Debugger
Stars: ✭ 384 (-31.91%)
Mutual labels:  debugger
Php Memory Profiler
Memory leak profiler for PHP
Stars: ✭ 544 (-3.55%)
Mutual labels:  memory-leak
Debugger
The faster and smarter Debugger for Firefox DevTools 🔥🦊🛠
Stars: ✭ 4,602 (+715.96%)
Mutual labels:  debugger
Mcclim
An implementation of the Common Lisp Interface Manager, version II
Stars: ✭ 461 (-18.26%)
Mutual labels:  debugger
Debugger.lua
A simple, embedabble CLI debugger for Lua.
Stars: ✭ 426 (-24.47%)
Mutual labels:  debugger
Various mcu debugger diy
各种LInk大合集
Stars: ✭ 402 (-28.72%)
Mutual labels:  debugger
Platformio Atom Ide
PlatformIO IDE for Atom: The next generation integrated development environment for IoT
Stars: ✭ 475 (-15.78%)
Mutual labels:  debugger
Powershelleditorservices
A common platform for PowerShell development support in any editor or application!
Stars: ✭ 394 (-30.14%)
Mutual labels:  debugger
Remake
Enhanced GNU Make - tracing, error reporting, debugging, profiling and more
Stars: ✭ 538 (-4.61%)
Mutual labels:  debugger
Python Web Pdb
Web-based remote UI for Python's PDB debugger
Stars: ✭ 390 (-30.85%)
Mutual labels:  debugger
Winrepl
x86 and x64 assembly "read-eval-print loop" shell for Windows
Stars: ✭ 424 (-24.82%)
Mutual labels:  debugger
Remotedebug
Library for Arduino to debug projects over WiFi, with web app or telnet, with print commands like Serial Monitor
Stars: ✭ 467 (-17.2%)
Mutual labels:  debugger
Xanalyzer
xAnalyzer plugin for x64dbg
Stars: ✭ 553 (-1.95%)
Mutual labels:  debugger
Vardbg
A simple Python debugger and profiler that generates animated visualizations of program flow, useful for algorithm learning.
Stars: ✭ 543 (-3.72%)
Mutual labels:  debugger

memleax

memleax debugs memory leak of a running process by attaching it, without recompiling or restarting.

status

Because the debugging work depends on CPU architecture and OS heavily, and I test memleax only on several programs, and it is not used widely by now. So there must be bugs.

Some known bugs for debugging multi-thread program, #38 and #39.

Besides, I write a new tool libleak, which works by hooking memory functions by LD_PRELOAD. It's much simpler and has much less impact on performance. So I am not going to improve memleax. Try libleak please.

how it works

memleax debugs memory leak of a running process by attaching it. It hooks the target process's invocation of memory allocation and free, and reports the memory blocks which live long enough as memory leak, in real time. The default expire threshold is 10 seconds, however you should always set it by -e option according to your scenarios.

It is very convenient to use, and suitable for production environment. There is no need to recompile the program or restart the target process. You run memleax to monitor the target process, wait for the real-time memory leak report, and then kill it (e.g. by Ctrl-C) to stop monitoring.

memleax follows new threads, but not forked processes. If you want to debug multiple processes, just run multiple memleax.

performance impact

Because target process's each invocation of memory allocation and free makes a TRAP, the performance impact depends on the frequency of memory invocation in target process.

For example, it impacts lightly to nginx with HTTP, while heavily with HTTPS, because OpenSSL calls malloc() terribly.

difference from Valgrind

  • Valgrind starts target process, while memleax attaches to a running process;

  • Valgrind gives memory leak report after target process quits, while memleax reports in real time;

  • Valgrind reports all unfreed memory include program init, while memleax reports only after attaching, skipping the init phase;

  • Valgrind runs target process on its virtual CPU, which makes it slow. While memleax hooks memory APIs, which may be less slow if the target process call memory APIs not often.

  • Valgrind debugs kinds of memory bugs, while memleax is lightweight and only detects memory leak.

In summary, I think Valgrind is more powerful, while memleax is more convenient and suitable for production environment.

licence

GPLv2

OS-machine

  • GNU/Linux at x86 and x86_64, tested on CentOS 7.2 and Ubuntu 16.04
  • GNU/Linux at armv7 and aarch64, tested on Raspbian and pi64.
  • FreeBSD at i386 and amd64, tested on FreeBSD 10.3

NOTE: If memleax can not show function backtrace on GNU/Linux at aarch64, you could try to compile the target program with -funwind-tables flag of GCC.

install by package

There are DEB and RPM packages for releases.

For Arch Linux users, memleax is available in AUR. Thanks to jelly.

For FreeBSD users, memleax is available in FreeBSD Ports Collection. Thanks to tabrarg.

I tried to submit memleax to Fedora EPEL, but failed. Any help is welcomed.

build from source

The development packages of the following libraries are required:

  • libunwind
  • libelf
  • libdw or libdwarf. libdw is preferred. They are used to read dwarf debug-line information. If you do not have them neither, set --disable-debug_line to configure to disable it. As a result you will not see file name and line number in backtrace.

These packages may have different names in different distributions, such as libelf may names libelf, elfutils-libelf, or libelf1.

NOTE: On FreeBSD 10.3, there are built-in libelf and libdwarf already. However another libelf and libdwarf still can be installed by pkg. memleax works with built-in libelf and pkg libdwarf. So you should install libdwarf by pkg, and must not install libelf by pkg.

After all required libraries are installed, run

$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install

usage

start

To debug a running process, run:

$ memleax [options] <target-pid>

then memleax begins to monitor the target process, and report memory leak in real time.

You should always set expire time by -e options according to your scenarios. For example, if you are debugging an HTTP server with keepalive, and there are connections last for more than 5 minutes, you should set -e 360 to cover it. If your program is expected to free every memory in 1 second, you should set -e 2 to get report in time.

wait and check the report

The memory blocks live longer than the threshold, are showed as:

CallStack[3]: memory expires with 101 bytes, backtrace:
    0x00007fd322bd8220  libc-2.17.so  malloc()+0
    0x000000000040084e  test  foo()+14  foo.c:12
    0x0000000000400875  test  bar()+37  bar.c:20
    0x0000000000400acb  test  main()+364  test.c:80

CallStack[3] is the ID of CallStack where memory leak happens.

The backtrace is showed only on the first time, while it only shows the ID and counter if expiring again:

CallStack[3]: memory expires with 101 bytes, 2 times again

If the expired memory block is freed later, it shows:

CallStack[6]: expired-memory frees after 10 seconds

If there are too many expired-memory-blocks are freed on one CallStack, this CallStack will not be showed again:

Warning: too many expired-free at CallStack[6]. will not show this CallStack later

When you think you have found the answer, stop the debug.

stop

memleax quits on:

  • you stop it, by Ctrl-C or kill,
  • the target process quits,
  • too many leaks at one CallStack (option -m), or
  • too many CallStacks with memory leak (option -c).

After quitting, it also gives statistics for the CallStacks with memory leak:

CallStack[3]: may-leak=20 (2020 bytes)
    expired=20 (2020 bytes), free_expired=0 (0 bytes)
    alloc=20 (2020 bytes), free=0 (0 bytes)
    freed memory live time: min=0 max=0 average=0
    un-freed memory live time: max=20
    0x00007fd322bd8220  libc-2.17.so  malloc()+0
    0x000000000040084e  test  foo()+14  foo.c:12
    0x0000000000400875  test  bar()+37  bar.c:20
    0x0000000000400acb  test  main()+364  test.c:80
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].