Created
March 7, 2012 14:52
-
-
Save hikoma/1993616 to your computer and use it in GitHub Desktop.
Prints java stack traces of java threads eating the CPU
This file contains 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 | |
threshold=${1-95} | |
now=$(date '+%Y-%m-%d %H:%M:%S') | |
cache=() | |
jps -q | xargs ps hH k -pcpu o pid,lwp,pcpu,args \ | |
| awk "\$3 >= $threshold" | while read line; do | |
array=($(echo "$line")) | |
pid=${array[0]} | |
lwp=$(printf '%#x' ${array[1]}) | |
if [ -z "${cache[$pid]}" ]; then | |
cache[$pid]=$(jstack $pid) | |
fi | |
echo "[$now] ${line}" | |
echo | |
echo "${cache[$pid]}" | sed -n "/nid=$lwp/,/^$/p" | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment