Using HPROF:
You can use HPROF: Heap and CPU Profiling Agent.
A complete dump of the current live objects in the heap can be obtained with:
-java -agentlib:hprof=heap=dump,format=b -jar application
This will automatically dump heap when java application is terminated. You can also force heap dump by sending QUIT signal to java process with kill -QUIT pid command.
Analysing Heapdump file using Jhat
You can use jhat (Java Heap Analysis Tool) to read the generated file:
– jhat [ options ]
The jhat command parses a java heap dump file and launches a webserver. jhat enables you to browse heap dumps using your favorite webbrowser.
Note that you should have a hprof binary format output to be able to parse it with jhat. You can useformat=b option to generate the dump in this format.
*****************************************************************************
Command to get Heap Dump on UNIX Platform:
Step1: Get the process ID of the server for which you are taking heap dump using below command
ps -ef | grep “server name”
Step2: Set PATH & CLASSPATH as below
export PATH=$PATH: <JDK bin path>
export CLASSPATH=$CLASSPATH: <WL-Home\server\lib>
Step3: Run below command to take Heap Dump
jmap -heap:format=b <PID>
It will generate a file named “heap.bin” in the path where you ran the command.
EX:
./jmap -dump:format=b,file=heapJMap.bin 5876
./jmap -heap:format=b 7000