File: 412

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (242 lines) | stat: -rwxr-xr-x 5,602 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#! /bin/sh
# PCP QA Test No. 412
# Test out wrapping on libpcp/interp
#
#  Test the creation and reading of an archive created using pmlogger(1) and
#  and pmval(1).
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

signal=$PCP_BINADM_DIR/pmsignal
status=1	# failure is the default!
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

_wrap_off()
{
    dowrap=0
    unset PCP_COUNTER_WRAP
    echo "--- Wrapping OFF ---"
}

_wrap_on()
{
    dowrap=1
    PCP_COUNTER_WRAP=
    export PCP_COUNTER_WRAP
    echo "--- Wrapping ON ---"
}

_setTimeZone () {
    MONTH=`date +%m`
    
    if [ $MONTH -lt 7 ]
    then
    	#  Daylight savings on from Sunday 1st January to
    	#  Sunday 5th March
        TZ="EST-10EDT-11,1/0,64/3"
    else
    	#  Daylight savings on from Sunday 29th October to Wednesday
    	#  "32nd" December (including the end of the extra day for
    	#  leap years)
    	TZ="EST-10EDT-11,302/2,367/0"
    fi
    
    #  This is what the specification should be normally, but
    #  it won't work because the start date of daylight savings
    #  is AFTER the end date.  libc.so hates this, so I hate
    #  libc.so.
    #TZ="EST-10EDT-11,302/2,64/3"
    
    echo $TZ
}

#
# Reset the sample agent so that we start from a known
# point for the wrap metrics
#
_reset()
{
    pmstore sample.control -1 >/dev/null
    $sudo $signal -a -s HUP pmcd
    _wait_for_pmcd || _exit 1
}

#
# Simulate interpolated fetching with/without wrapping
# Assumes doing it for sample.wrap.ulong
#
_process_log()
{
    rm -f $tmp.dbg
    # t is reporting time in seconds
    #
    t=`echo $starttime | sed -e 's/.*://'`
    sed <$tmp.dump \
	-e '/^[0-9]/{
s/[0-9][0-9]* metrics*//
N
s/\n/ /
}' \
    | $PCP_AWK_PROG -v dowrap=$dowrap -v half_delta=$half_delta -v t=$t '
      BEGIN {
	    maxuint = 4294967295
	    debug = 0
	    # get to same starting time as -O $half_time used for pmval
	    #
	    t += half_delta
      }
      $2 == "29.0.58" { 
	    next_time = $1
	    next_value = $5
	    gsub(/^.*:/, "", next_time)
	    if (prev_time != 0) {
		if (next_time < prev_time) next_time += 60
		delta = next_time - prev_time
		if (debug) {
		    printf("time t=%s;delta=%s;next=%s;prev=%s\n", t, delta, next_time, prev_time) >"'$tmp.dbg'"
		    printf("value next=%s;prev=%d\n", next_value, prev_value) >"'$tmp.dbg'"
		}

		# note ... cannot do arithmetic here bacause of precision
		#	issues on some platforms (especialy *BSD) where
		#	integer arithmetic in awk tops out at 32-bits,
		#	so defer to bc(1)
		#
		if (next_value < prev_value && dowrap) { # then wrap
		    system("echo \"(" prev_value "+(" next_value "+" maxuint "-" prev_value ")*(" t "-" prev_time ")/" delta ") % " maxuint "\" | bc")
		    if (debug)
			printf("dowrap\n") >"'$tmp.dbg'"
		}
		else {
		    system("echo \"" prev_value "+(" next_value "-" prev_value ")*(" t "-" prev_time ")/" delta "\" | bc")
		}

		# increment the same as -t $delta for pmval
		#
		t += half_delta + half_delta
	    }
	    prev_time = next_time
	    prev_value = next_value
      }
    '
    if [ -f $tmp.dbg ]
    then
	cat $tmp.dbg >>$seq_full
	rm -f $tmp.dbg
    fi
}

#
# Note the time of the first sample.wrap value
#
_set_starttime()
{
    $PCP_AWK_PROG <$tmp.dump '
BEGIN		{ stamp = 0 }
/^[0-9]/	{ stamp = $1; next }
$1 == "29.0.58" { printf("%s\n", stamp); exit 0; }'
}

#
# Get out the interp values using pmval
#
_pmval_log()
{
    echo >>$seq_full
    echo "--- pmval -S@$starttime -O $half_delta ---" >>$seq_full
    #debug debug=-Dinterp,fetch
    pmval $debug -w 15 -f 0 -r -a $tmp.archive -S "@$starttime" -O $half_delta -t $delta 2>$tmp.err \
      sample.wrap.ulong \
    | tee -a $seq_full \
    | sed \
	-e '/metric/,/interval/d' \
	-e '/^[ 	]*$/d' \
	-e 's/^[^ ][^ ]*  *//'
    cat $tmp.err >>$seq_full
}

#
# Compare values allowing for an error
#
_compare_results()
{
    echo >>$seq_full
    echo "--- paste ---" >>$seq_full
    # imprecision is in floating point arithmetic where the time
    # stamp precision from pmdumplog is much less than then precision
    # used in interp.c within libpcp
    # the values are O(10) digits, and expect the first 5 of these to
    # be correct, so error should be less than 100,000
    #
    error=100000
    paste $tmp.1 $tmp.2 \
    | tee -a $seq_full \
    | $PCP_AWK_PROG -v error=$error ' {
	    diff = $1-$2; 
	    if (diff < 0) diff *= -1; 
	    if (diff > error) 
		printf("mismatch: %f, %f (diff=%f)\n", $1, $2, diff);
	    else
		printf("match\n");
    }'
}


# real QA test starts here

delta=2
half_delta=1

_reset
cat <<EOF >$tmp.config
log advisory on $delta second {
    sample.wrap.ulong
} 
EOF
pmlogger -c $tmp.config -s5 -l$tmp.log $tmp.archive
if [ $? -ne 0 ]
then
    echo "Archive failed to be created !"
    cat $tmp.log
    exit 1
    fi
pmdumplog $tmp.archive >$tmp.dump
echo >>$seq_full
echo "--- pmdumplog ---" >>$seq_full
cat $tmp.dump >>$seq_full
starttime=`_set_starttime`

_wrap_off
_process_log >$tmp.1
echo >>$seq_full
echo "--- process_log wrap_off ---" >>$seq_full
cat $tmp.1 >>$seq_full
_pmval_log >$tmp.2
echo >>$seq_full
echo "--- process pmval ---" >>$seq_full
cat $tmp.2 >>$seq_full
_compare_results

_wrap_on
_process_log >$tmp.1
echo >>$seq_full
echo "--- process_log wrap_on ---" >>$seq_full
cat $tmp.1 >>$seq_full
_pmval_log >$tmp.2
echo >>$seq_full
echo "--- process pmval ---" >>$seq_full
cat $tmp.2 >>$seq_full
_compare_results

# success, all done
status=0
exit