#! /bin/sh
# PCP QA Test No. 419
# expand non-leaf names to pmdumplog
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

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

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

rm -f $seq.out
case $PCP_PLATFORM
in
    linux)
	ln $seq.$PCP_PLATFORM $seq.out || exit 1
	;;
    darwin|solaris|freebsd)
	# same output config for Mac OS X, OpenSolaris and FreeBSD
	ln $seq.darwin $seq.out || exit 1
	;;
    *)
	_notrun "Need qualified output for PCP_PLATFORM $PCP_PLATFORM"
	;;
esac

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

_filter()
{
    sed -n \
	-e '/No values/d' \
	-e '/):/{
s/):.*//
s/.*(//
p
}' \
    | LC_COLLATE=POSIX sort \
    | uniq -c \
    | sed -e 's/^[ 	][ 	]*/ /' \
    | $here/xlate_2_new_pmns
}

$sudo rm -f $tmp.0 $tmp.index $tmp.meta

if [ $PCP_PLATFORM = linux ]
then
    cat > $tmp.pmlogger.in <<End-of-File
log mandatory on default {
	kernel.all.load
	kernel.all.pswitch
	kernel.all.cpu.idle
	kernel.all.cpu.intr
	kernel.all.cpu.sys
	kernel.all.cpu.user
	kernel.all.cpu.wait.total
	disk.dev.read
	disk.dev.write
	disk.dev.total
	network.interface.in.bytes
	network.interface.out.bytes
}
End-of-File
elif [ $PCP_PLATFORM = darwin -o $PCP_PLATFORM = solaris -o $PCP_PLATFORM = freebsd ]
then
    # same pmlogger config for Mac OS X, OpenSolaris and FreeBSD
    cat > $tmp.pmlogger.in <<End-of-File
log mandatory on default {
	kernel.all.load
	kernel.all.cpu.idle
	kernel.all.cpu.sys
	kernel.all.cpu.user
	disk.dev.read
	disk.dev.write
	disk.dev.total
	network.interface.in.bytes
	network.interface.out.bytes
}
End-of-File
else
    echo "Arrgh ... need pmlogger config for $PCP_PLATFORM"
    exit 1
fi

pmlogger -t 2sec -T 5sec -l $tmp.log $tmp < $tmp.pmlogger.in

pmdumplog $tmp | _filter >$tmp.ref

cat $tmp.ref

# real QA test starts here
if [ $PCP_PLATFORM = linux ]
then
		for args in "kernel.all disk.dev network.interface.in network.interface.out" "kernel disk network" "kernel.all.load kernel.all.pswitch kernel.all.cpu.idle kernel.all.cpu.intr kernel.all.cpu.sys kernel.all.cpu.user kernel.all.cpu.wait.total disk.dev.read disk.dev.write disk.dev.total network.interface.in.bytes network.interface.out.bytes"
		do
			echo
			echo "=== $args ==="
			eval pmdumplog $tmp \
			pmcd.pmlogger.host pmcd.pmlogger.port pmcd.pmlogger.archive \
			pmcd.pid pmcd.seqnum $args \
			| _filter >$tmp.tmp
			cat $tmp.tmp
			diff $tmp.ref $tmp.tmp
		done
elif [ $PCP_PLATFORM = darwin -o $PCP_PLATFORM = solaris -o $PCP_PLATFORM = freebsd ]
then
		# same metrics for Mac OS X, OpenSolaris and FreeBSD
		for args in "kernel.all disk.dev network.interface.in network.interface.out" "kernel disk network" "kernel.all.load kernel.all.cpu.idle kernel.all.cpu.sys kernel.all.cpu.user disk.dev.read disk.dev.write disk.dev.total network.interface.in.bytes network.interface.out.bytes"
		do
			echo
			echo "=== $args ==="
			eval pmdumplog $tmp \
			pmcd.pmlogger.host pmcd.pmlogger.port pmcd.pmlogger.archive \
			pmcd.pid pmcd.seqnum $args \
			| _filter >$tmp.tmp
			cat $tmp.tmp
			diff $tmp.ref $tmp.tmp
		done
else
    echo "Arrgh ... need pmdumplog args for $PCP_PLATFORM"
    exit 1
fi

status=0
exit
