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
10
[ -z $UTAH_PROBE_DIR ] && UTAH_PROBE_DIR="/tmp"
12
# default exit code storage
15
calc () { awk "BEGIN{ print $* }" ;}
17
function show_usage() {
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"
32
while getopts "h?rp:c:d:i:m:l:" opt; do
38
p) idle_avg_min=$OPTARG
48
l) top_log_label=$OPTARG
53
# minimum average idle level required to succeed
54
idle_avg_min=${idle_avg_min:-99}
55
# measurement details: top $top_wait $top_repeat
56
top_repeat=${top_repeat:-10}
57
top_wait=${top_wait:-6}
58
# how many samples to ignore
59
top_ignore=${top_ignore:-1}
60
# how many total attempts to settle the system
61
settle_max=${settle_max:-10}
63
top_log="$UTAH_PROBE_DIR/top$top_log_label.log"
65
# set and calc more runtime values
66
top_tail=`calc $top_repeat - $top_ignore`
70
echo "System Settle run - quiesce the system"
71
echo "--------------------------------------"
73
echo " idle_avg_min = '$idle_avg_min'"
74
echo " top_repeat = '$top_repeat'"
75
echo " top_wait = '$top_wait'"
76
echo " top_ignore = '$top_ignore'"
77
echo " settle_max = '$settle_max'"
78
echo " run_forever = '$settle_prefix' (- = yes)"
79
echo " log files = $top_log $top_log.reduced"
82
while test `calc $idle_avg '<' $idle_avg_min` = 1 -a "$settle_prefix$settle_count" -lt "$settle_max"; do
83
echo -n "Starting system idle measurement (run: $settle_count) ... "
86
echo "TOP DUMP (after settle run: $settle_count)" >> $top_log
87
echo "========================" >> $top_log
88
${TARGET_PREFIX} top -b -d $top_wait -n $top_repeat >> $top_log
89
cat $top_log | grep '.Cpu.*' | tail -n $top_tail > $top_log.reduced
92
# calc average of idle field for this measurement
96
idle=`echo $line | sed -e 's/.* \([0-9\.]*\) id.*/\1/'`
97
sum=`calc $sum + $idle`
98
count=`calc $count + 1`
99
done < $top_log.reduced
101
idle_avg=`calc $sum / $count`
102
settle_count=`calc $settle_count + 1`
107
echo " + idle level: $idle_avg"
108
echo " + idle sum: $sum / count: $count"
112
if test `calc $idle_avg '<' $idle_avg_min` = 1; then
113
echo "system not settled. FAIL"
116
echo "system settled. SUCCESS"