Based on information from: https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Heap-Profiling
RedHat & related flavours don't enable profiling in their binaries, so we need to build from source:
wget https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2
tar xjf jemalloc-5.3.0.tar.bz2
cd jemalloc-5.3.0
./configure --enable-stats --enable-prof
make -j16
sudo make install
Check install location - on RedHat is /usr/local/lib/libjemalloc.so.2
If not explicitly linking to jemalloc, it needs to be preloaded:
- RedHat-based Linux:
export LD_PRELOAD=/usr/local/lib/libjemalloc.so.2
MALLOC_CONF=stats_print:true <my_program>
Dump a profile every time a Virtual Memory reaches a new maximum:
MALLOC_CONF="prof:true,prof_prefix:jeprof.out,prof_gdump:true" <my_program>