#!/bin/bash
# This is the script to run the dbench benchmark
#
# reqparam value The directory to run the test in
# reqparam value The number of clients to run
# optparam prefix "-v" Show version
# optparam prefix "-s" Synchronous file IO
# optparam prefix "-S" Synchronous directories (mkdir, unlink...)
# optparam prefix "-t" value Set socket options for tbench

. /etc/autobench.conf || . functions

# Process the arguments ######################################################
if [ $# -lt 2 ]; then
  echo "You must specify the directory to run the test in (on the disk to test)"
  echo "and the number of clients to run."
  exit 1
fi

# Install support files ######################################################
if [ ! \( -d $AUTODIR/sources/dbench -a -x $AUTODIR/sources/dbench/dbench \) ];
then
  $AUTODIR/scripts/benchmarks/install/dbench || exit 2
fi

getcommand doprofilers
doprofilers install

# Prepare the benchmark ######################################################

fs_type $1 $LOGDIR/benchmark/fstype.$RUN_NUMBER
touch $LOGDIR/benchmark/dbenchout.$RUN_NUMBER

mkdir -p $1
pushd $1 > /dev/null
shift

# Run the benchmark ##########################################################
startprofilers
$AUTODIR/sources/dbench/dbench $@ -c $AUTODIR/sources/dbench/client_oplocks.txt | tee $LOGDIR/benchmark/dbenchout.$RUN_NUMBER
stopprofilers
doprofilers report
doprofilers postprocess

popd > /dev/null
