Created
July 23, 2013 08:19
-
-
Save sdslnmd/6060738 to your computer and use it in GitHub Desktop.
top java thread performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
redEcho() | |
{ | |
echo -e "\033[1;31m$@\033[0m" | |
} | |
pid=`pgrep java` | |
uuid=`date +%s`_${RANDOM}_$$ | |
jstackFile=/tmp/${uuid}_${pid} | |
sudo -u tomcat jstack ${pid} > ${jstackFile} | |
top -b -n1 -d0.01 -H -p ${pid} | grep tomcat | sort -k9 -r -n | head -5 | while read threadLine ; do | |
threadId=`echo ${threadLine} | awk '{print $1}'` | |
threadId0x=`printf %x ${threadId}` | |
pcpu=`echo ${threadLine} | awk '{print $9}'` | |
user=`echo ${threadLine} | awk '{print $2}'` | |
[ ! -f "${jstackFile}" ] && | |
{ | |
{ redEcho "Fail to jstack java process ${pid}"; rm ${jstackFile} ; continue; } | |
} | |
redEcho "The stack of busy(${pcpu}%) thread(${threadId}/0x${threadId0x}) of java process(${pid} of user(${user}):" | |
sed "/nid=0x${threadId0x}/,/^$/p" -n ${jstackFile} | |
done | |
rm /tmp/${uuid}_* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it!