因为需要测试jvm 的性能,需要收集YGC和FGC等性能数据,写了个脚本来统计5分钟的情况。
- #!/bin/bash
-
################################
-
DELTA=3 #print each DELTA seconds
-
TTIME=18 #total time
-
MYPID=$$
-
usage(){
-
echo "usage:"
-
echo -e "\t$0 -d gap_time -t total_time"
-
echo -e "\tthe unit is seconds, not subsecond."
-
}
-
while getopts d:t:n: ARGS
-
do
-
case $ARGS in
-
t)
-
TTIME=$OPTARG
-
;;
-
d)
-
DELTA=$OPTARG
-
;;
-
*)
-
usage
-
exit 1
-
;;
-
esac
-
done
-
if [ $TTIME -lt $DELTA ]; then
-
echo "gap_time must less than total_time!"
-
exit 2
-
fi
-
FLAG=$(( TTIME % DELTA ))
-
if [ $FLAG -ne 0 ]; then
-
echo "total_time/gap_time ==0 !"
-
exit 3
-
fi
-
N=$(( TTIME / DELTA ))
-
DELTA=$(( 1000 * DELTA ))
-
TTIME=$(( 1000 * TTIME ))
-
PFLAG=$(ps aux|grep java|grep -v -E 'grep|agent'|grep 'Xms'|awk '{print $2}'|wc -l)
-
if [[ $PFLAG > 1 ]];then
-
echo "find more than 1 java process,exit"
-
exit 1
-
fi
-
PID=$(ps aux|grep java|grep -v -E 'grep|agent'|grep 'Xms'|awk '{print $2}')
-
if [ -d /proc/$PID ] ;then
-
echo -e "\e[31mjava pid is $PID\e[m"
-
else
-
echo -e "\e[32mcan't find java process!\e[m"
-
exit 2
-
fi
-
jstat -gc $PID $DELTA 2>&1 |awk \
-
'BEGIN {
-
M="'$N'"
-
i=0
-
times=0
-
-
}
-
NR>1{
-
ygc[i]=$11
-
ygct[i]=$12
-
fgc[i]=$13
-
fgct[i]=$14
-
#print "M=",M,"i=",i
-
if(i==0){
-
printf("YGC\tYGCT\tFGC\tFGCT\n")
-
}
-
printf("%s\t%s\t%s\t%s\n",ygc[i],ygct[i],fgc[i],fgct[i])
-
if(++i - M >0) {
-
times++
-
printf("#########in %d subseconds#############\n","'$TTIME'")
-
printf("\tYGC=%s\n",ygc[M]-ygc[0])
-
printf("\tYGCT=%s\n",ygct[M]-ygct[0])
-
printf("\tFGC=%s\n",fgc[M]-fgc[0])
-
printf("\tFGCT=%s\n",fgct[M]-fgct[0])
-
printf("##########################################\n")
-
system("date '+%Y_%m_%d_%T'")
-
i=0
-
}
-
}'
阅读(10331) | 评论(0) | 转发(0) |