#!/bin/sh
# PCP QA Test No. 1168
# Exercise the pmrep with newly appearing BCC PMDA klockstat metrics.
#
# Copyright (c) 2019 Red Hat.
#

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

. ./common.bcc

_pmdabcc_check
_pmdabcc_require_kernel_version 4 7

status=1       # failure is the default!
signal=$PCP_BINADM_DIR/pmsignal
$sudo rm -rf $tmp.* $seq.full

_instance_filter()
{
    sed \
	-e 's/[0-9]//g' \
	-e 's/".*"/"inst"/g' \
	-e 's/\[  /\[ /' \
    #end
}

_prepare_pmda bcc
trap "_pmdabcc_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd

# real QA test starts here
cat <<EOF | _pmdabcc_install
# Installed by PCP QA test $seq on `date`
[pmda]
modules = klockstat
prefix = bcc.
[klockstat]
module = klockstat
cluster = 31
process = pmcd
EOF
_service pmcd restart
pmsleep 5

echo "=== pmrep output ==="
pmrep -g -r -1 -s 1 bcc.kernel.lock.mutex.spin.avg 2>&1 | tee -a $here/$seq.full \
| grep bcc.kernel.lock.mutex.spin.avg | _instance_filter | sort | uniq

_pmdabcc_remove

status=0
exit
