genfio: Adding iodepth support
[fio.git] / tools / genfio
index 195a86135e460ef32f0d48d5137744f6ae529195..4c1e710d2b2784d79bae4737d95d758920113a8d 100755 (executable)
@@ -27,9 +27,12 @@ OUTFILE=
 DISKS=
 RUNTIME=300
 ETA=0
-MODES="read,write,randread,randwrite"
+MODES="write,randwrite,read,randread"
 SHORT_HOSTNAME=
 CACHED_IO="FALSE"
+PREFIX=""
+PREFIX_FILENAME=""
+IODEPTH=1
 
 show_help() {
        PROG=$(basename $0)
@@ -46,6 +49,8 @@ show_help() {
 -p                             : Run parallel test
                                        one test after anoter but all disks at the same time
                                        Enabled by default
+-D iodepth                     : Run with the specified iodepth
+                                       Default is 32
 -d disk1[,disk2,disk3,..]      : Run the tests on the selected disks
                                        Separated each disk with a comma
                                        Disk name shall be "sdxx", /dev/ shall NOT be used here
@@ -56,27 +61,30 @@ show_help() {
                                        Separated each blocksize with a comma
                                        Default is 4k
 -m mode1,[mode2,mode3, ...]     : Define the fio IO profile to use like read, write, randread, randwrite
-                                       Default is "read,write,randread,randwrite"
+                                       Default is "write,randwrite,read,randread"
+-x prefix                      : Add a prefix to the fio filename
+                                       Useful to let a context associated with the file
+                                       If the prefix features a / (slash), prefix will be considered as a directory
 
 Example:
 
-$PROG -d sdb,sdc,sdd,sde -a -b 4k,128k,1m -r 100 -a
+$PROG -d sdb,sdc,sdd,sde -a -b 4k,128k,1m -r 100 -a -x dellr720-day2/
 
        Will generate an fio file that will run
-               - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with read,write,randread,randwrite tests
+               - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with write,randwrite,read,randread tests
                        ETA ~ 4 tests * 4 disks * 100 seconds
-               - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with read,write,randread,randwrite tests
+               - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with write,randwrite,read,randread tests
                        ETA ~ 4 tests * 4 disks * 100 seconds
-               - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with read,write,randread,randwrite tests
+               - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with write,randwrite,read,randread tests
                        ETA ~ 4 tests * 4 disks * 100 seconds
-               - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with read,write,randread,randwrite tests
+               - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with write,randwrite,read,randread tests
                        ETA ~ 4 tests * 100 seconds
-               - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with read,write,randread,randwrite tests
+               - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with write,randwrite,read,randread tests
                        ETA ~ 4 tests * 100 seconds
-               - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with read,write,randread,randwrite tests
+               - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with write,randwrite,read,randread tests
                        ETA ~ 4 tests * 100 seconds
 
-Generating localhost-4k,128k,1m-all-read,write,randread,randwrite-sdb,sdc,sdd,sde.fio
+Generating dellr720-day2/localhost-4k,128k,1m-all-write,randwrite,read,randread-sdb,sdc,sdd,sde.fio
 Estimated Time = 6000 seconds : 1 hour 40 minutes
 EOF
 }
@@ -85,6 +93,7 @@ gen_template() {
 cat >$TEMPLATE << EOF
 [global]
 ioengine=libaio
+iodepth=$IODEPTH
 invalidate=1
 ramp_time=5
 EOF
@@ -111,8 +120,8 @@ stonewall
 bs=$BLK_SIZE
 filename=/dev/$disk
 rw=$TYPE
-write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
-write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
+write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
+write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
 EOF
 ETA=$(($ETA + $RUNTIME))
 }
@@ -144,8 +153,8 @@ fi
 cat >> $OUTFILE << EOF
 filename=/dev/$disk
 rw=$TYPE
-write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
-write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
+write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
+write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
 EOF
 done
 
@@ -175,7 +184,7 @@ esac
 }
 
 parse_cmdline() {
-while getopts "hacpsd:b:r:m:" opt; do
+while getopts "hacpsd:b:r:m:x:D:" opt; do
   case $opt in
     h)
        show_help
@@ -192,6 +201,19 @@ while getopts "hacpsd:b:r:m:" opt; do
                SEQ=1
        fi
       ;;
+    x)
+       PREFIX=$OPTARG
+       echo "$PREFIX" | grep -q "/"
+       if [ "$?" -eq 0 ]; then
+               mkdir -p $PREFIX
+               # No need to keep the prefix for the log files
+               # we do have a directory for that
+               PREFIX_FILENAME=""
+       else
+               # We need to keep the prefix for the log files
+               PREFIX_FILENAME=$PREFIX
+       fi
+       ;;
     r)
        RUNTIME=$OPTARG
       ;;
@@ -206,6 +228,9 @@ while getopts "hacpsd:b:r:m:" opt; do
     d)
        DISKS=$OPTARG
       ;;
+    D)
+       IODEPTH=$OPTARG
+      ;;
     a)
        SEQ=2
       ;;
@@ -222,14 +247,14 @@ fi
 SHORT_HOSTNAME=$(hostname -s)
 case $SEQ in
        2)
-               OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$DISKS.fio
+               OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$DISKS.fio
        ;;
 
        1)
-               OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$DISKS.fio
+               OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$DISKS.fio
        ;;
        0)
-               OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$DISKS.fio
+               OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$DISKS.fio
        ;;
 esac
 
@@ -242,9 +267,43 @@ fi
 
 }
 
+check_mode_order() {
+FOUND_WRITE="NO"
+CAUSE="You are reading data before writing them          "
+
+# If no write occurs, let's show a different message
+echo $MODES | grep -q "write"
+if [ "$?" -ne 0 ]; then
+       CAUSE="You are reading data while never wrote them before"
+fi
+
+for mode in $(echo $MODES | tr "," " "); do
+       echo $mode | grep -q write
+       if [ "$?" -eq 0 ]; then
+               FOUND_WRITE="YES"
+       fi
+       echo $mode | grep -q "read"
+       if [ "$?" -eq 0 ]; then
+               if [ "$FOUND_WRITE" = "NO" ]; then
+                       echo "###############################################################"
+                       echo "# Warning : $CAUSE#"
+                       echo "# On some storage devices, this could lead to invalid results #"
+                       echo "#                                                             #"
+                       echo "# Press Ctrl-C to adjust pattern order if you have doubts     #"
+                       echo "# Or Wait 5 seconds before the file will be created           #"
+                       echo "###############################################################"
+                       sleep 5
+                       # No need to try showing the message more than one time
+                       return
+               fi
+       fi
+done
+}
+
 
 ########## MAIN
 parse_cmdline $@
+check_mode_order
 gen_template
 
 echo "Generating $OUTFILE"
@@ -256,7 +315,7 @@ for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
 done
 ETA_H=$(($ETA / 3600))
 ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
-if [ "$ETA_M" = "0" ]; then
+if [ "$ETA" = "0" ]; then
        echo "Cannot estimate ETA as RUNTIME=0"
 else
        echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"