#!/bin/ksh
# Driver for benchmark

PATH=/sbin:/bin:/usr/bin
export PATH
systype=$(uname -s)

timer () {
    case "$systype" in
        FreeBSD) cmd=/usr/bin/time ;;
          Linux) cmd=/usr/bin/time ;;
              *) cmd=/bin/time ;;
    esac

    $cmd -p $@
}

# Keep results without redirecting every command.

exec 1> /tmp/fdtree.results
exec 2>&1

# Print something about the filesystem used for the test.

echo Test run on:

set X $(df -k . | tail -1)
case "$#" in
    7) here=$7
       mount | grep $here
       dev=$(echo $2 | sed -e 's/[0-9]*$//g')
       echo scheduler: $(cat /sys/block/$dev/queue/scheduler)
       ;;

    *) here=. ;;
esac

echo
df -k $here
echo

# Small Files - Shallow Directory Structure
#
#   This command creates 20 sub-directories from each upper level directory
#   at each level ("-d 20") and there are 3 levels ("-l 3").  It's a basic
#   tree structure.  This is a total of 8,421 directories.  In each directory
#   there are 40 files ("-f 40") each sized at 1 block (4 KiB) denoted by
#   "-s 1".  This is a total of 336,840 files and 1,347 MiB total data.

echo Small Files - Shallow Directory Structure
for try in 1 2 3 4 5 6 7 8 9 10
do
    timer ./fdtree -d 20 -f 40 -s 1 -l 3
done

# Small Files - Deep Directory Structure
#
#   This command creates 3 sub-directories from each upper level directory at
#   each level ("-d 3") and there are 10 levels ("-l 10").  This is a total
#   of 88,573 directories.  In each directory there are 4 files each sized
#   at 1 block (4 KiB).  This is a total of 354,292 files and 1,417 MiB
#   total data.

echo Small Files - Deep Directory Structure
for try in 1 2 3 4 5 6 7 8 9 10
do
    timer ./fdtree -d 3 -f 4 -s 1 -l 10
done

# Medium Files - Shallow Directory Structure
#
#   This command creates 17 sub-directories from each upper level directory
#   at each level ("-d 17") and there are 2 levels ("-l 2").  This is a total
#   of 307 directories.  In each directory there are 10 files each sized
#   at 1000 blocks (4 MiB).  This is a total of 3,070 files and 12,280 MiB
#   total data.

echo Medium Files - Shallow Directory Structure
for try in 1 2 3 4 5 6 7 8 9 10
do
    timer ./fdtree -d 17 -f 10 -s 1000 -l 2
done

# Medium Files - Deep Directory Structure
#
#   This command creates 2 sub-directories from each upper level directory at
#   each level ("-d 2") and there are 10 levels ("-l 10").  This is a total
#   of 2,047 directories.  In each directory there are 2 files each sized
#   at 1000 blocks (4 MiB).  This is a total of 4,094 files and 16,376 MiB
#   total data.

echo Medium Files - Deep Directory Structure
for try in 1 2 3 4 5 6 7 8 9 10
do
    timer ./fdtree -d 2 -f 2 -s 1000 -l 10
done

echo Done
exit 0
