fio: ioengine flag cleanup
[fio.git] / tools / genfio
CommitLineData
10ee8843 1#!/bin/bash
afbbd646
EV
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
fa07eaa6 20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
afbbd646
EV
21
22BLK_SIZE=
23BLOCK_SIZE=4k
24SEQ=-1
31952e1d
VS
25TEMPLATE=$(mktemp "${TMPDIR:-${TEMP:-/tmp}}/template.fio.XXXXXX") || exit $?
26trap 'rm -f "$TEMPLATE"' EXIT
afbbd646
EV
27OUTFILE=
28DISKS=
bed59bab 29PRINTABLE_DISKS=
afbbd646
EV
30RUNTIME=300
31ETA=0
60238f0e 32MODES="write,randwrite,read,randread"
afbbd646 33SHORT_HOSTNAME=
76c7c63e 34CACHED_IO="FALSE"
a7419837
EV
35PREFIX=""
36PREFIX_FILENAME=""
7d1ca6cf 37IODEPTH=1
afbbd646
EV
38
39show_help() {
40 PROG=$(basename $0)
41 echo "usage of $PROG:"
42 cat << EOF
43-h : Show this help & exit
76c7c63e 44-c : Enable cached-based IOs
e1c6f2e1 45 Disabled by default
afbbd646 46-a : Run sequential test then parallel one
e1c6f2e1 47 Disabled by default
afbbd646
EV
48-s : Run sequential test (default value)
49 one test after another then one disk after another
e1c6f2e1 50 Disabled by default
afbbd646 51-p : Run parallel test
fc002f14 52 one test after another but all disks at the same time
e1c6f2e1 53 Enabled by default
7d1ca6cf 54-D iodepth : Run with the specified iodepth
80139d2d 55 Default is $IODEPTH
afbbd646
EV
56-d disk1[,disk2,disk3,..] : Run the tests on the selected disks
57 Separated each disk with a comma
f6facd21
LM
58-z filesize : Specify the working file size, if you are passing filepaths to -d
59 Disabled by default
e1c6f2e1 60-r seconds : Time in seconds per benchmark
72fe3ef1 61 0 means till the end of the device
80139d2d 62 Default is $RUNTIME seconds
afbbd646
EV
63-b blocksize[,blocksize1, ...] : The blocksizes to test under fio format (4k, 1m, ...)
64 Separated each blocksize with a comma
80139d2d 65 Default is $BLOCK_SIZE
afbbd646 66-m mode1,[mode2,mode3, ...] : Define the fio IO profile to use like read, write, randread, randwrite
80139d2d 67 Default is "$MODES"
a7419837
EV
68-x prefix : Add a prefix to the fio filename
69 Useful to let a context associated with the file
70 If the prefix features a / (slash), prefix will be considered as a directory
ca143750
EV
71-A cmd_to_run : System command to run after each job (exec_postrun in fio)
72-B cmd_to_run : System command to run before each job (exec_prerun in fio)
afbbd646
EV
73
74Example:
75
bed59bab 76$PROG -d /dev/sdb,/dev/sdc,/dev/sdd,/dev/sde -a -b 4k,128k,1m -r 100 -a -x dellr720-day2/
afbbd646
EV
77
78 Will generate an fio file that will run
60238f0e 79 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with write,randwrite,read,randread tests
afbbd646 80 ETA ~ 4 tests * 4 disks * 100 seconds
60238f0e 81 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with write,randwrite,read,randread tests
afbbd646 82 ETA ~ 4 tests * 4 disks * 100 seconds
60238f0e 83 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with write,randwrite,read,randread tests
afbbd646 84 ETA ~ 4 tests * 4 disks * 100 seconds
60238f0e 85 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with write,randwrite,read,randread tests
afbbd646 86 ETA ~ 4 tests * 100 seconds
60238f0e 87 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with write,randwrite,read,randread tests
afbbd646 88 ETA ~ 4 tests * 100 seconds
60238f0e 89 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with write,randwrite,read,randread tests
afbbd646
EV
90 ETA ~ 4 tests * 100 seconds
91
60238f0e 92Generating dellr720-day2/localhost-4k,128k,1m-all-write,randwrite,read,randread-sdb,sdc,sdd,sde.fio
afbbd646
EV
93Estimated Time = 6000 seconds : 1 hour 40 minutes
94EOF
95}
96
fdc0f3b6 97finish_template() {
ea0542d9 98echo "iodepth=$IODEPTH" >> $TEMPLATE
afbbd646 99
72fe3ef1 100if [ "$RUNTIME" != "0" ]; then
ea0542d9
EV
101 echo "runtime=$RUNTIME" >> $TEMPLATE
102 echo "time_based" >> $TEMPLATE
72fe3ef1
EV
103fi
104
76c7c63e 105if [ "$CACHED_IO" = "FALSE" ]; then
ea0542d9 106 echo "direct=1" >> $TEMPLATE
76c7c63e 107fi
fdc0f3b6 108}
76c7c63e 109
bed59bab
EV
110
111diskname_to_printable() {
112COUNT=0
113for disk in $(echo $@ | tr "," " "); do
114 R=$(basename $disk | sed 's|/|_|g')
115 COUNT=$(($COUNT + 1))
116 if [ $COUNT -eq 1 ]; then
117 P="$R"
118 else
119 P="$P,$R"
120 fi
121done
122echo $P
123}
124
fdc0f3b6
EV
125gen_template() {
126cat >$TEMPLATE << EOF
127[global]
128ioengine=libaio
129invalidate=1
130ramp_time=5
131EOF
afbbd646
EV
132}
133
134gen_seq_suite() {
135TYPE=$1
bed59bab
EV
136disk=$2
137PRINTABLE_DISK=$(diskname_to_printable $disk)
afbbd646 138cat >> $OUTFILE << EOF
bed59bab 139[$TYPE-$PRINTABLE_DISK-$BLK_SIZE-seq]
afbbd646
EV
140stonewall
141bs=$BLK_SIZE
bed59bab 142filename=$disk
afbbd646 143rw=$TYPE
bed59bab
EV
144write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-seq.results
145write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-seq.results
afbbd646
EV
146EOF
147ETA=$(($ETA + $RUNTIME))
148}
149
150gen_seq_fio() {
151for disk in $(echo $DISKS | tr "," " "); do
152 for mode in $(echo $MODES | tr "," " "); do
bed59bab 153 gen_seq_suite "$mode" "$disk"
afbbd646
EV
154 done
155done
156}
157
158
159gen_para_suite() {
160TYPE=$1
161NEED_WALL=$2
162D=0
163for disk in $(echo $DISKS | tr "," " "); do
bed59bab 164 PRINTABLE_DISK=$(diskname_to_printable $disk)
afbbd646 165 cat >> $OUTFILE << EOF
bed59bab 166[$TYPE-$PRINTABLE_DISK-$BLK_SIZE-para]
afbbd646
EV
167bs=$BLK_SIZE
168EOF
169
170if [ "$D" = 0 ]; then
171 echo "stonewall" >> $OUTFILE
172 D=1
173fi
174
175cat >> $OUTFILE << EOF
bed59bab 176filename=$disk
afbbd646 177rw=$TYPE
bed59bab
EV
178write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-para.results
179write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-para.results
afbbd646
EV
180EOF
181done
182
183ETA=$(($ETA + $RUNTIME))
184echo >> $OUTFILE
185}
186
187gen_para_fio() {
188for mode in $(echo $MODES | tr "," " "); do
189 gen_para_suite "$mode"
190done
191}
192
193gen_fio() {
194case $SEQ in
195 2)
196 gen_seq_fio
197 gen_para_fio
198 ;;
199 1)
200 gen_seq_fio
201 ;;
202 0)
203 gen_para_fio
204 ;;
205esac
206}
207
208parse_cmdline() {
f6facd21 209while getopts "hacpsd:b:r:m:x:z:D:A:B:" opt; do
afbbd646
EV
210 case $opt in
211 h)
212 show_help
213 exit 0
214 ;;
215 b)
216 BLOCK_SIZE=$OPTARG
217 ;;
76c7c63e
EV
218 c)
219 CACHED_IO="TRUE"
220 ;;
afbbd646
EV
221 s)
222 if [ "$SEQ" = "-1" ]; then
223 SEQ=1
224 fi
225 ;;
a7419837
EV
226 x)
227 PREFIX=$OPTARG
228 echo "$PREFIX" | grep -q "/"
229 if [ "$?" -eq 0 ]; then
230 mkdir -p $PREFIX
231 # No need to keep the prefix for the log files
232 # we do have a directory for that
233 PREFIX_FILENAME=""
234 else
235 # We need to keep the prefix for the log files
236 PREFIX_FILENAME=$PREFIX
237 fi
238 ;;
afbbd646
EV
239 r)
240 RUNTIME=$OPTARG
241 ;;
242 p)
243 if [ "$SEQ" = "-1" ]; then
244 SEQ=0
245 fi
246 ;;
247 m)
248 MODES=$OPTARG;
249 ;;
250 d)
251 DISKS=$OPTARG
bed59bab 252 PRINTABLE_DISKS=$(diskname_to_printable "$DISKS")
afbbd646 253 ;;
7d1ca6cf
EV
254 D)
255 IODEPTH=$OPTARG
256 ;;
afbbd646
EV
257 a)
258 SEQ=2
259 ;;
ca143750
EV
260 B)
261 echo "exec_prerun=$OPTARG" >> $TEMPLATE
262 ;;
263 A)
264 echo "exec_postrun=$OPTARG" >> $TEMPLATE
265 ;;
f6facd21
LM
266 z)
267 FSIZE=$OPTARG
268 echo "size=$FSIZE" >> $TEMPLATE
269 ;;
afbbd646
EV
270 \?)
271 echo "Invalid option: -$OPTARG" >&2
272 ;;
273 esac
274done
275
276if [ "$SEQ" = "-1" ]; then
277 SEQ=0
278fi
279
280SHORT_HOSTNAME=$(hostname -s)
281case $SEQ in
282 2)
bed59bab 283 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$PRINTABLE_DISKS.fio
afbbd646
EV
284 ;;
285
286 1)
bed59bab 287 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$PRINTABLE_DISKS.fio
afbbd646
EV
288 ;;
289 0)
bed59bab 290 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$PRINTABLE_DISKS.fio
afbbd646
EV
291 ;;
292esac
293
294if [ -z "$DISKS" ]; then
295 echo "Missing DISKS !"
e1c6f2e1
EV
296 echo "Please read the help !"
297 show_help
afbbd646
EV
298 exit 1
299fi
300
301}
302
60238f0e
EV
303check_mode_order() {
304FOUND_WRITE="NO"
305CAUSE="You are reading data before writing them "
306
307# If no write occurs, let's show a different message
308echo $MODES | grep -q "write"
309if [ "$?" -ne 0 ]; then
310 CAUSE="You are reading data while never wrote them before"
311fi
312
313for mode in $(echo $MODES | tr "," " "); do
314 echo $mode | grep -q write
315 if [ "$?" -eq 0 ]; then
316 FOUND_WRITE="YES"
317 fi
318 echo $mode | grep -q "read"
319 if [ "$?" -eq 0 ]; then
320 if [ "$FOUND_WRITE" = "NO" ]; then
321 echo "###############################################################"
322 echo "# Warning : $CAUSE#"
323 echo "# On some storage devices, this could lead to invalid results #"
324 echo "# #"
325 echo "# Press Ctrl-C to adjust pattern order if you have doubts #"
326 echo "# Or Wait 5 seconds before the file will be created #"
327 echo "###############################################################"
328 sleep 5
329 # No need to try showing the message more than one time
330 return
331 fi
332 fi
333done
334}
335
afbbd646
EV
336
337########## MAIN
fdc0f3b6 338gen_template
3b73c537 339parse_cmdline "$@"
fdc0f3b6 340finish_template
60238f0e 341check_mode_order
afbbd646
EV
342
343echo "Generating $OUTFILE"
344cp -f $TEMPLATE $OUTFILE
345echo >> $OUTFILE
346
347for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
348 gen_fio
349done
350ETA_H=$(($ETA / 3600))
351ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
af360e39 352if [ "$ETA" = "0" ]; then
72fe3ef1
EV
353 echo "Cannot estimate ETA as RUNTIME=0"
354else
355 echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
356fi