#!/bin/bash
# This is the script to run the iozone benchmark
#
# reqparam value The temporary file or directory to conduct the test in
# optparam prefix "-b" value Output the result to the named excel file
# optparam prefix "-B" Use mmap() to access the temporary file
# optparam prefix "-c" Include close() in the timing calculations
# optparam prefix "-C" Show bytes transfered by each child in throupur testing
# optparam prefix "-d" value During throughput tests, use the given delay when starting each client
# optparam prefix "-D" Use msync(MS_ASYNC) on mmap files
# optparam prefix "-e" Include flush in the timing calculations
# optparam prefix "-E" Select an extension test (available on some platforms)
# optparam prefix "-F" value Specify each of the temporary file names to be used in the throughput test
# optparam prefix "-g" value Set the maximum file size (in Kbytes)
# optparam prefix "-G" Use msync(MS_SYNC) on mmap files
# optparam prefix "-H" value Use POSIX async (with bcopy) I/O with the given number of async opterations
# optparam prefix "-i" value repeat Specify which tests to run: 0=write/rewrite, 1=read/re-read, 2=random-read/write, 3=Read-backwards, 4=Re-write-record, 5=stride-read, 6=fwrite/re-fwrite, 7=fread/Re-fread, 8=random mix, 9=pwrite/Re-pwrite, 10=pread/Re-pread, 11=pwritev/Re-pwritev, 12=preadv/Re-preadv
# optparam prefix "-I" Use the VX_DIRECT option for VXFS filesystems
# optparam prefix "-j" value Set the stride of file accesses (N * record size)
# optparam prefix "-J" value Wait for the given number of milliseconds before each I/O operation
# optparam prefix "-k" value Use POSIX async (no bcopy) I/O with the given number of async opterations
# optparam prefix "-K" Inject some random accesses in the testing
# optparam prefix "-l" value Specify the minimum number of clients in throughput testing
# optparam prefix "-L" value Specify the processor cache line size (bytes)
# optparam prefix "-m" Use multiple buffers internally
# optparam prefix "-M" Put the output of uname() into the output file
# optparam prefix "-n" value Set the minimum file size
# optparam prefix "-N" Report results in microseconds per operation
# optparam prefix "-o" Open files with the O_SYNC flag
# optparam prefix "-O" Report results in operations per second
# optparam prefix "-p" Purge the processor cache before each file operation
# optparam prefix "-P" value Bind subprocesses to processors, starting with the given processor
# optparam prefix "-q" value Set the maximum record size (Kbytes)
# optparam prefix "-Q" Generate offset/latency files
# optparam prefix "-r" value Specify the record size (Kbytes)
# optparam prefix "-R" Generate Excel report
# optparam prefix "-s" value Specify the size of the test file (Kbytes)
# optparam prefix "-S" value Specify the processor cache size (Kbytes)
# optparam prefix "-t" value Run in throughput mode with the given number of clients
# optparam prefix "-T" Use pthreads for throughput tests
# optparam prefix "-u" value Specify the maximum number of clients in throughput testing
# optparam prefix "-U" value Mount point to unmount and remount between tests
# optparam prefix "-v" Display the iozone version
# optparam prefix "-V" value Specify the test pattern to be used to verify accuracy
# optparam prefix "-w" Do not unlink temporary files when done
# optparam prefix "-W" Lock files when reading or writing
# optparam prefix "-x" Turn off stone-walling
# optparam prefix "-X" value Specify a filename with write telemetry information
# optparam prefix "-y" value Specify the minimum record size (Kbytes)
# optparam prefix "-Y" value Specify a filename with read telemetry information
# optparam prefix "-z" Test small record sizes even for large files
# optparam prefix "-Z" Enable mixing of mmap and normal file I/O
# optparam prefix "-+A" value Enable madvice behavoir: 0=normal, 1=random, 2=sequential 3=dontneed, 4=willneed
# optparam prefix "-+d" Diagnostic mode : diagnose a broken file I/O subsystem
# optparam prefix "-+m" value Specify a file containing information for distributed measurments
# optparam prefix "-+p" value Specify the percentage of clients that will perform random read testing
# optparam prefix "-+r" Enable O_RSYNC | O_SYNC on all tests
# optparam prefix "-+t" Enable netowkr performance test
# optparam prefix "-+u" Enable CPU statistics collection
#
. /etc/autobench.conf || . functions

# Process the arguments ######################################################
if [ $# -lt 2 ]; then
  echo "You must specify a temporary filename or directory to run the test in"
  exit 1
fi

TMPFILE=$1
shift

# Install support files ######################################################
if [ ! \( -d $AUTODIR/sources/iozone -a \
          -x $AUTODIR/sources/iozone/src/current/iozone \) ]; then
  $AUTODIR/scripts/benchmarks/install/iozone
fi

getcommand doprofilers
doprofilers install

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

fs_type $TMPFILE $LOGDIR/benchmark/fstype.$RUN_NUMBER

if [ -d $TMPFILE ]; then
	TMPFILE=$TMPFILE/iozone.tmpfile.$$
fi
touch $TMPFILE

# Run the benchmark ##########################################################
startprofilers
$AUTODIR/sources/iozone/src/current/iozone -a -f $TMPFILE $*  | \
	tee $LOGDIR/benchmark/iozoneout.$RUN_NUMBER
stopprofilers
doprofilers report
doprofilers postprocess

