Installing and Using gperftools to Analyze Java Off-Heap Memory
CentOS
- Install using yum
yum install gperftools libunwind
- Optional, PDF support
yum install graphviz
- Set environment variables
export LD_PRELOAD=/usr/lib64/libtcmalloc.so
export HEAPPROFILE=/DATA1/admin_tmp/gzip
- Start the Java program
Omitted
- Analyze memory usage, display results in text
pprof --text /usr/bin/java /DATA1/admin_tmp/gzip.0001.heap
- Analyze memory usage, display results in PDF
macOS
- Install using Homebrew
brew install gperftools 或者 brew install --build-from-source gperftools
- Optional, PDF support
brew install graphviz 或者 brew install --build-from-source graphviz
- Set environment variables
export DYLD_INSERT_LIBRARIES=/usr/local/Cellar/gperftools/2.8.1/lib/libtcmalloc.dylib
export HEAPPROFILE=/Users/cheng/tmp/test.log
- Start the Java program
Omitted
- Analyze memory usage, display results in text
pprof --text /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home/bin/java ~/tmp *.heap
- Analyze memory usage, display results in PDF
Compile and Install the Latest Version from Source
mkdir ~/gperftools
cd gperftools
wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.9.1/gperftools-2.9.1.zip
unzip gperftools-2.9.1.zip
cd gperftools-2.9.1
./configure
make
sudo make install
Reference Articles https://github.com/gperftools/gperftools/blob/master/INSTALL https://blog.csdn.net/gao_yu_long/article/details/104459116 https://mp.weixin.qq.com/s/BWayrHM6b7lEt4A_ZS-D_Q https://developer.ridgerun.com/wiki/index.php?title=Profiling_with_GPerfTools http://www.dylan326.com/2017/09/28/gperftools/