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