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"
29
echo " -s sleep timeout for %cpu calculation (Default: 10)"
33
while getopts "h?rp:c:d:i:m:l:s:" opt; do
39
p) idle_avg_min=$OPTARG
49
l) top_log_label=$OPTARG
56
sleep_len=${sleep_len:-10}
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}
68
top_log="$UTAH_PROBE_DIR/top$top_log_label.log"
70
# set and calc more runtime values
71
top_tail=`calc $top_repeat - $top_ignore`
75
echo "System Settle run - quiesce the system"
76
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"
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) ... "
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
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
100
${TARGET_PREFIX} cat /proc/stat
102
${TARGET_PREFIX} cat /proc/stat
105
/^cpu / { iter = iter + 1; count = 0; next }
106
/^cpu/ { S[iter] = S[iter] + ($2+$3+$4+$6); count = count + 1;
108
END { print (S[2] - S[1]) * 100 / ('"$HZ"' * count * '"$sleep_len"') }
110
idle_avg=`calc 100 - $cpu_avg`
111
settle_count=`calc $settle_count + 1`
116
echo " + idle level: $idle_avg"
120
if test `calc $idle_avg '<' $idle_avg_min` = 1; then
121
echo "system not settled. FAIL"
124
echo "system settled. SUCCESS"