~pwlars/ubuntu-test-cases/dialer-messaging-address-book

« back to all changes in this revision

Viewing changes to systemsettle/systemsettle.sh

  • Committer: Paul Larson
  • Date: 2013-08-19 18:56:07 UTC
  • Revision ID: paul.larson@canonical.com-20130819185607-tpcrtnx2tenmhxgi
Use top instead of vmstat and always output toplot

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
cleanup () {
11
11
  if ! test "$dump_error" = 0; then
12
 
    echo "System failed to settle to target idle level ($idle_avg_min)"
13
 
    echo "   + check out the following top log taken at each retry:"
 
12
    echo "Check out the following top log taken at each retry:"
14
13
 
 
14
    echo
15
15
    # dumb toplog indented
16
16
    while read line; do
17
17
      echo "  $line"
18
18
    done < $top_log
19
 
 
20
 
    echo
21
19
    # dont rerun this logic in case we get multiple signals
22
20
    dump_error=0
23
21
  fi
24
 
  rm -f $top_log $vmstat_log $vmstat_log.reduced
 
22
  rm -f $top_log $top_log.reduced
25
23
}
26
24
 
27
25
function show_usage() {
30
28
   echo "Options:"
31
29
   echo " -r  run forever without exiting"
32
30
   echo " -p  minimum idle percent to wait for (Default: 99)"
33
 
   echo " -c  number of times to run vmstat at each iteration (Default: 10)"
34
 
   echo " -d  seconds to delay between each vmstat iteration (Default: 6)"
35
 
   echo " -i  vmstat measurements to ignore from each loop (Default: 1)"
36
 
   echo " -m  maximum loops of vmstat before giving up if minimum idle"
 
31
   echo " -c  number of times to run top at each iteration (Default: 10)"
 
32
   echo " -d  seconds to delay between each top iteration (Default: 6)"
 
33
   echo " -i  top measurements to ignore from each loop (Default: 1)"
 
34
   echo " -m  maximum loops of top before giving up if minimum idle"
37
35
   echo "     percent is not reached (Default: 10)"
38
36
   exit 129
39
37
}
46
44
              ;;
47
45
        p)    idle_avg_min=$OPTARG
48
46
              ;;
49
 
        c)    vmstat_repeat=$OPTARG
50
 
              ;;
51
 
        d)    vmstat_wait=$OPTARG
52
 
              ;;
53
 
        i)    vmstat_ignore=$OPTARG
 
47
        c)    top_repeat=$OPTARG
 
48
              ;;
 
49
        d)    top_wait=$OPTARG
 
50
              ;;
 
51
        i)    top_ignore=$OPTARG
54
52
              ;;
55
53
        m)    settle_max=$OPTARG
56
54
              ;;
59
57
 
60
58
# minimum average idle level required to succeed
61
59
idle_avg_min=${idle_avg_min:-99}
62
 
# measurement details: vmstat $vmstat_wait $vmstat_repeat
63
 
vmstat_repeat=${vmstat_repeat:-10}
64
 
vmstat_wait=${vmstat_wait:-6}
 
60
# measurement details: top $top_wait $top_repeat
 
61
top_repeat=${top_repeat:-10}
 
62
top_wait=${top_wait:-6}
65
63
# how many samples to ignore
66
 
vmstat_ignore=${vmstat_ignore:-1}
 
64
top_ignore=${top_ignore:-1}
67
65
# how many total attempts to settle the system
68
66
settle_max=${settle_max:-10}
69
67
 
70
68
# set and calc more runtime values
71
 
vmstat_tail=`calc $vmstat_repeat - $vmstat_ignore`
 
69
top_tail=`calc $top_repeat - $top_ignore`
72
70
settle_count=0
73
71
idle_avg=0
74
72
 
75
73
echo "System Settle run - quiesce the system"
76
74
echo "--------------------------------------"
77
75
echo
78
 
echo "  + cmd: \'vmstat $vmstat_wait $vmstat_repeat\' ignoring first $vmstat_ignore (tail: $vmstat_tail)"
 
76
echo "  idle_avg_min   = '$idle_avg_min'"
 
77
echo "  top_repeat  = '$top_repeat'"
 
78
echo "  top_wait    = '$top_wait'"
 
79
echo "  top_ignore  = '$top_ignore'"
 
80
echo "  settle_max     = '$settle_max'"
 
81
echo "  run_forever    = '$settle_prefix' (- = yes)"
79
82
echo
80
83
 
81
84
trap cleanup EXIT INT QUIT ILL KILL SEGV TERM
82
 
vmstat_log=`mktemp -t`
83
85
top_log=`mktemp -t`
84
86
 
85
87
while test `calc $idle_avg '<' $idle_avg_min` = 1 -a "$settle_prefix$settle_count" -lt "$settle_max"; do
86
 
  echo Starting settle run $settle_count:
87
 
 
88
 
  # get vmstat
89
 
  vmstat $vmstat_wait $vmstat_repeat | tee $vmstat_log
90
 
  cat $vmstat_log | tail -n $vmstat_tail > $vmstat_log.reduced
91
 
 
92
 
  # log top output for potential debugging
 
88
  echo -n "Starting system idle measurement (run: $settle_count) ... "
 
89
 
 
90
  # get top
93
91
  echo "TOP DUMP (after settle run: $settle_count)" >> $top_log
94
92
  echo "========================" >> $top_log
95
 
  top -n 1 -b >> $top_log
 
93
  top -b -d $top_wait -n $top_repeat >> $top_log
 
94
  cat $top_log | grep '.Cpu.*' | tail -n $top_tail > $top_log.reduced
96
95
  echo >> $top_log
97
96
 
98
97
  # calc average of idle field for this measurement
99
98
  sum=0
100
99
  count=0
101
100
  while read line; do
102
 
     idle=`echo $line | sed -e 's/\s\s*/ /g' | cut -d ' ' -f 15`
 
101
     idle=`echo $line | sed -e 's/.* \([0-9\.]*\) id.*/\1/'`
103
102
     sum=`calc $sum + $idle`
104
103
     count=`calc $count + 1`
105
 
  done < $vmstat_log.reduced
 
104
  done < $top_log.reduced
106
105
 
107
 
  idle_avg=`calc $sum.0 / $count.0`
 
106
  idle_avg=`calc $sum / $count`
108
107
  settle_count=`calc $settle_count + 1`
109
108
 
 
109
  echo " DONE."
110
110
  echo
111
111
  echo "Measurement:"
112
112
  echo "  + idle level: $idle_avg"
119
119
  exit 1
120
120
else
121
121
  echo "system settled. SUCCESS"
122
 
  dump_error=0
123
122
  exit 0
124
123
fi
125
124