#!/bin/bash
# This script tells autobench to not use a particular profiler (when a 
# benchmark runs the important section).  If no use/disuseprofiler command are 
# issued, the default set of profilers (readprofile, sar, lockmeter) are used.
#
# reqparam value command - the name of the command to start/stop/install the profiler
#

. /etc/autobench.conf || . functions

if [ $# -lt 1 ]; then
  echo "You must specify a command to execute the profiler"
  exit 1
fi

getcommand startprofilers
getcommand stopprofilers

# call this script recursively when more than one argument
# is given to it.  
if [ $# -gt 1 ]; then
	for i in $*; do 
		"$0" "$i";
	done;
	exit;
fi;


# Remove it from the list of profilers
if [ -e $TMPDIR/profilers ]; then
  cat $TMPDIR/profilers | grep -v $1 > $TMPDIR/profilers.new
  rm $TMPDIR/profilers
  mv $TMPDIR/profilers.new $TMPDIR/profilers
fi


# Remove it to the start & stop profilers script
cat $AUTODIR/scripts/startprofilers | grep -v "# $1$" > $TMPDIR/startprofilers.new
rm $AUTODIR/scripts/startprofilers
mv $TMPDIR/startprofilers.new $AUTODIR/scripts/startprofilers
chmod a+x $AUTODIR/scripts/startprofilers

cat $AUTODIR/scripts/stopprofilers | grep -v "# $1$" > $TMPDIR/stopprofilers.new
rm $AUTODIR/scripts/stopprofilers
mv $TMPDIR/stopprofilers.new $AUTODIR/scripts/stopprofilers
chmod a+x $AUTODIR/scripts/stopprofilers
