nickdesaulniers / malloc-flame-graph

runtime function interposition for malloc to generate callsite flamegraphs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Malloc Flame Graph

A fake malloc hook (using runtime function interposition) that logs backtraces of allocation sites, and tools to preprocess the log into a flamegraph.

The # of samples is actually the size of the allocation. Allocation sites are grouped by call frame.

Also, for more meaningful stack frames, you probably want debug builds (debug info and unstripped binary names).

Usage

$ rm -f mallocs.log
$ LD_PRELOAD=./hook.so clang -fuse-ld=lld hello_world.c
$ c++filt < mallocs.txt > mallocs.demangled
$ python flatten.py > mallocs.txt
$ path/to/FlameGraph/flamegraph.pl mallocs.txt > mallocs.svg

hook.so appends to a file named mallocs.txt. flatten.py reads a file named mallocs.demangled.

Dependencies

  • FlameGraph
  • c++filt (optional, if you'd like demangled C++ function names)
  • python

Links

About

runtime function interposition for malloc to generate callsite flamegraphs


Languages

Language:C 80.9%Language:Python 14.4%Language:Makefile 4.7%