Skip to content

Instantly share code, notes, and snippets.

@tmkasun
Created November 28, 2019 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmkasun/a07b16fa7499d9e92e13cbf4b88d266e to your computer and use it in GitHub Desktop.
Save tmkasun/a07b16fa7499d9e92e13cbf4b88d266e to your computer and use it in GitHub Desktop.
Thread analyser for MAC
#!/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
mkdir -p report
jstack -l $1 > report/thread_dump_`date "+%F-%T"`.txt &
ps -p $1 -Lo pid,tid,%cpu,time,nlwp,c > report/thread_usage_`date "+%F-%T"`.txt &
if [ $i -ne $count ]; then
echo "sleeping for $3 [$i]"
sleep $3
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment