genfio: Adding cached_based option
[fio.git] / tools / genfio
1 #!/bin/bash
2 #
3 #  Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
4 #  Author: Erwan Velu  <erwan@enovance.com>
5 #
6 #  The license below covers all files distributed with fio unless otherwise
7 #  noted in the file itself.
8 #
9 #  This program is free software; you can redistribute it and/or modify
10 #  it under the terms of the GNU General Public License version 2 as
11 #  published by the Free Software Foundation.
12 #
13 #  This program is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #  GNU General Public License for more details.
17 #
18 #  You should have received a copy of the GNU General Public License
19 #  along with this program; if not, write to the Free Software
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
22 BLK_SIZE=
23 BLOCK_SIZE=4k
24 SEQ=-1
25 TEMPLATE=/tmp/template.fio
26 OUTFILE=
27 DISKS=
28 RUNTIME=300
29 ETA=0
30 MODES="read,write,randread,randwrite"
31 SHORT_HOSTNAME=
32 CACHED_IO="FALSE"
33
34 show_help() {
35         PROG=$(basename $0)
36         echo "usage of $PROG:"
37         cat << EOF
38 -h                              : Show this help & exit
39 -c                              : Enable cached-based IOs
40                                         by default, fio is run in direct mode
41 -a                              : Run sequential test then parallel one
42 -s                              : Run sequential test (default value)
43                                         one test after another then one disk after another
44 -p                              : Run parallel test
45                                         one test after anoter but all disks at the same time
46 -d disk1[,disk2,disk3,..]       : Run the tests on the selected disks
47                                         Separated each disk with a comma
48                                         Disk name shall be "sdxx", /dev/ shall NOT be used here
49 -r seconds                      : Time in seconds per benchmark (300 as default)
50                                         0 means till the end of the device
51 -b blocksize[,blocksize1, ...]  : The blocksizes to test under fio format (4k, 1m, ...)
52                                         Separated each blocksize with a comma
53 -m mode1,[mode2,mode3, ...]     : Define the fio IO profile to use like read, write, randread, randwrite
54
55 Example:
56
57 $PROG -d sdb,sdc,sdd,sde -a -b 4k,128k,1m -r 100 -a
58
59         Will generate an fio file that will run
60                 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with read,write,randread,randwrite tests
61                         ETA ~ 4 tests * 4 disks * 100 seconds
62                 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with read,write,randread,randwrite tests
63                         ETA ~ 4 tests * 4 disks * 100 seconds
64                 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with read,write,randread,randwrite tests
65                         ETA ~ 4 tests * 4 disks * 100 seconds
66                 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with read,write,randread,randwrite tests
67                         ETA ~ 4 tests * 100 seconds
68                 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with read,write,randread,randwrite tests
69                         ETA ~ 4 tests * 100 seconds
70                 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with read,write,randread,randwrite tests
71                         ETA ~ 4 tests * 100 seconds
72
73 Generating localhost-4k,128k,1m-all-read,write,randread,randwrite-sdb,sdc,sdd,sde.fio
74 Estimated Time = 6000 seconds : 1 hour 40 minutes
75 EOF
76 }
77
78 gen_template() {
79 cat >$TEMPLATE << EOF
80 [global]
81 ioengine=libaio
82 invalidate=1
83 ramp_time=5
84 EOF
85
86 if [ "$RUNTIME" != "0" ]; then
87 cat >>$TEMPLATE << EOF
88 runtime=$RUNTIME
89 EOF
90 fi
91
92 if [ "$CACHED_IO" = "FALSE" ]; then
93 cat >>$TEMPLATE << EOF
94 direct=1
95 EOF
96 fi
97
98 }
99
100 gen_seq_suite() {
101 TYPE=$1
102 cat >> $OUTFILE << EOF
103 [$TYPE-$disk-$BLK_SIZE-seq]
104 stonewall
105 bs=$BLK_SIZE
106 filename=/dev/$disk
107 rw=$TYPE
108 write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
109 write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
110 EOF
111 ETA=$(($ETA + $RUNTIME))
112 }
113
114 gen_seq_fio() {
115 for disk in $(echo $DISKS | tr "," " "); do
116         for mode in $(echo $MODES | tr "," " "); do
117                 gen_seq_suite "$mode"
118         done
119 done
120 }
121
122
123 gen_para_suite() {
124 TYPE=$1
125 NEED_WALL=$2
126 D=0
127 for disk in $(echo $DISKS | tr "," " "); do
128     cat >> $OUTFILE << EOF
129 [$TYPE-$disk-$BLK_SIZE-para]
130 bs=$BLK_SIZE
131 EOF
132
133 if [ "$D" = 0 ]; then
134     echo "stonewall" >> $OUTFILE
135     D=1
136 fi
137
138 cat >> $OUTFILE << EOF
139 filename=/dev/$disk
140 rw=$TYPE
141 write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
142 write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
143 EOF
144 done
145
146 ETA=$(($ETA + $RUNTIME))
147 echo >> $OUTFILE
148 }
149
150 gen_para_fio() {
151 for mode in $(echo $MODES | tr "," " "); do
152         gen_para_suite "$mode"
153 done
154 }
155
156 gen_fio() {
157 case $SEQ in
158         2)
159                 gen_seq_fio
160                 gen_para_fio
161         ;;
162         1)
163                 gen_seq_fio
164         ;;
165         0)
166                 gen_para_fio
167         ;;
168 esac
169 }
170
171 parse_cmdline() {
172 while getopts "hacpsd:b:r:m:" opt; do
173   case $opt in
174     h)
175         show_help
176         exit 0
177         ;;
178     b)
179         BLOCK_SIZE=$OPTARG
180         ;;
181     c)
182         CACHED_IO="TRUE"
183         ;;
184     s)
185         if [ "$SEQ" = "-1" ]; then
186                 SEQ=1
187         fi
188       ;;
189     r)
190         RUNTIME=$OPTARG
191       ;;
192     p)
193         if [ "$SEQ" = "-1" ]; then
194                 SEQ=0
195         fi
196       ;;
197     m)
198         MODES=$OPTARG;
199       ;;
200     d)
201         DISKS=$OPTARG
202       ;;
203     a)
204         SEQ=2
205       ;;
206     \?)
207       echo "Invalid option: -$OPTARG" >&2
208       ;;
209   esac
210 done
211
212 if [ "$SEQ" = "-1" ]; then
213         SEQ=0
214 fi
215
216 SHORT_HOSTNAME=$(hostname -s)
217 case $SEQ in
218         2)
219                 OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$DISKS.fio
220         ;;
221
222         1)
223                 OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$DISKS.fio
224         ;;
225         0)
226                 OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$DISKS.fio
227         ;;
228 esac
229
230 if [ -z "$DISKS" ]; then
231         echo "Missing DISKS !"
232         echo "Exiting !"
233         exit 1
234 fi
235
236 }
237
238
239 ########## MAIN
240 parse_cmdline $@
241 gen_template
242
243 echo "Generating $OUTFILE"
244 cp -f $TEMPLATE $OUTFILE
245 echo >> $OUTFILE
246
247 for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
248         gen_fio
249 done
250 ETA_H=$(($ETA / 3600))
251 ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
252 if [ "$ETA_M" = "0" ]; then
253         echo "Cannot estimate ETA as RUNTIME=0"
254 else
255         echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
256 fi