Skip to content

Instantly share code, notes, and snippets.

@kugelblitzz
Forked from bsenduran/thread-analyze.sh
Last active August 11, 2022 10:00
Show Gist options
  • Save kugelblitzz/ac5f8e008a46fa06acd90ece4f2daa49 to your computer and use it in GitHub Desktop.
Save kugelblitzz/ac5f8e008a46fa06acd90ece4f2daa49 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "usage: sh thread-analyze.sh <pid> <number-of-dumps> <interval>"
exit
fi
count=$2
for i in `seq 1 $count`;
do
/opt/java/bin/jstack -l $1 > thread_dump_`date "+%F-%T"`.txt &
ps --pid $1 -Lo pid,tid,%cpu,time,nlwp,c > thread_usage_`date "+%F-%T"`.txt &
if [ $i -ne $count ]; then
echo "sleeping for $3 [$i]"
sleep $3
fi
done
@kugelblitzz
Copy link
Author

Taking 4 thread dumps in one minute interval for java process with pid 1234
sh thread-analyze.sh 1234 10 1m

Available time units

s for seconds (the default)
m for minutes.
h for hours.
d for days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment