Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1330569
  • 博文数量: 107
  • 博客积分: 1715
  • 博客等级: 上尉
  • 技术积分: 3168
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-18 18:42
个人简介

阿里巴巴DBA,原去哪儿网DBA。专注于MySQL源码研究、DBA运维、CGroup虚拟化及Linux Kernel源码研究等。 github:https://github.com/HengWang/ Email:king_wangheng@163.com 微博 :@王恒-Henry QQ :506437736

文章分类

全部博文(107)

文章存档

2014年(2)

2013年(38)

2012年(67)

分类: Mysql/postgreSQL

2012-05-11 15:09:01

2、analyze.sh脚本

点击(此处)折叠或打开

  1. #! /bin/sh

  2. ###########################################################
  3. # Copyright (c) 2012, Heng.Wang. All rights reserved.
  4. #
  5. # This program is used to analyze the sysbench test report.
  6. ###########################################################

  7. # set -x

  8. # Get the key value of input arguments format like '--args=value'.
  9. get_key_value()
  10. {
  11.     echo "$1" | sed 's/^--[a-zA-Z_-]*=//'
  12. }

  13. # Usage will be helpful when you need to input the valid arguments.
  14. usage()
  15. {
  16. cat <<EOF
  17. Usage: $0 [configure-options]
  18.   -?, --help Show this help message.
  19.   --inputdir=<> Set the input file path.
  20.   --min-threads=<> Set the min threads number.
  21.   --max-threads=<> Set the max threads number.
  22.   --step=<> Set the thread incremental step.
  23.   --count=<> Set the count of test.
  24.   --outputdir=<> Set the output directory.

  25. Note: this script is intended for internal use by developers.

  26. EOF
  27. }

  28. # Print the default value of the arguments of the script.
  29. print_default()
  30. {
  31. cat <<EOF
  32.   The default value of the variables:
  33.   inputdir $INPUTDIR
  34.   min-threads $MIN_THREADS
  35.   max-threads $MAX_THREADS
  36.   step $STEP
  37.   count $COUNT
  38.   outputdir $OUTPUTDIR

  39. EOF
  40. }

  41. # Parse the input arguments and get the value of the input argument.
  42. parse_options()
  43. {
  44.   while test $# -gt 0
  45.   do
  46.     case "$1" in
  47.     --inputdir=*)
  48.       INPUTDIR=`get_key_value "$1"`;;
  49.     --min-threads=*)
  50.       MIN_THREADS=`get_key_value "$1"`;;
  51.     --max-threads=*)
  52.       MAX_THREADS=`get_key_value "$1"`;;
  53.     --step=*)
  54.       STEP=`get_key_value "$1"`;;
  55.     --count=*)
  56.       COUNT=`get_key_value "$1"`;;
  57.     --outputdir=*)
  58.       OUTPUTDIR=`get_key_value "$1"`;;
  59.     -? | --help)
  60.       usage
  61.       print_default
  62.       exit 0;;
  63.     *)
  64.       echo "Unknown option '$1'"
  65.       exit 1;;
  66.     esac
  67.     shift
  68.   done
  69. }

  70. #################################################################
  71. INPUTDIR=""
  72. MIN_THREADS=100
  73. MAX_THREADS=1000
  74. STEP=100
  75. COUNT=1
  76. OUTPUTDIR=/opt/result

  77. parse_options "$@"

  78. if [ -z $INPUTDIR ]
  79. then
  80.   echo "Please give the input file address!"
  81.   exit -1
  82. fi

  83. [[ -d $OUTPUTDIR ]] || mkdir -p $OUTPUTDIR


  84. threads=$MIN_THREADS
  85. # Test the influence of the given argument with different threads .
  86. while [ $threads -le $MAX_THREADS ]
  87. do

  88.   # If the number of min threads adds step bigger than the number of max threads,
  89.   # then set outputdir to the subdirectory of outputdir.
  90.   if [ $MIN_THREADS -lt $MAX_THREADS ]
  91.   then
  92.     threadpath=${INPUTDIR}/${threads}
  93.   else
  94.     threadpath=${INPUTDIR}
  95.   fi
  96.         
  97.   iter=1
  98.   while [ $iter -le $COUNT ]
  99.   do
  100.     
  101.     # If the count variable bigger than 1, then set outputdir to
  102.      # the subdirectory of outputdir.
  103.      if [ $COUNT -eq 1 ]
  104.      then
  105.      iterpath=${threadpath}
  106.      else
  107.      iterpath=${threadpath}/${iter}
  108.      fi
  109.     
  110.      # If the subdirectory is exists, then run the analyze scripts.
  111.     if [ -d $iterpath ]
  112.     then
  113.       
  114.       sysbench_file=`find $iterpath -name "sysbench_*.res"`
  115.       global_file=`find $iterpath -name "global_*.stat"`
  116.       innodb_file=`find $iterpath -name "innodb_*.stat"`
  117.       
  118.       # Analyze the sysbench output result and get the sysbench report and key value.
  119.       if [ -f $sysbench_file ]
  120.       then
  121.         echo "----Analyze the sysbench report----"
  122.         ./analyze/analyze_sysbench_report.sh --input=$sysbench_file --outputdir=$OUTPUTDIR
  123.         if [ $? -ne 0 ]
  124.      then
  125.      echo "Exit with error when run analyze_sysbench_report.sh procedure!"
  126.      exit -1
  127.      fi
  128.     
  129.         echo "----Analyze the sysbench key value----"
  130.         ./analyze/analyze_sysbench_performance_args.sh --input=$sysbench_file --outputdir=$OUTPUTDIR
  131.         if [ $? -ne 0 ]
  132.      then
  133.      echo "Exit with error when run analyze_sysbench_performance_args.sh procedure!"
  134.      exit -1
  135.      fi
  136.     
  137.       else
  138.         echo "The sysbench test output data file is not exists!"
  139.         echo "Please be double check the address $iterpath where the file like 'sysbench_*.res'"
  140.         exit -1
  141.       fi
  142.       
  143.       # Analyze the global innodb status result and get the innodb pages flushed and dirty page ratio
  144.       if [ -f $global_file ]
  145.       then
  146.         echo "----Analyze the global innodb page flushed----"
  147.         ./analyze/analyze_global_innodb_page_flushed.sh --input=$global_file --outputdir=$OUTPUTDIR
  148.         if [ $? -ne 0 ]
  149.      then
  150.      echo "Exit with error when run analyze_global_innodb_page_flushed.sh procedure!"
  151.      exit -1
  152.      fi
  153.         
  154.         echo "----Analyze the global innodb dirty page ratio----"
  155.         ./analyze/analyze_global_innodb_dirty_page_ratio.sh --input=$global_file --outputdir=$OUTPUTDIR
  156.         if [ $? -ne 0 ]
  157.      then
  158.      echo "Exit with error when run analyze_global_innodb_dirty_page_ratio.sh procedure!"
  159.      exit -1
  160.      fi
  161.         
  162.       else
  163.         echo "The sysbench test output data file is not exists!"
  164.         echo "Please be double check the address $iterpath where the file like 'global_*.stat'"
  165.         exit -1
  166.       fi
  167.       
  168.       # Analyze the innodb status result and get the log flushed fallbehind and checkpoint.
  169.       if [ -f $innodb_file ]
  170.       then
  171.         echo "----Analyze the innodb log flushed fallbehind----"
  172.         ./analyze/analyze_innodb_log_flushed_fallbehind.sh --input=$innodb_file --outputdir=$OUTPUTDIR
  173.         if [ $? -ne 0 ]
  174.      then
  175.      echo "Exit with error when run analyze_innodb_log_flushed_fallbehind.sh procedure!"
  176.      exit -1
  177.      fi
  178.         
  179.         echo "----Analyze the innodb checkpoint----"
  180.         ./analyze/analyze_innodb_checkpoint.sh --input=$innodb_file --outputdir=$OUTPUTDIR
  181.         if [ $? -ne 0 ]
  182.      then
  183.      echo "Exit with error when run analyze_innodb_checkpoint.sh procedure!"
  184.      exit -1
  185.      fi
  186.         
  187.       else
  188.         echo "The sysbench test output data file is not exists!"
  189.         echo "Please be double check the address $iterpath where the file like 'innodb_*.stat'"
  190.         exit -1
  191.       fi
  192.     
  193.     # The subdirectory is not exist.
  194.     else
  195.       echo "The input directory don\'t exist the subdirectory!"
  196.       echo "Please be double check the input file!"
  197.       exit -1
  198.     fi
  199.     
  200.     iter=$(($iter+1))
  201.   done
  202.   
  203.   # Summary the test result
  204.   if [ $COUNT -ne 1 ]
  205.   then
  206.   
  207.     echo "Summarize the test result for thread number is ${threads}"
  208.     
  209.     checkpoint_files=`find $OUTPUTDIR -name "checkpoint_*${threads}*.result"`
  210.     dirty_pages_files=`find $OUTPUTDIR -name "dirty_*${threads}*.result"`
  211.     flushed_pages_files=`find $OUTPUTDIR -name "flushed_*${threads}*.result"`
  212.     log_flushed_files=`find $OUTPUTDIR -name "log_*${threads}*.result"`
  213.     # Summary the checkpoint for each thread.
  214.     paste $checkpoint_files | awk '{sum=0;for(i=1;i<=NF;i++) sum+=$i; print sum/NF}' > $OUTPUTDIR/summary_checkpoint_${threads}_avg.result
  215.     # Summary the dirty page ratio for each thread.
  216.     paste $dirty_pages_files | awk '{sum=0;for(i=1;i<=NF;i++) sum+=$i; print sum/NF}' > $OUTPUTDIR/summary_dirty_page_ratio_${threads}_avg.result
  217.     # Summary the flushed pages for each thread.
  218.     paste $flushed_pages_files | awk '{sum=0;for(i=1;i<=NF;i++) sum+=$i; print sum/NF}' > $OUTPUTDIR/summary_flushed_pages_${threads}_avg.result
  219.     # Summary the log flushed fallbehind for each thread.
  220.     paste $log_flushed_files | awk '{sum=0;for(i=1;i<=NF;i++) sum+=$i; print sum/NF}' > $OUTPUTDIR/summary_log_flushed_fallbehind_${threads}_avg.result
  221.     
  222.   fi
  223.   
  224.   threads=$((${threads}+${STEP}))
  225. done

  226. echo "The analysis is successfully finished!"
  227. echo "-------------------------------------"
  228. exit 0
阅读(1725) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册