#!/bin/sh
# - delay
# - interval
# - count
# - nodes
# - cpus
# - per_node

. $LKP_SRC/lib/wait.sh
. $LKP_SRC/lib/common.sh
. $LKP_SRC/lib/env.sh

mpstat="/lkp/benchmarks/sysstat/usr/local/bin/mpstat"

[ -e $mpstat ] || {
	# rollback to the default mpstat
	has_cmd mpstat || exit
	mpstat="mpstat"
}

: ${interval:=1}

if parse_bool -q "$per_node"; then
	opt_node="-n"
	[ -n "$nodes" ] && opt_node="-N $nodes"
elif [ -n "$cpus" ]; then
	opt_cpu="-P $cpus"
fi

setup_wait

[ -n "$delay" ] && $WAIT_POST_TEST_CMD --timeout "$delay"

LC_ALL=C S_TIME_FORMAT=ISO $mpstat $opt_node $opt_cpu -o JSON $interval $count&

pid=$!

$WAIT_POST_TEST_CMD

pkill -INT mpstat
