genfio: Claryfing default options
[fio.git] / tools / genfio
CommitLineData
afbbd646
EV
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
22BLK_SIZE=
23BLOCK_SIZE=4k
24SEQ=-1
25TEMPLATE=/tmp/template.fio
26OUTFILE=
27DISKS=
28RUNTIME=300
29ETA=0
30MODES="read,write,randread,randwrite"
31SHORT_HOSTNAME=
76c7c63e 32CACHED_IO="FALSE"
afbbd646
EV
33
34show_help() {
35 PROG=$(basename $0)
36 echo "usage of $PROG:"
37 cat << EOF
38-h : Show this help & exit
76c7c63e 39-c : Enable cached-based IOs
e1c6f2e1 40 Disabled by default
afbbd646 41-a : Run sequential test then parallel one
e1c6f2e1 42 Disabled by default
afbbd646
EV
43-s : Run sequential test (default value)
44 one test after another then one disk after another
e1c6f2e1 45 Disabled by default
afbbd646
EV
46-p : Run parallel test
47 one test after anoter but all disks at the same time
e1c6f2e1 48 Enabled by default
afbbd646
EV
49-d disk1[,disk2,disk3,..] : Run the tests on the selected disks
50 Separated each disk with a comma
51 Disk name shall be "sdxx", /dev/ shall NOT be used here
e1c6f2e1 52-r seconds : Time in seconds per benchmark
72fe3ef1 53 0 means till the end of the device
e1c6f2e1 54 Default is 300 seconds
afbbd646
EV
55-b blocksize[,blocksize1, ...] : The blocksizes to test under fio format (4k, 1m, ...)
56 Separated each blocksize with a comma
e1c6f2e1 57 Default is 4k
afbbd646 58-m mode1,[mode2,mode3, ...] : Define the fio IO profile to use like read, write, randread, randwrite
e1c6f2e1 59 Default is "read,write,randread,randwrite"
afbbd646
EV
60
61Example:
62
63$PROG -d sdb,sdc,sdd,sde -a -b 4k,128k,1m -r 100 -a
64
65 Will generate an fio file that will run
66 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with read,write,randread,randwrite tests
67 ETA ~ 4 tests * 4 disks * 100 seconds
68 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with read,write,randread,randwrite tests
69 ETA ~ 4 tests * 4 disks * 100 seconds
70 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with read,write,randread,randwrite tests
71 ETA ~ 4 tests * 4 disks * 100 seconds
72 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with read,write,randread,randwrite tests
73 ETA ~ 4 tests * 100 seconds
74 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with read,write,randread,randwrite tests
75 ETA ~ 4 tests * 100 seconds
76 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with read,write,randread,randwrite tests
77 ETA ~ 4 tests * 100 seconds
78
79Generating localhost-4k,128k,1m-all-read,write,randread,randwrite-sdb,sdc,sdd,sde.fio
80Estimated Time = 6000 seconds : 1 hour 40 minutes
81EOF
82}
83
84gen_template() {
85cat >$TEMPLATE << EOF
86[global]
87ioengine=libaio
88invalidate=1
afbbd646 89ramp_time=5
72fe3ef1 90EOF
afbbd646 91
72fe3ef1
EV
92if [ "$RUNTIME" != "0" ]; then
93cat >>$TEMPLATE << EOF
94runtime=$RUNTIME
afbbd646 95EOF
72fe3ef1
EV
96fi
97
76c7c63e
EV
98if [ "$CACHED_IO" = "FALSE" ]; then
99cat >>$TEMPLATE << EOF
100direct=1
101EOF
102fi
103
afbbd646
EV
104}
105
106gen_seq_suite() {
107TYPE=$1
108cat >> $OUTFILE << EOF
109[$TYPE-$disk-$BLK_SIZE-seq]
110stonewall
111bs=$BLK_SIZE
112filename=/dev/$disk
113rw=$TYPE
114write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
115write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
116EOF
117ETA=$(($ETA + $RUNTIME))
118}
119
120gen_seq_fio() {
121for disk in $(echo $DISKS | tr "," " "); do
122 for mode in $(echo $MODES | tr "," " "); do
123 gen_seq_suite "$mode"
124 done
125done
126}
127
128
129gen_para_suite() {
130TYPE=$1
131NEED_WALL=$2
132D=0
133for disk in $(echo $DISKS | tr "," " "); do
134 cat >> $OUTFILE << EOF
135[$TYPE-$disk-$BLK_SIZE-para]
136bs=$BLK_SIZE
137EOF
138
139if [ "$D" = 0 ]; then
140 echo "stonewall" >> $OUTFILE
141 D=1
142fi
143
144cat >> $OUTFILE << EOF
145filename=/dev/$disk
146rw=$TYPE
147write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
148write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
149EOF
150done
151
152ETA=$(($ETA + $RUNTIME))
153echo >> $OUTFILE
154}
155
156gen_para_fio() {
157for mode in $(echo $MODES | tr "," " "); do
158 gen_para_suite "$mode"
159done
160}
161
162gen_fio() {
163case $SEQ in
164 2)
165 gen_seq_fio
166 gen_para_fio
167 ;;
168 1)
169 gen_seq_fio
170 ;;
171 0)
172 gen_para_fio
173 ;;
174esac
175}
176
177parse_cmdline() {
76c7c63e 178while getopts "hacpsd:b:r:m:" opt; do
afbbd646
EV
179 case $opt in
180 h)
181 show_help
182 exit 0
183 ;;
184 b)
185 BLOCK_SIZE=$OPTARG
186 ;;
76c7c63e
EV
187 c)
188 CACHED_IO="TRUE"
189 ;;
afbbd646
EV
190 s)
191 if [ "$SEQ" = "-1" ]; then
192 SEQ=1
193 fi
194 ;;
195 r)
196 RUNTIME=$OPTARG
197 ;;
198 p)
199 if [ "$SEQ" = "-1" ]; then
200 SEQ=0
201 fi
202 ;;
203 m)
204 MODES=$OPTARG;
205 ;;
206 d)
207 DISKS=$OPTARG
208 ;;
209 a)
210 SEQ=2
211 ;;
212 \?)
213 echo "Invalid option: -$OPTARG" >&2
214 ;;
215 esac
216done
217
218if [ "$SEQ" = "-1" ]; then
219 SEQ=0
220fi
221
222SHORT_HOSTNAME=$(hostname -s)
223case $SEQ in
224 2)
225 OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$DISKS.fio
226 ;;
227
228 1)
229 OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$DISKS.fio
230 ;;
231 0)
232 OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$DISKS.fio
233 ;;
234esac
235
236if [ -z "$DISKS" ]; then
237 echo "Missing DISKS !"
e1c6f2e1
EV
238 echo "Please read the help !"
239 show_help
afbbd646
EV
240 exit 1
241fi
242
243}
244
245
246########## MAIN
247parse_cmdline $@
248gen_template
249
250echo "Generating $OUTFILE"
251cp -f $TEMPLATE $OUTFILE
252echo >> $OUTFILE
253
254for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
255 gen_fio
256done
257ETA_H=$(($ETA / 3600))
258ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
72fe3ef1
EV
259if [ "$ETA_M" = "0" ]; then
260 echo "Cannot estimate ETA as RUNTIME=0"
261else
262 echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
263fi