Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Last active February 5, 2024 02:05
Show Gist options
  • Save thomasdarimont/79b3cef01e5786210309 to your computer and use it in GitHub Desktop.
Save thomasdarimont/79b3cef01e5786210309 to your computer and use it in GitHub Desktop.
Example for using jemalloc to analyze memory allocation profile of a Java Application

Install Graphviz

sudo apt-get install graphviz

#Clone jemalloc git clone https://github.com/jemalloc/jemalloc

Configurie jemalloc with profiling enabled

./configure --enable-prof --enable-stats --enable-debug --enable-fill make make install

Export jemalloc Konfiguration

export MALLOC_CONF="prof:true,prof_prefix:jeprof.out"

Shadow glibc malloc with version from jemallic

export LD_PRELOAD=/home/tom/dev/playgroud/jemalloc/jemalloc/lib/libjemalloc.so

Start Java Application

java -jar target/spring-boot-jemalloc-example-0.0.1-SNAPSHOT.jar

Analyze generated .heap snapshots and combine to .gif

jeprof --show_bytes --gif jeprof.*.heap > app-profiling.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment