genfio: Adding cached_based option
[fio.git] / tools / genfio
... / ...
CommitLineData
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=
32CACHED_IO="FALSE"
33
34show_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
55Example:
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
73Generating localhost-4k,128k,1m-all-read,write,randread,randwrite-sdb,sdc,sdd,sde.fio
74Estimated Time = 6000 seconds : 1 hour 40 minutes
75EOF
76}
77
78gen_template() {
79cat >$TEMPLATE << EOF
80[global]
81ioengine=libaio
82invalidate=1
83ramp_time=5
84EOF
85
86if [ "$RUNTIME" != "0" ]; then
87cat >>$TEMPLATE << EOF
88runtime=$RUNTIME
89EOF
90fi
91
92if [ "$CACHED_IO" = "FALSE" ]; then
93cat >>$TEMPLATE << EOF
94direct=1
95EOF
96fi
97
98}
99
100gen_seq_suite() {
101TYPE=$1
102cat >> $OUTFILE << EOF
103[$TYPE-$disk-$BLK_SIZE-seq]
104stonewall
105bs=$BLK_SIZE
106filename=/dev/$disk
107rw=$TYPE
108write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
109write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
110EOF
111ETA=$(($ETA + $RUNTIME))
112}
113
114gen_seq_fio() {
115for disk in $(echo $DISKS | tr "," " "); do
116 for mode in $(echo $MODES | tr "," " "); do
117 gen_seq_suite "$mode"
118 done
119done
120}
121
122
123gen_para_suite() {
124TYPE=$1
125NEED_WALL=$2
126D=0
127for disk in $(echo $DISKS | tr "," " "); do
128 cat >> $OUTFILE << EOF
129[$TYPE-$disk-$BLK_SIZE-para]
130bs=$BLK_SIZE
131EOF
132
133if [ "$D" = 0 ]; then
134 echo "stonewall" >> $OUTFILE
135 D=1
136fi
137
138cat >> $OUTFILE << EOF
139filename=/dev/$disk
140rw=$TYPE
141write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
142write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
143EOF
144done
145
146ETA=$(($ETA + $RUNTIME))
147echo >> $OUTFILE
148}
149
150gen_para_fio() {
151for mode in $(echo $MODES | tr "," " "); do
152 gen_para_suite "$mode"
153done
154}
155
156gen_fio() {
157case $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 ;;
168esac
169}
170
171parse_cmdline() {
172while 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
210done
211
212if [ "$SEQ" = "-1" ]; then
213 SEQ=0
214fi
215
216SHORT_HOSTNAME=$(hostname -s)
217case $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 ;;
228esac
229
230if [ -z "$DISKS" ]; then
231 echo "Missing DISKS !"
232 echo "Exiting !"
233 exit 1
234fi
235
236}
237
238
239########## MAIN
240parse_cmdline $@
241gen_template
242
243echo "Generating $OUTFILE"
244cp -f $TEMPLATE $OUTFILE
245echo >> $OUTFILE
246
247for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
248 gen_fio
249done
250ETA_H=$(($ETA / 3600))
251ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
252if [ "$ETA_M" = "0" ]; then
253 echo "Cannot estimate ETA as RUNTIME=0"
254else
255 echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
256fi