Creating Windows Thread Dumps for Atlassian Review

red-blue-and-pink-thread-spool.jpg

As a Jira administrator, sometimes you need to get down to the OS level to figure out a performance issue. For many of us, OS-level work is not our strength; after all, we are Jira administrators and we are used to working in our Jira GUI. At most, we might read through the atlassian-jira.log file.

For a recent ticket that I opened with Atlassian, I was asked to create a series of thread dumps at different intervals. In this case, I was asked to provide 50 thread dumps every 3 seconds and 5 thread dumps every minute, for 55 thread dumps altogether. Being a developer, my first thought is “How can I automate this?”.

Here is my solution.

The first step is to make sure that you have jstack.exe installed. This comes with the Java JDK, not the JRE that ships with Jira. If you have not installed the JDK on the system where Jira is running, then download it from Oracle or OpenJDK. Note where it is installed. You will need this information to edit the script.

Next, you need to find the process that is running Jira. Open the Windows Task Manager and add the Process ID column to the view

image-20200430-150054.png

Look through the process list until you find your Jira process. Depending on whether you are running it as a service or from the command line, it will appear differently in your list. Regardless of how you find it, you will need the process id.

Now you are ready to get the thread dumps. The PowerShell Script that I wrote to automate this task is below

$processId = 6972
$jstack = "C:\Program Files\Java\jdk1.8.0_191\bin\jstack.exe"
$outdir = "C:\Users\RightStar\Documents\threaddump"

# get the thread dumps
# we need a filename, the number of runs to make
# The seconds and minutes indicate the time between runs
function get-thread ($fname, $runs, $seconds, $minutes) {

# Convert the seconds and minutes to seconds
$interval = $seconds + $minutes*60

for ($i=0;$i -lt $runs; $i++) {

# Get the current time for this run and set a filename
$start = (get-date)
$filename = "$fname$i.txt"
echo "Running iteration $i with interval of $interval seconds"

# Call jstack to create the thread dump
& $jstack -l $processId > "$outdir\$filename"

# Start a loop to wait until the time has elapsed
$datediff = (get-date)-$start
$elapsed = $datediff.seconds + $datediff.minutes*60
while ($elapsed -lt $interval) {
datediff = (get-date)-$start
$elapsed = $datediff.seconds + $datediff.minutes*60
}
}
}

# Get 50 threads with 3 second intervals
get-thread "3_seconddump" 50 3 0

# Get 5 threads with 1 minute intervals
get-thread "1_minutedump" 5 0 1

That is it. This script, which is commented internally, will run the thread dumps based on your parameters.

Feel free to use it, change it, improve on it. I hope it helps

1 comment

M Amine
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 1, 2020

Great article.

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events