Skip to content
forked from jrfonseca/memtrail

A LD_PRELOAD based memory profiler and leak detector for Linux

Notifications You must be signed in to change notification settings

UIKit0/memtrail

 
 

Repository files navigation

About

memtrail is a LD_PRELOAD based memory profiler and leak detector for Linux.

There are already many other open-source memory debugging/profiling tools for Linux, several of which are listed on Links section below, and the most powerful arguably being Valgrind. However, I needed a tool that could quantify leaks and identify memory hogs, for long-running and CPU intensive workloads, which simply run too slow under Valgrind's dynamic binary instrumentation, hence this project.

Features

  • Very little runtime overhead

  • Will immediately output maxmimum memory allocated and total leaked memory at the end of program execution.

  • Text trees show callstacks for memory consuption or leaks

  • Can produce graphs showing flow of memory consumption or leaks

Requirements

Build

make

Usage

Run the application you want to debug as

memtrail record /path/to/application [args...]

and it will generate a record memtrail.data in the current directory.

View results with

memtrail report

It will produce something like

maximum: 5890 bytes

->34.77% (2048B): test_calloc
| ->34.77% (2048B): main
|   ->34.77% (2048B): __libc_start_main
|     ->34.77% (2048B): _start
| 
->17.39% (1024B): test_memalign
| ->17.39% (1024B): main
|   ->17.39% (1024B): __libc_start_main
|     ->17.39% (1024B): _start
| 
->17.39% (1024B): test_malloc
| ->17.39% (1024B): main
|   ->17.39% (1024B): __libc_start_main
|     ->17.39% (1024B): _start
| 
-> 8.69% (512B): TestGlobal::TestGlobal()
| -> 8.69% (512B): __static_initialization_and_destruction_0
|   -> 8.69% (512B): _GLOBAL__sub_I_leaked
|     -> 8.69% (512B): __libc_csu_init
|       -> 8.69% (512B): __libc_start_main
|         -> 8.69% (512B): _start
| 
-> 8.69% (512B): test_cxx
| -> 8.69% (512B): main
|   -> 8.69% (512B): __libc_start_main
|     -> 8.69% (512B): _start
| 
-> 8.69% (512B): test_cxx
| -> 8.69% (512B): main
|   -> 8.69% (512B): __libc_start_main
|     -> 8.69% (512B): _start
| 
-> 4.35% (256B): TestGlobal::TestGlobal()
| -> 4.35% (256B): __static_initialization_and_destruction_0
|   -> 4.35% (256B): _GLOBAL__sub_I_leaked
|     -> 4.35% (256B): __libc_csu_init
|       -> 4.35% (256B): __libc_start_main
|         -> 4.35% (256B): _start
| 
-> 0.02% (1B) in 2 places, all below the 1.00% threshold

memtrail.maximum.json written

You can then use gprof2dot.py to obtain graphs highlighting memory leaks or consumption:

gprof2dot.py -f json memtrail.maximum.json | dot -Tpng -o memtrail.maximum.png

Sample

#include "memtrail.h"

...

   memtrail_snapshot();

Links

Memory debugging:

Memory profiling:

Catalogs:

About

A LD_PRELOAD based memory profiler and leak detector for Linux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 45.0%
  • C++ 42.8%
  • C 9.7%
  • Makefile 2.5%