jstack 导出堆栈信息

This commit is contained in:
jiangzeyin 2018-10-02 23:33:40 +08:00
parent 26b9667ee7
commit c97cd35661

35
bin/command/java_Analy.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
T=`ps -mp $1 -o THREAD,tid,time|sort -k 2 -nr|awk '{print $2","$8","$9}'|head -n 11|grep -v "-"`
Count=$2
Name=$3
if [ "$Name" = "" ]; then
Name="java_Analy.txt";
fi
touch $Name
: > $Name
cur_dateTime="`date +%Y-%m-%d_%H:%M:%S`"
echo "生成时间:$cur_dateTime" >>$Name
echo "进程id:$T"
for i in $T
do
consum=`echo $i |awk -F"," '{print $1}'`
tid=`echo $i |awk -F"," '{print $2}'`
dtime=`echo $i |awk -F"," '{print $3}'`
echo "线程id$tid"
id=`printf "%x\n" $tid`
echo "线程消耗CPU$consum% 运行时间:$dtime 线程id$id" >> $Name
jstack $1 |grep $id -A $Count >> $Name
echo "">> $Name
echo "===========================================================================================" >> $Name
done