195a86135e460ef32f0d48d5137744f6ae529195
[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                                         Disabled by default
41 -a                              : Run sequential test then parallel one
42                                         Disabled by default
43 -s                              : Run sequential test (default value)
44                                         one test after another then one disk after another
45                                         Disabled by default
46 -p                              : Run parallel test
47                                         one test after anoter but all disks at the same time
48                                         Enabled by default
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
52 -r seconds                      : Time in seconds per benchmark
53                                         0 means till the end of the device
54                                         Default is 300 seconds
55 -b blocksize[,blocksize1, ...]  : The blocksizes to test under fio format (4k, 1m, ...)
56                                         Separated each blocksize with a comma
57                                         Default is 4k
58 -m mode1,[mode2,mode3, ...]     : Define the fio IO profile to use like read, write, randread, randwrite
59                                         Default is "read,write,randread,randwrite"
60
61 Example:
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
79 Generating localhost-4k,128k,1m-all-read,write,randread,randwrite-sdb,sdc,sdd,sde.fio
80 Estimated Time = 6000 seconds : 1 hour 40 minutes
81 EOF
82 }
83
84 gen_template() {
85 cat >$TEMPLATE << EOF
86 [global]
87 ioengine=libaio
88 invalidate=1
89 ramp_time=5
90 EOF
91
92 if [ "$RUNTIME" != "0" ]; then
93 cat >>$TEMPLATE << EOF
94 runtime=$RUNTIME
95 EOF
96 fi
97
98 if [ "$CACHED_IO" = "FALSE" ]; then
99 cat >>$TEMPLATE << EOF
100 direct=1
101 EOF
102 fi
103
104 }
105
106 gen_seq_suite() {
107 TYPE=$1
108 cat >> $OUTFILE << EOF
109 [$TYPE-$disk-$BLK_SIZE-seq]
110 stonewall
111 bs=$BLK_SIZE
112 filename=/dev/$disk
113 rw=$TYPE
114 write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
115 write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
116 EOF
117 ETA=$(($ETA + $RUNTIME))
118 }
119
120 gen_seq_fio() {
121 for disk in $(echo $DISKS | tr "," " "); do
122         for mode in $(echo $MODES | tr "," " "); do
123                 gen_seq_suite "$mode"
124         done
125 done
126 }
127
128
129 gen_para_suite() {
130 TYPE=$1
131 NEED_WALL=$2
132 D=0
133 for disk in $(echo $DISKS | tr "," " "); do
134     cat >> $OUTFILE << EOF
135 [$TYPE-$disk-$BLK_SIZE-para]
136 bs=$BLK_SIZE
137 EOF
138
139 if [ "$D" = 0 ]; then
140     echo "stonewall" >> $OUTFILE
141     D=1
142 fi
143
144 cat >> $OUTFILE << EOF
145 filename=/dev/$disk
146 rw=$TYPE
147 write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
148 write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
149 EOF
150 done
151
152 ETA=$(($ETA + $RUNTIME))
153 echo >> $OUTFILE
154 }
155
156 gen_para_fio() {
157 for mode in $(echo $MODES | tr "," " "); do
158         gen_para_suite "$mode"
159 done
160 }
161
162 gen_fio() {
163 case $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         ;;
174 esac
175 }
176
177 parse_cmdline() {
178 while getopts "hacpsd:b:r:m:" opt; do
179   case $opt in
180     h)
181         show_help
182         exit 0
183         ;;
184     b)
185         BLOCK_SIZE=$OPTARG
186         ;;
187     c)
188         CACHED_IO="TRUE"
189         ;;
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
216 done
217
218 if [ "$SEQ" = "-1" ]; then
219         SEQ=0
220 fi
221
222 SHORT_HOSTNAME=$(hostname -s)
223 case $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         ;;
234 esac
235
236 if [ -z "$DISKS" ]; then
237         echo "Missing DISKS !"
238         echo "Please read the help !"
239         show_help
240         exit 1
241 fi
242
243 }
244
245
246 ########## MAIN
247 parse_cmdline $@
248 gen_template
249
250 echo "Generating $OUTFILE"
251 cp -f $TEMPLATE $OUTFILE
252 echo >> $OUTFILE
253
254 for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
255         gen_fio
256 done
257 ETA_H=$(($ETA / 3600))
258 ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
259 if [ "$ETA_M" = "0" ]; then
260         echo "Cannot estimate ETA as RUNTIME=0"
261 else
262         echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
263 fi