- Get source package:
apt-get source libjemalloc-dev
- Install build depends:
apt-get build-dep libjemalloc-dev
- 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
- Build packages:
dpkg-buildpackage
- 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>