Script for use on Linux machines to take thread dumps over time for a java application

26 Aug
Usage

To use, simply go

./scriptName.sh {jstack|signal} <pid> <number of dumps> <interval (seconds)>
E.g:
./scriptName.sh signal 23524 3 5

This will take 3 thread dumps 5 seconds apart (a total of 3 dumps in 15 seconds) for the process id 23524. To find out the ‘pid’ use top/ps or similar.

Use signal if you don’t have jstack installed.

The Script

#! /bin/bash

#
# This script will cause a java application to drop a thread
# dump to it's log every <interval (seconds)> for <number of dumps> times

case "$1" in
	jstack)
		CMD=jstack
	;;
	signal)
		CMD="kill -QUIT"
	;;
	*)
		echo "Usage: threadDumpsOverTime.sh {jstack|signal} <pid> <number of dumps> <interval (seconds)>"
		exit 1;
esac

i=0
while [ $i -lt $3 ]
do
	$CMD $2
	sleep $4
	let i=$i+1
done

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: