Menu

Saturday 15 May 2021

Scripts for HeapDump Generation On JBoss || Tomcat

 ##To Capture the 1 HeapDmp file with CPU usage on Tomcat & JBoss application.

Step 1: Create a file "heap_dump_script.sh" and add below script codes.

##Codes for heapdump generation.
***********************************************************
#!/bin/sh
JAVA_HOME=/u01/jdk1.8.0_121
# Number of times to collect data.
LOOP=1
# Interval in seconds between data points.
INTERVAL=1
 
for ((i=1; i <= $LOOP; i++))
do
   _now=$(date)
   echo "${_now}" >>high-cpu-Heap.out
   top -b -n 1 -H -p $1 >>high-cpu-Heap.out
   echo "${_now}" >>high-cpu-Heapdump.out
  $JAVA_HOME/bin/jmap -dump:format=b,file=heapdump_`date +"%Y-%m-%d-%T"`.hprof $1
   echo "heap dump captured #" $i
   if [ $i -lt $LOOP ]; then
      echo "Sleeping..."
      sleep $INTERVAL
   fi
done
 ***********************************************

Step 2: How to Run the "heap_dump_script.sh" script.

./heap_dump_script.sh JVM_PID


For HeapDump analysis , use Memory Analyzer (MAT) tool.

Download Address: https://www.eclipse.org/mat/downloads.php


Thanks :-)


No comments:

Post a Comment