#新建javacpu.sh ,并赋予可执行权限
#!/bin/bash

JAVA_PID=`top -b -n 1|grep java|head -n 1|awk '{print $1}'`
HIGH_CPU_TID=`ps -mp $JAVA_PID -o THREAD,tid,time | sort -rn |head -n 3 |tail -n 1 |awk '{print $8}'`
HIGH_CPU_TID_HEX=`printf "%x\n" $HIGH_CPU_TID`

echo "JAVA_PID: "$JAVA_PID""
echo "HIGH_CPU_TID: "$HIGH_CPU_TID""
echo "HIGH_CPU_TID_HEX: "$HIGH_CPU_TID_HEX""

echo `date` `(jstack  $JAVA_PID | grep $HIGH_CPU_TID_HEX  -A 30)`
echo `date` `(jstack  $JAVA_PID | grep $HIGH_CPU_TID_HEX  -A 30)` >> /usr/local/javacpu.log

#运行方法  ./javacpu.sh

Logo

更多推荐