This file is indexed.

/var/lib/pcp/testsuite/src/grind-tools is in pcp-testsuite 3.9.10.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/bin/sh

_usage()
{
    echo "Usage: $0 [-v] [-a archive] [-h host] metricspec [...]"
    echo
    echo "metricspec one of the forms:"
    echo "    metric-name"
    echo "    metric-name[instance]"
    exit 1
}

# Get standard environment
. $PCP_DIR/etc/pcp.env

status=0
tmp=/tmp/$$
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
rm -f $tmp.*

verbose=false
very_verbose=false
host=localhost
archive=""
while getopts "a:h:v" c
do
    case "$c"
    in
	a)
	    src="-a $OPTARG"
	    archive=$OPTARG
	    host=""
	    ;;
	h)
	    src="-h $OPTARG"
	    archive=""
	    host=$OPTARG
	    ;;
	v)
	    $verbose && very_verbose=true
	    verbose=true
	    ;;
	*)
	    _usage
	    # NOTREACHED
	    ;;
    esac
done
shift `expr $OPTIND - 1`

if [ $# -lt 1 ]
then
    _usage
    # NOTREACHHED
fi

for arg
do
    case "$arg"
    in
	*[*)
	    echo "$arg" >>$tmp.all
	    ;;
	*)
	    pmprobe -I $src $arg \
	    | sed  \
		-e 's/ "/ /' \
		-e 's/" "/ /g' \
		-e 's/"$//' \
		-e 's/ /\
/g' \
	    | sed -e '1,2d' \
	    | while read inst
	    do
		echo "$arg[$inst]" >>$tmp.all
	    done
	    ;;
    esac
done

sed <$tmp.all -e 's/\[.*//' \
| sort -u >$tmp.metrics

# cat $tmp.metrics
# echo
# cat $tmp.all

# pmie
#
sed <$tmp.all >$tmp.config \
    -e "s/\[/ #'/" \
    -e "s/]/'/" \
    -e 's/$/+/' \
    -e '$s/$/1;/'
$very_verbose && echo "pmie config ..." && cat $tmp.config
if pmie $src -c $tmp.config -C
then
    $verbose && echo "pmie OK"
else
    echo "pmie FAILED"
    echo "pmie config:"
    cat $tmp.config
    status=1
fi

# pmval
#
sed -e 's/]//' -e 's/\[/ /' <$tmp.all \
    | $PCP_AWK_PROG '
BEGIN		{ printf "pmval -s 2 -t 1sec '"$src"' -i " }
$1 != metric	{ if (NR > 1) {
		    print " " metric
		    printf "pmval -s 2 -t 1sec '"$src"' -i "
		  }
		  metric = $1
		}
NR > 1		{ printf "," }
		{ printf $2 }
END		{ print " " metric
		}' \
| sed -e "s/-i /-i '/" -e "s/ [^ ]*\$/'&/" >$tmp.config
$very_verbose && echo "pmval cmd ..." && cat $tmp.config
cat $tmp.config | sh >$tmp.out 2>&1
if grep '^samples: *2$' $tmp.out >/dev/null
then
    $verbose && echo "pmval OK"
else
    echo "pmval FAILED"
    echo "pmval cmd:"
    cat $tmp.config
    cat $tmp.out
    status=1
fi

# pmlogger
#
if [ -z "$host" ]
then
    echo "pmlogger skipped, source is an archive"
else
    echo "log mandatory on default {" >$tmp.config
    sed -e 's/]//' -e 's/\[/ /' <$tmp.all \
    | $PCP_AWK_PROG >>$tmp.config '
$1 != metric	{ if (NR > 1) print " ]"
		  print $1," ["
		  metric = $1
		}
		{ print "  \"" $2 "\"" }
END		{ print " ]"
		  print "}"
		}'
    $very_verbose && echo "pmlogger config ..." && cat $tmp.config
    if pmlogger -l $tmp.log $src -s 2 -t 1sec -c $tmp.config $tmp
    then
	$verbose && echo "pmlogger OK"
	archive=$tmp
    else
	echo "pmlogger FAILED"
	cat $tmp.log
	echo "pmlogger config:"
	cat $tmp.config
	status=1
    fi
fi

# pmdumptext - simple with -a or -h
#
if which pmdumptext >/dev/null 2>&1
then
    sed -e 's/]//' -e 's/\[/ /' <$tmp.all \
	    | $PCP_AWK_PROG '
BEGIN		{ printf "pmdumptext -s 2 -t 1sec '"$src"'" }
$1 != metric	{ if (NR > 1) {
		    print "]"
		    printf "pmdumptext -s 2 -t 1sec '"$src"'"
		  }
		  metric = $1
		  printf " %s[",metric
		  first = 1
		}
		{ if (first) {
		    printf "%s",$2
		    first = 0
		  }
		  else
		    printf ",%s",$2
		}
END		{ print "]"
		    }' >$tmp.config
    $very_verbose && echo "pmdumptext cmd ..." && cat $tmp.config
    cat $tmp.config | sh >$tmp.out 2>&1
    ok=`grep '^[A-Z][a-z][a-z] [A-Z][a-z][a-z]' $tmp.out | wc -l | sed -e 's/ //g'`
    if [ "$ok" -eq 2 ]
    then
	    $verbose && echo "pmdumptext (simple) OK"
    else
	    echo "pmdumptext (simple) FAILED"
	    echo "pmdumptext cmd:"
	    cat $tmp.config
	    cat $tmp.out
	    status=1
    fi
else
    echo "pmdumptext skipped, no binary installed"
fi

