#!/bin/sh
# PCP QA Test No. 1179
# Exercise the BCC PMDA ustat module - install, remove and values.
#
# Copyright (c) 2018-2019 Red Hat.
#

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

. ./common.bcc
_pmdabcc_check
_pmdabcc_require_kernel_version 4 7
_java_check

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

_prepare_pmda bcc
trap "\$signal -s KILL \$javapid > /dev/null 2>&1; _pmdabcc_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd

# Launch a Java test program
cd $here/java
java -XX:+DTraceAllocProbes -XX:+ExtendedDTraceProbes USDTJVMTest &
javapid=$!
disown > /dev/null 2>&1 || :
cd $here

# real QA test starts here
cat <<EOF | _pmdabcc_install | _pmdabcc_install_filter
# Installed by PCP QA test $seq on `date`
[pmda]
modules = ustat
prefix = bcc.
[ustat]
module = ustat
cluster = 17
process = java
language = java
EOF
_pmdabcc_wait_for_metric

# Wait for values to appear
pmsleep 1

echo "=== report metric values for object creation ==="
pminfo -dfmtT bcc.proc.ustat.object 2>&1 | tee -a $here/$seq.full \
| grep $javapid\" | _value_filter_nonzero

echo "=== report metric values for method calls ==="
pminfo -dfmtT bcc.proc.ustat.method 2>&1 | tee -a $here/$seq.full \
| grep $javapid\" | _value_filter_nonzero

echo "=== report metric values for threads started ==="
pminfo -dfmtT bcc.proc.ustat.thread 2>&1 | tee -a $here/$seq.full \
| grep $javapid\" | _value_filter_nonzero

$signal -s KILL $javapid > /dev/null 2>&1
_pmdabcc_remove 2>&1

status=0
exit
