Chinaunix首页 | 论坛 | 博客
  • 博客访问: 969910
  • 博文数量: 99
  • 博客积分: 3306
  • 博客等级: 中校
  • 技术积分: 1238
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-21 10:14
文章分类

全部博文(99)

文章存档

2012年(37)

2011年(56)

2010年(6)

分类: Python/Ruby

2011-09-23 00:12:08

因为需要测试jvm 的性能,需要收集YGC和FGC等性能数据,写了个脚本来统计5分钟的情况。

  1. #!/bin/bash
  2. ################################
  3. DELTA=3 #print each DELTA seconds
  4. TTIME=18 #total time
  5. MYPID=$$
  6. usage(){
  7.         echo "usage:"
  8.         echo -e "\t$0 -d gap_time -t total_time"
  9.         echo -e "\tthe unit is seconds, not subsecond."
  10. }
  11. while getopts d:t:n: ARGS
  12. do
  13.         case $ARGS in
  14.         t)
  15.                 TTIME=$OPTARG
  16.                 ;;
  17.         d)
  18.                 DELTA=$OPTARG
  19.                 ;;
  20.         *)
  21.                 usage
  22.                 exit 1
  23.                 ;;
  24.         esac
  25. done
  26. if [ $TTIME -lt $DELTA ]; then
  27.         echo "gap_time must less than total_time!"
  28.         exit 2
  29. fi
  30. FLAG=$(( TTIME % DELTA ))
  31. if [ $FLAG -ne 0 ]; then
  32.         echo "total_time/gap_time ==0 !"
  33.         exit 3
  34. fi
  35. N=$(( TTIME / DELTA ))
  36. DELTA=$(( 1000 * DELTA ))
  37. TTIME=$(( 1000 * TTIME ))
  38. PFLAG=$(ps aux|grep java|grep -v -E 'grep|agent'|grep 'Xms'|awk '{print $2}'|wc -l)
  39. if [[ $PFLAG > 1 ]];then
  40.       echo "find more than 1 java process,exit"
  41.       exit 1
  42. fi
  43. PID=$(ps aux|grep java|grep -v -E 'grep|agent'|grep 'Xms'|awk '{print $2}')
  44. if [ -d /proc/$PID ] ;then
  45.         echo -e "\e[31mjava pid is $PID\e[m"
  46. else
  47.         echo -e "\e[32mcan't find java process!\e[m"
  48.         exit 2
  49. fi
  50. jstat -gc $PID $DELTA 2>&1 |awk \
  51. 'BEGIN {
  52.         M="'$N'"
  53.         i=0
  54.         times=0

  55. }
  56. NR>1{
  57.         ygc[i]=$11
  58.         ygct[i]=$12
  59.         fgc[i]=$13
  60.         fgct[i]=$14
  61.         #print "M=",M,"i=",i
  62.         if(i==0){
  63.             printf("YGC\tYGCT\tFGC\tFGCT\n")
  64.         }
  65.         printf("%s\t%s\t%s\t%s\n",ygc[i],ygct[i],fgc[i],fgct[i])
  66.         if(++i - M >0) {
  67.                 times++
  68.                 printf("#########in %d subseconds#############\n","'$TTIME'")
  69.                 printf("\tYGC=%s\n",ygc[M]-ygc[0])
  70.                 printf("\tYGCT=%s\n",ygct[M]-ygct[0])
  71.                 printf("\tFGC=%s\n",fgc[M]-fgc[0])
  72.                 printf("\tFGCT=%s\n",fgct[M]-fgct[0])
  73.                 printf("##########################################\n")
  74.                 system("date '+%Y_%m_%d_%T'")
  75.                 i=0
  76.         }
  77. }'

阅读(10331) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~