#!/bin/bash
# Author: Enrique Gaona Jr.
#         IBM LTC Infrastructure
# Date:   08/19/2003
#
# reqparam value the directory to run the test in
# reqparam value the workfile name (workfile.aim9 workfile.all_utime workfile.compute workfile.custom workfile.dbase workfile.disk workfile.five_sec workfile.fserver workfile.high_systime workfile.long workfile.new_dbase workfile.new_fserver workfile.shared workfile.short workvile.very_long)
# optparam prefix "-v" Be verbose
# optparam prefix "-s" value The number of users to start with
# optparam prefix "-e" value The number of users to end with
# optparam prefix "-i" value The number of users to increment by
# optparam prefix "-c" Run to crossover (jpm/user < 1.0)
# optparam prefix "-q" Run to quick crossover (jpm/user < 60.0)
# optparam prefix "-t" Turns off adaptive timer
# optparam prefix "-j" value Number of jobs in tasklist
# optparam prefix "-m" Multiuser (default)
# optparam prefix "-o" Singluser
# optparam prefix "-p" value Number of seconds to run each test in singleuser mode
#

. /etc/autobench.conf || $AUTODIR/scripts/functions 

# Process the arguments.
if [ $# -lt 2 ]; then
  echo "At a minimum, you need to specify two arguments, "
  echo "the directory to the test in, and the workfile to use."
  exit 1
fi

# Install reaim if directory does not exist.
if [ ! \( -d $AUTODIR/sources/reaim -a \
          -x $AUTODIR/sources/reaim/src/reaim \) ]; then
  $AUTODIR/scripts/benchmarks/install/reaim
fi

# Figure out what type of filesystem we're running on.
WORK_DIR=`echo $1 | sed -e "s:/$::"` # Remove trailing /'s
FS_TYPE=`mount | grep $WORK_DIR | cut -f5 -d" "`

if [ -z "$FS_TYPE" ]; then
  log "WARNING: $WORK_DIR is not an isolated partition"
  #Figure out which FS the given directory is on...

  ROOT_TYPE=`mount | grep "/ " | cut -f5 -d" "`
  while [ -n "$WORK_DIR" ]; do
    FS_TYPE=`mount | grep "$WORK_DIR" | cut -f5 -d" "`
    if [ -n "$FS_TYPE" ]; then
      break  # We found it...
    fi
    FS_TYPE=$ROOT_TYPE
    WORK_DIR=`echo $WORK_DIR | sed -e "s:/[^/]*$::"` # Strip off another level
  done
fi

mkdir -p $1

echo $FS_TYPE > $LOGDIR/benchmark/fstype.$RUN_NUMBER
touch $LOGDIR/benchmark/reaim.$RUN_NUMBER

getcommand doprofilers
doprofilers install

pushd $AUTODIR/sources/reaim/src >/dev/null

echo "reaim $1 -f $2 ${@:3}"  > $LOGDIR/benchmark/cmdline.$RUN_NUMBER
startprofilers
./reaim $1 -f $2 ${@:3} | tee $LOGDIR/benchmark/reaim.$RUN_NUMBER
stopprofilers

doprofilers report
doprofilers postprocess

popd >/dev/null
