~vila/ubuntu-test-cases/retry-apt-get-update

« back to all changes in this revision

Viewing changes to tests/systemsettle/systemsettle.sh

  • Committer: Leo Arias
  • Date: 2014-11-10 19:28:56 UTC
  • mfrom: (345 touch)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: leo.arias@canonical.com-20141110192856-rgpksx9n9j0b39yl
Merged with the touch branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
# Configuration variables:
 
4
#  TARGET_PREFIX - Allows this to be run from the host, by providings something
 
5
#                  like TARGET_PREFIX="adb shell"
 
6
#  UTAH_PROBE_DIR - optionally where to save log files so utah will grab them
 
7
 
 
8
set -e
 
9
 
 
10
[ -z $UTAH_PROBE_DIR ] && UTAH_PROBE_DIR="/tmp"
 
11
 
 
12
# default exit code storage
 
13
dump_error=1
 
14
 
 
15
calc () { awk "BEGIN{ print $* }" ;}
 
16
 
 
17
function show_usage() {
 
18
   echo "Usage:"
 
19
   echo " $0 [options]"
 
20
   echo "Options:"
 
21
   echo " -r  run forever without exiting"
 
22
   echo " -p  minimum idle percent to wait for (Default: 99)"
 
23
   echo " -c  number of times to run top at each iteration (Default: 10)"
 
24
   echo " -d  seconds to delay between each top iteration (Default: 6)"
 
25
   echo " -i  top measurements to ignore from each loop (Default: 1)"
 
26
   echo " -m  maximum loops of top before giving up if minimum idle"
 
27
   echo "     percent is not reached (Default: 10)"
 
28
   echo " -l  label to include for the top_log file"
 
29
   echo " -s  sleep timeout for %cpu calculation (Default: 10)"
 
30
   exit 129
 
31
}
 
32
 
 
33
while getopts "h?rp:c:d:i:m:l:s:" opt; do
 
34
    case "$opt" in
 
35
        h|\?) show_usage
 
36
              ;;
 
37
        r)    settle_prefix='-'
 
38
              ;;
 
39
        p)    idle_avg_min=$OPTARG
 
40
              ;;
 
41
        c)    top_repeat=$OPTARG
 
42
              ;;
 
43
        d)    top_wait=$OPTARG
 
44
              ;;
 
45
        i)    top_ignore=$OPTARG
 
46
              ;;
 
47
        m)    settle_max=$OPTARG
 
48
              ;;
 
49
        l)    top_log_label=$OPTARG
 
50
              ;;
 
51
        s)    sleep_len=$OPTARG
 
52
              ;;
 
53
    esac
 
54
done
 
55
 
 
56
sleep_len=${sleep_len:-10}
 
57
HZ=`getconf CLK_TCK`
 
58
# minimum average idle level required to succeed
 
59
idle_avg_min=${idle_avg_min:-99}
 
60
# measurement details: top $top_wait $top_repeat
 
61
top_repeat=${top_repeat:-10}
 
62
top_wait=${top_wait:-6}
 
63
# how many samples to ignore
 
64
top_ignore=${top_ignore:-1}
 
65
# how many total attempts to settle the system
 
66
settle_max=${settle_max:-10}
 
67
 
 
68
top_log="$UTAH_PROBE_DIR/top$top_log_label.log"
 
69
 
 
70
# set and calc more runtime values
 
71
top_tail=`calc $top_repeat - $top_ignore`
 
72
settle_count=0
 
73
idle_avg=0
 
74
 
 
75
echo "System Settle run - quiesce the system"
 
76
echo "--------------------------------------"
 
77
echo
 
78
echo "  idle_avg_min   = '$idle_avg_min'"
 
79
echo "  top_repeat  = '$top_repeat'"
 
80
echo "  top_wait    = '$top_wait'"
 
81
echo "  top_ignore  = '$top_ignore'"
 
82
echo "  settle_max     = '$settle_max'"
 
83
echo "  run_forever    = '$settle_prefix' (- = yes)"
 
84
echo "  log files   = $top_log $top_log.reduced"
 
85
echo
 
86
 
 
87
while test `calc $idle_avg '<' $idle_avg_min` = 1 -a "$settle_prefix$settle_count" -lt "$settle_max"; do
 
88
  echo -n "Starting system idle measurement (run: $settle_count) ... "
 
89
 
 
90
  # get top
 
91
  echo "TOP DUMP (after settle run: $settle_count)" >> $top_log
 
92
  echo "========================" >> $top_log
 
93
  ${TARGET_PREFIX} COLUMNS=900 top -c -b -d $top_wait -n $top_repeat >> $top_log
 
94
  cat $top_log | grep '.Cpu.*' | tail -n $top_tail > $top_log.reduced
 
95
  echo >> $top_log
 
96
 
 
97
  # Instead of using top, we need to use /proc/stat and compensate for
 
98
  # the number of cpus and any frequency scaling that could be in effect
 
99
  cpu_avg=$({
 
100
    ${TARGET_PREFIX} cat /proc/stat
 
101
    sleep "$sleep_len"
 
102
    ${TARGET_PREFIX} cat /proc/stat
 
103
  } | awk '
 
104
    BEGIN       { iter = 0 }
 
105
    /^cpu /     { iter = iter + 1; count = 0; next }
 
106
    /^cpu/      { S[iter] = S[iter] + ($2+$3+$4+$6); count = count + 1;
 
107
next }
 
108
    END     { print (S[2] - S[1]) * 100 / ('"$HZ"' * count * '"$sleep_len"') }
 
109
  ')
 
110
  idle_avg=`calc 100 - $cpu_avg`
 
111
  settle_count=`calc $settle_count + 1`
 
112
 
 
113
  echo " DONE."
 
114
  echo
 
115
  echo "Measurement:"
 
116
  echo "  + idle level: $idle_avg"
 
117
  echo
 
118
done
 
119
 
 
120
if test `calc $idle_avg '<' $idle_avg_min` = 1; then
 
121
  echo "system not settled. FAIL"
 
122
  exit 1
 
123
else
 
124
  echo "system settled. SUCCESS"
 
125
  exit 0
 
126
fi
 
127