#!/bin/sh
# PCP QA Test No. 1171
# Exercise the BCC PMDA profile module - install, remove and values.
#
# Copyright (c) 2018 Andreas Gerstmayr.
#

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

. ./common.bcc

_pmdabcc_check
_pmdabcc_require_kernel_version 4 9

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

_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 = profile
prefix = bcc.
[profile]
module = profile
cluster = 14
EOF
_pmdabcc_wait_for_metric

echo "=== start profiling ==="
pmstore bcc.proc.profile start
for i in `seq 1 10`; do pminfo -f bcc.proc.profile | grep started > /dev/null && break; sleep 1; done
if [ $i -ge 10 ]; then
    echo Could not start profiling, test failed
    exit
fi

echo
echo "=== start test program ==="
src/bcc_profile 5

echo
echo "=== stop profiling ==="
pmstore bcc.proc.profile stop
for i in `seq 1 10`; do pminfo -f bcc.proc.profile | grep stopped > /dev/null && break; sleep 1; done
if [ $i -ge 10 ]; then
    echo Could not stop profiling, test failed
    exit
fi

echo
echo "=== verify captured stack frames ==="
pminfo -f bcc.proc.profile | grep bcc_profile > /dev/null && echo 'OK'

_pmdabcc_remove

status=0
exit
