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:"
15
15
# dumb toplog indented
16
16
while read line; do
21
19
# dont rerun this logic in case we get multiple signals
24
rm -f $top_log $vmstat_log $vmstat_log.reduced
22
rm -f $top_log $top_log.reduced
27
25
function show_usage() {
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)"
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}
70
68
# set and calc more runtime values
71
vmstat_tail=`calc $vmstat_repeat - $vmstat_ignore`
69
top_tail=`calc $top_repeat - $top_ignore`
75
73
echo "System Settle run - quiesce the system"
76
74
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)"
81
84
trap cleanup EXIT INT QUIT ILL KILL SEGV TERM
82
vmstat_log=`mktemp -t`
83
85
top_log=`mktemp -t`
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:
89
vmstat $vmstat_wait $vmstat_repeat | tee $vmstat_log
90
cat $vmstat_log | tail -n $vmstat_tail > $vmstat_log.reduced
92
# log top output for potential debugging
88
echo -n "Starting system idle measurement (run: $settle_count) ... "
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
98
97
# calc average of idle field for this measurement
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
107
idle_avg=`calc $sum.0 / $count.0`
106
idle_avg=`calc $sum / $count`
108
107
settle_count=`calc $settle_count + 1`
111
111
echo "Measurement:"
112
112
echo " + idle level: $idle_avg"