sysbench scripts (12)

     銜接上文,以下是analyze文件夾下的腳本。

    12、analyze_innodb_checkpoint.sh腳本

#! /bin/sh

###########################################################
# Copyright (c) 2012, Heng.Wang. All rights reserved.
#
# This program is used to analyze the checkpoint.
###########################################################

# set -x

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

# Usage will be helpful when you need to input the valid arguments.
usage()
{
cat <<EOF
Usage: $0 [configure-options]
  -?, --help                       Show this help message.
  --input=<>                       Set the input file path.
  --outputdir=<>                   Set the output directory.  

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

EOF
}

# Print the default value of the arguments of the script.
print_default()
{
cat <<EOF
  The default value of the variables:
  input             $INPUT
  outputdir         $OUTPUTDIR

EOF
}

# Parse the input arguments and get the value of the input argument.
parse_options()
{
  while test $# -gt 0
  do
    case "$1" in    
    --input=*)
      INPUT=`get_key_value "$1"`;;
    --outputdir=*)
      OUTPUTDIR=`get_key_value "$1"`;;
    -? | --help)
      usage
      print_default
      exit 0;;
    *)
      echo "Unknown option '$1'"
      exit 1;;
    esac
    shift
  done
}



#################################################################
INPUT=""
OUTPUTDIR=/opt/result

parse_options "$@"

if [ -z $INPUT ]
then 
  echo "Please give the input file address!"
  exit -1
fi

if [ -f $INPUT ]
then
  [[ -d $OUTPUTDIR ]] || mkdir -p $OUTPUTDIR
  
  dir1=`dirname $INPUT`
  dir2=`dirname $dir1`
 
  cat $INPUT | awk ' BEGIN { } /Log sequence number/ {st=$4 } /Last checkpoint at/ \
  { ed=$4; print (st-ed)/1024/1024 } '>$OUTPUTDIR/checkpoint_${dir2##*/}_${dir1##*/}.result
  exit 0
else
  echo "The input file is not exist!"
  echo "Please be double check the input file!"
  exit -1
fi
  


發佈了34 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章