FIND HIGH CPU ON LINUX with JDK
Lot of times on the WLS PROD Environment we see high CPU on the java process , We just end up restarting the server , Its very hard to find the root cause
Here is small utility script that will display the Top 10 cpu consuming threads of the java process we just need to pass the <Java PID> to the script.
cpuhigh.sh
Just copy the script to a sh file
./cpuhigh.sh <javaPID>
#!/bin/bash # put your JAVA_HOME here, JAVA_HOME=/JDK/jdk160_31 PID=$1 IFS='' top_number=10 if [ $# -gt 1 ] ; then top_number=$2 fi top_number=$((top_number+1)) java_stack=`$JAVA_HOME/bin/jstack -l $PID` top=`top -s -b -H -p $PID -n 1 | grep -vE '^top|^Tasks|^Cpu|^Mem|^Swap|^$' | awk 'NR==1; NR > 1 {print $0 | "sort -nrk 9"}' | head -$top_number` echo $top echo $top | while read psline; do if [ `echo $psline|grep -c PID` -gt 0 ] ; then continue fi lwp_id=`echo $psline | awk '{print $1}'` nid=`printf '%x\n' $lwp_id ` echo "========> Java LWP: $lwp_id - Native Thread ID=$nid" echo $java_stack | sed -n "/$nid/,/^$/ p" ; done
Sample Output
No comments:
Post a Comment