# pmdumptext - extended notation ...
# myhost:kernel.all.cpu.idle[cpu0,cpu3]
# /path/to/myarchive/kernel.all.cpu.idle[cpu1]
#
if which pmdumptext >/dev/null 2>&1
then
    if [ -n "$host" ]
    then
	    pfx="$host:"
    else
	    pfx="$archive/"
    fi
    sed -e 's/]//' -e 's/\[/ /' <$tmp.all \
	    | $PCP_AWK_PROG '
BEGIN		{ printf "pmdumptext -s 2 -t 1sec" }
$1 != metric	{ metric = $1
		  first = 1
		  if (NR > 1) printf "]"
		}
		{ if (first) {
		    printf " %s%s[%s","'"$pfx"'",metric,$2
		    first = 0
		  }
		  else
		    printf ",%s",$2
		}
END		{ print "]" }' >$tmp.config
    $very_verbose && echo "pmdumptext cmd ..." && cat $tmp.config
    cat $tmp.config | sh >$tmp.out 2>&1
    ok=`grep '^[A-Z][a-z][a-z] [A-Z][a-z][a-z]' $tmp.out | wc -l | sed -e 's/ //g'`
    if [ "$ok" -eq 2 ]
    then
	    $verbose && echo "pmdumptext (extended) OK"
    else
	    echo "pmdumptext (extended) FAILED"
	    echo "pmdumptext cmd:"
	    cat $tmp.config
	    cat $tmp.out
	    status=1
    fi
fi

# pmchart
#
if which pmchart >/dev/null 2>&1
then
    echo "#pmchart" >$tmp.config
    echo "Version 2.0 host dynamic" >>$tmp.config
    echo "Chart Title "test" Style line" >>$tmp.config
    sed <$tmp.all >>$tmp.config \
	    -e 's/]//' \
	    -e 's/\[/ Instance /' \
	    -e 's/^/  Plot Color #-cycle Host * Metric /'
    $very_verbose && echo "pmchart config ..." && cat $tmp.config
    if pmchart -C -c $tmp.config $src
    then
	    $verbose && echo "pmchart OK"
    else
	    echo "pmchart FAILED"
	    echo "pmchart config:"
	    cat $tmp.config
	    status=1
    fi
else
    echo "pmchart skipped, no binary installed"
fi

# pmview
#
if which pmview >/dev/null 2>&1
then
    echo 'pmview Version 2.1 "foo" "bar"' >$tmp.config
    $PCP_AWK_PROG <$tmp.all >>$tmp.config '
BEGIN		{ printf "_colorlist l1 (" }
NR % 3 == 0	{ printf " red" }
NR % 3 == 1	{ printf " green" }
NR % 3 == 2	{ printf " blue" }
END		{ print " )" }'
    $PCP_AWK_PROG <$tmp.metrics >>$tmp.config '
BEGIN		{ printf "_colorlist l2 (" }
NR % 3 == 0	{ printf " red" }
NR % 3 == 1	{ printf " green" }
NR % 3 == 2	{ printf " blue" }
END		{ print " )" }'
    sed <$tmp.all \
	-e 's/]//' \
	-e 's/\[/ /' \
    | $PCP_AWK_PROG '
BEGIN	{ print "_grid ("
          print " _bar 0 0 ("
	  print "  _metrics ("
	}
	{ printf "   %s[%s] 10 \"%d\"\n",$1,$2,NR }
END	{ print "  )"
	  print "  _colorlist l1"
	  print " )"
	}' >>$tmp.config
    sed <$tmp.all \
	-e 's/]//' \
	-e 's/\[/ /' \
    | $PCP_AWK_PROG '
BEGIN	{ print " _bar 1 0 ("
	  print "  _metrics ("
	}
$1 != metric	{ if (NR > 1) {
		    printf "] 100 \"%d\"\n",NR
		  }
		  metric = $1
		  printf "   %s[%s",$1,$2
		  next
		}
		{ printf ",%s",$2 }
END	{ printf "] 100 \"%d\"\n",NR
	  print "  )"
	  print "  _colorlist l2"
	  print " )"
	}' >>$tmp.config
    sed <$tmp.all \
	-e 's/]//' \
	-e 's/\[/ /' \
    | $PCP_AWK_PROG '
BEGIN	{ print " _stack 2 0 ("
	  print "  _metrics ("
	}
	{ printf "   %s[%s] 10\n",$1,$2 }
END	{ print "  )"
	  print "  _colorlist l1"
	  print " )"
	  print ")"
	}' >>$tmp.config
    $very_verbose && echo "pmview config ..." && cat $tmp.config
    if pmview -C -c $tmp.config $src
    then
	$verbose && echo "pmview OK"
    else
	echo "pmview FAILED"
	echo "pmview config:"
	cat $tmp.config
	status=1
    fi
else
    echo "pmview skipped, no binary installed"
fi

# pmgadgets
#
if which pmgadgets >/dev/null 2>&1
then
    if [ -z "$host" ]
    then
	echo "pmgadgets skipped, source is an archive"
    else
	cat <<End-of-File >$tmp.config
pmgadgets 1 "foo" "bar"
_legend l (
  _default green3
  10 yellow
)
End-of-File
	sed <$tmp.all \
	    -e 's/]//' \
	    -e 's/\[/ /' \
	| $PCP_AWK_PROG '
	    { printf "_led 10 %d 5 5\n",10*NR
	      printf "  _metric %s[\"%s\"]\n",$1,$2
	      printf "  _legend l\n"
	    }' >>$tmp.config
	$very_verbose && echo "pmgadgets config ..." && cat $tmp.config
	if pmgadgets -C -c $tmp.config $src
	then
	    $verbose && echo "pmgadgets OK"
	else
	    echo "pmgadgets FAILED"
	    echo "pmgadgets config:"
	    cat $tmp.config
	    status=1
	fi
    fi
else
    echo "pmgadgets skipped, no binary installed"
fi