pmrep: fix archive end time reporting
[pcp.git] / qa / 412
blobf6602137f8c159c808a50da758200eb19ad49e48
1 #! /bin/sh
2 # PCP QA Test No. 412
3 # Test out wrapping on libpcp/interp
5 # Test the creation and reading of an archive created using pmlogger(1) and
6 # and pmval(1).
8 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
11 seq=`basename $0`
12 echo "QA output created by $seq"
14 # get standard environment, filters and checks
15 . ./common.product
16 . ./common.filter
17 . ./common.check
19 signal=$PCP_BINADM_DIR/pmsignal
20 status=1 # failure is the default!
21 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
23 _wrap_off()
25 dowrap=0
26 unset PCP_COUNTER_WRAP
27 echo "--- Wrapping OFF ---"
30 _wrap_on()
32 dowrap=1
33 PCP_COUNTER_WRAP=
34 export PCP_COUNTER_WRAP
35 echo "--- Wrapping ON ---"
38 _setTimeZone () {
39 MONTH=`date +%m`
41 if [ $MONTH -lt 7 ]
42 then
43 # Daylight savings on from Sunday 1st January to
44 # Sunday 5th March
45 TZ="EST-10EDT-11,1/0,64/3"
46 else
47 # Daylight savings on from Sunday 29th October to Wednesday
48 # "32nd" December (including the end of the extra day for
49 # leap years)
50 TZ="EST-10EDT-11,302/2,367/0"
53 # This is what the specification should be normally, but
54 # it won't work because the start date of daylight savings
55 # is AFTER the end date. libc.so hates this, so I hate
56 # libc.so.
57 #TZ="EST-10EDT-11,302/2,64/3"
59 echo $TZ
63 # Reset the sample agent so that we start from a known
64 # point for the wrap metrics
66 _reset()
68 pmstore sample.control -1 >/dev/null
69 $sudo $signal -a -s HUP pmcd
70 _wait_for_pmcd
74 # Simulate interpolated fetching with/without wrapping
75 # Assumes doing it for sample.wrap.ulong
77 _process_log()
79 $PCP_AWK_PROG -v dowrap=$dowrap -v half_delta=$half_delta '
80 BEGIN {
81 maxuint = 4294967295;
82 debug=0
84 $2 == "29.0.58" {
85 curr_time = $1;
86 curr_value = $5;
87 gsub(/^.*:/, "", curr_time);
88 if (prev_time != 0) {
89 delta = curr_time - prev_time;
90 if (delta < 0) delta += 60; # delta wrap :-)
91 if (debug)
92 printf("delta=%s;curr=%s;prev=%s\n", delta, curr_time, prev_time);
94 #x = (prev_value + curr_value) / 2.0
95 x = (curr_value - prev_value) / delta * half_delta;
96 x += prev_value;
98 if (curr_value < prev_value && dowrap) { # then wrap
99 new_curr_value = curr_value + maxuint;
101 x = (new_curr_value - prev_value) / delta * half_delta;
102 x += prev_value;
104 if (x > maxuint) x -= maxuint; # wrap back if necessary
106 printf "%15.0d\n",x;
108 prev_time = curr_time;
109 prev_value = curr_value;
111 ' <$tmp.dump
115 # Note the time of the first sample.wrap value
117 _set_starttime()
119 $PCP_AWK_PROG '
120 $2 == "29.0.58" {
121 printf("starttime=%s\n", $1);
122 exit 0;
124 ' <$tmp.dump >$tmp.starttime
125 eval `cat $tmp.starttime`
129 # Get out the interp values using pmval
131 _pmval_log()
133 echo >>$seq.full
134 echo "--- pmval ---" >>$seq.full
135 pmval -w 15 -f 0 -r -a $tmp.archive -S "@$starttime" -O $half_delta -t $delta \
136 sample.wrap.ulong \
137 | tee -a $seq.full \
138 | sed \
139 -e '/metric/,/interval/d' \
140 -e '/^[ ]*$/d' \
141 -e 's/^[^ ][^ ]* *//'
145 # Compare values allowing for an error
147 _compare_results()
149 echo >>$seq.full
150 echo "--- paste ---" >>$seq.full
151 error=1e+08
152 paste $tmp.1 $tmp.2 \
153 | tee -a $seq.full \
154 | $PCP_AWK_PROG -v error=$error ' {
155 diff = $1-$2;
156 if (diff < 0) diff *= -1;
157 if (diff > error)
158 printf("mismatch: %f, %f (diff=%f)\n", $1, $2, diff);
159 else
160 printf("match\n");
164 rm -f $seq.full
166 # real QA test starts here
168 delta=2
169 half_delta=1
171 _reset
172 cat <<EOF >$tmp.config
173 log advisory on $delta second {
174 sample.wrap.ulong
177 pmlogger -c $tmp.config -s5 -l$tmp.log $tmp.archive
178 if [ $? -ne 0 ]
179 then
180 echo "Archive failed to be created !"
181 cat $tmp.log
182 exit 1
184 pmdumplog $tmp.archive >$tmp.dump
185 echo >>$seq.full
186 echo "--- pmdumplog ---" >>$seq.full
187 cat $tmp.dump >>$seq.full
188 _set_starttime
190 _wrap_off
191 _process_log >$tmp.1
192 echo >>$seq.full
193 echo "--- process_log wrap_off ---" >>$seq.full
194 cat $tmp.1 >>$seq.full
195 _pmval_log >$tmp.2
196 echo >>$seq.full
197 echo "--- process pmval ---" >>$seq.full
198 cat $tmp.2 >>$seq.full
199 _compare_results
201 _wrap_on
202 _process_log >$tmp.1
203 echo >>$seq.full
204 echo "--- process_log wrap_on ---" >>$seq.full
205 cat $tmp.1 >>$seq.full
206 _pmval_log >$tmp.2
207 echo >>$seq.full
208 echo "--- process pmval ---" >>$seq.full
209 cat $tmp.2 >>$seq.full
210 _compare_results
212 # success, all done
213 status=0
214 exit