Collecting JVM Thread Dumps

Collecting JVM Thread Dumps

  • perf-test.com need your contributions to build up a strong repository of performance engineering resources.

This article explains how to collect the thread dumps manually and automatically by scheduling running simple shell script

This process can be used on any java jvm deployed on any unix platforms

This Article explains how to collect the thread dumps for WAS on HPUX platform by specifying related paths

Thread dumps and Objective:

During performance tuning it is very important to check how the application is handing multiple concurrent threads. Well designed applications should not have any dependencies on other threads.

1. Collecting thread dumps manually:

1.1 We need to find out the Java PID for the profile

You can get the java process id by doing a simple grep, fire below command on your unix terminal (Of application server) to list down all java processes running on the system.

Ps –ef|grep java

To collect thread dump execute below command to send an interrupt to processor and collect thread dump‌

Kill -3 <PID of java process>

Above command will write the dumps to native_stdout.log file of java server.

2. Collecting thread dumps automatically

2.1Scheduling the thread dump collection

Some time we come across the scenarios where we need to collect the thread dumps periodically either on production systems or during endurance runs.

In order to collect thread dumps in such scenarios we can make thread dump collection as an automatic process

We can run the script by providing process ID on which thread dumps needs to be collected and the no. of snaps/dumps to be collected

Below mentioned is the simple script which automatically collects the thread dumps for each one hour and takes the backup of each thread dump collected on given WAS process ID


if [ $# -lt 2 ]

then

echo "Syntax:pass two parameters 1 - PID 2 - No. thread dumps/Hours"

exit

fi

pid=$1

snaps=$2

num=1

while [ "$num" -lt "$snaps" ]

do

echo $pid

cd /WAS/IBM/WebSphere/AppServer/profiles/somefolder/logs/server1

>native_stdout.log

sleep 60

kill -3 $pid

sleep 540

cp native_stdout.log native_stdout.log_$num

cd -

num=`expr $num + 1`

sleep 3000

done


Customizing the Script:


1. Above script expects two input parameters

2. First one to be passed is PID of java process on which thread dumps needs to be collected

3. Second one to be passed is no. of thread dumps needs to be collected

4. Script collects the thread dumps for each one hour, we can modify the values marked in pink above to change the time interval according to our requirements

a. 60 + 540 + 3000 = 3600 seconds, we can change these values according to our requirement

5. Marked in bold in above script is path related to the profile where we created the script, This needs to be modified according to the server path where thread dumps will be generated/collected
Author
AnmolD
Views
49
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from AnmolD