Skip to content

Instantly share code, notes, and snippets.

@vstakhov
Created January 12, 2017 12:40
Show Gist options
  • Save vstakhov/b9a4e94abdb1b5255aaba3dceeb7ea18 to your computer and use it in GitHub Desktop.
Save vstakhov/b9a4e94abdb1b5255aaba3dceeb7ea18 to your computer and use it in GitHub Desktop.
Jemalloc profiler practical sample
  1. Get source package: apt-get source libjemalloc-dev
  2. Install build depends: apt-get build-dep libjemalloc-dev
  3. Go to the source dir and edit debian/rules file adding the following text:
override_dh_auto_configure:
        dh_auto_configure -- --enable-debug --enable-fill --enable-prof --enable-stat
  1. Build packages: dpkg-buildpackage
  2. Install new jemalloc: dpkg -i ../libjemalloc*.deb

After these steps you can use jemalloc to profile your code. For example, if you want to save profiles into /tmp (useful for daemons) you can run code with the following environment variables:

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so 
MALLOC_CONF=prof_leak:true,lg_prof_sample:0,prof_final:true,prof_prefix:/tmp/jemalloc

After program is started and finished (either normally or by some catchable signal), you can use pprof to get the dump. Unfortunately, debian package does not install it, however, you can still use this utility from the source folder:

~/jemalloc-<version>/bin/pprof <path_to_binary> /tmp/jemalloc-<pid_id>

To output postscript you need graphviz and the following command:

~/jemalloc-<version>/bin/pprof --ps <path_to_binary> /tmp/jemalloc-<pid_id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment