blob: 4d32d13084707103e5bd32beac10eb1156378e3e [file] [log] [blame]
Bruce Cranc60587f2013-11-04 11:52:08 +00001#!/usr/bin/env bash
Erwan Veluafbbd642013-06-25 17:47:01 +02002#
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=
Erwan Velubed59ba2013-08-08 10:59:46 +020028PRINTABLE_DISKS=
Erwan Veluafbbd642013-06-25 17:47:01 +020029RUNTIME=300
30ETA=0
Erwan Velu60238f02013-07-12 15:21:25 +020031MODES="write,randwrite,read,randread"
Erwan Veluafbbd642013-06-25 17:47:01 +020032SHORT_HOSTNAME=
Erwan Velu76c7c632013-07-10 16:44:24 +020033CACHED_IO="FALSE"
Erwan Velua7419832013-07-11 09:56:28 +020034PREFIX=""
35PREFIX_FILENAME=""
Erwan Velu7d1ca6c2013-07-12 17:01:31 +020036IODEPTH=1
Erwan Veluafbbd642013-06-25 17:47:01 +020037
38show_help() {
39 PROG=$(basename $0)
40 echo "usage of $PROG:"
41 cat << EOF
42-h : Show this help & exit
Erwan Velu76c7c632013-07-10 16:44:24 +020043-c : Enable cached-based IOs
Erwan Velue1c6f2e2013-07-10 16:50:20 +020044 Disabled by default
Erwan Veluafbbd642013-06-25 17:47:01 +020045-a : Run sequential test then parallel one
Erwan Velue1c6f2e2013-07-10 16:50:20 +020046 Disabled by default
Erwan Veluafbbd642013-06-25 17:47:01 +020047-s : Run sequential test (default value)
48 one test after another then one disk after another
Erwan Velue1c6f2e2013-07-10 16:50:20 +020049 Disabled by default
Erwan Veluafbbd642013-06-25 17:47:01 +020050-p : Run parallel test
51 one test after anoter but all disks at the same time
Erwan Velue1c6f2e2013-07-10 16:50:20 +020052 Enabled by default
Erwan Velu7d1ca6c2013-07-12 17:01:31 +020053-D iodepth : Run with the specified iodepth
Erwan Velu80139d22013-07-15 12:03:55 +020054 Default is $IODEPTH
Erwan Veluafbbd642013-06-25 17:47:01 +020055-d disk1[,disk2,disk3,..] : Run the tests on the selected disks
56 Separated each disk with a comma
Erwan Velue1c6f2e2013-07-10 16:50:20 +020057-r seconds : Time in seconds per benchmark
Erwan Velu72fe3ef2013-07-10 16:38:33 +020058 0 means till the end of the device
Erwan Velu80139d22013-07-15 12:03:55 +020059 Default is $RUNTIME seconds
Erwan Veluafbbd642013-06-25 17:47:01 +020060-b blocksize[,blocksize1, ...] : The blocksizes to test under fio format (4k, 1m, ...)
61 Separated each blocksize with a comma
Erwan Velu80139d22013-07-15 12:03:55 +020062 Default is $BLOCK_SIZE
Erwan Veluafbbd642013-06-25 17:47:01 +020063-m mode1,[mode2,mode3, ...] : Define the fio IO profile to use like read, write, randread, randwrite
Erwan Velu80139d22013-07-15 12:03:55 +020064 Default is "$MODES"
Erwan Velua7419832013-07-11 09:56:28 +020065-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
Erwan Veluca143752013-07-15 11:10:27 +020068-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)
Erwan Veluafbbd642013-06-25 17:47:01 +020070
71Example:
72
Erwan Velubed59ba2013-08-08 10:59:46 +020073$PROG -d /dev/sdb,/dev/sdc,/dev/sdd,/dev/sde -a -b 4k,128k,1m -r 100 -a -x dellr720-day2/
Erwan Veluafbbd642013-06-25 17:47:01 +020074
75 Will generate an fio file that will run
Erwan Velu60238f02013-07-12 15:21:25 +020076 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with write,randwrite,read,randread tests
Erwan Veluafbbd642013-06-25 17:47:01 +020077 ETA ~ 4 tests * 4 disks * 100 seconds
Erwan Velu60238f02013-07-12 15:21:25 +020078 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with write,randwrite,read,randread tests
Erwan Veluafbbd642013-06-25 17:47:01 +020079 ETA ~ 4 tests * 4 disks * 100 seconds
Erwan Velu60238f02013-07-12 15:21:25 +020080 - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with write,randwrite,read,randread tests
Erwan Veluafbbd642013-06-25 17:47:01 +020081 ETA ~ 4 tests * 4 disks * 100 seconds
Erwan Velu60238f02013-07-12 15:21:25 +020082 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with write,randwrite,read,randread tests
Erwan Veluafbbd642013-06-25 17:47:01 +020083 ETA ~ 4 tests * 100 seconds
Erwan Velu60238f02013-07-12 15:21:25 +020084 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with write,randwrite,read,randread tests
Erwan Veluafbbd642013-06-25 17:47:01 +020085 ETA ~ 4 tests * 100 seconds
Erwan Velu60238f02013-07-12 15:21:25 +020086 - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with write,randwrite,read,randread tests
Erwan Veluafbbd642013-06-25 17:47:01 +020087 ETA ~ 4 tests * 100 seconds
88
Erwan Velu60238f02013-07-12 15:21:25 +020089Generating dellr720-day2/localhost-4k,128k,1m-all-write,randwrite,read,randread-sdb,sdc,sdd,sde.fio
Erwan Veluafbbd642013-06-25 17:47:01 +020090Estimated Time = 6000 seconds : 1 hour 40 minutes
91EOF
92}
93
Erwan Velufdc0f3b2013-07-15 10:44:58 +020094finish_template() {
Erwan Veluea0542d2013-07-15 11:14:39 +020095echo "iodepth=$IODEPTH" >> $TEMPLATE
Erwan Velu72fe3ef2013-07-10 16:38:33 +020096
97if [ "$RUNTIME" != "0" ]; then
Erwan Veluea0542d2013-07-15 11:14:39 +020098 echo "runtime=$RUNTIME" >> $TEMPLATE
99 echo "time_based" >> $TEMPLATE
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200100fi
101
Erwan Velu76c7c632013-07-10 16:44:24 +0200102if [ "$CACHED_IO" = "FALSE" ]; then
Erwan Veluea0542d2013-07-15 11:14:39 +0200103 echo "direct=1" >> $TEMPLATE
Erwan Velu76c7c632013-07-10 16:44:24 +0200104fi
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200105}
Erwan Velu76c7c632013-07-10 16:44:24 +0200106
Erwan Velubed59ba2013-08-08 10:59:46 +0200107
108diskname_to_printable() {
109COUNT=0
110for disk in $(echo $@ | tr "," " "); do
111 R=$(basename $disk | sed 's|/|_|g')
112 COUNT=$(($COUNT + 1))
113 if [ $COUNT -eq 1 ]; then
114 P="$R"
115 else
116 P="$P,$R"
117 fi
118done
119echo $P
120}
121
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200122gen_template() {
123cat >$TEMPLATE << EOF
124[global]
125ioengine=libaio
126invalidate=1
127ramp_time=5
128EOF
Erwan Veluafbbd642013-06-25 17:47:01 +0200129}
130
131gen_seq_suite() {
132TYPE=$1
Erwan Velubed59ba2013-08-08 10:59:46 +0200133disk=$2
134PRINTABLE_DISK=$(diskname_to_printable $disk)
Erwan Veluafbbd642013-06-25 17:47:01 +0200135cat >> $OUTFILE << EOF
Erwan Velubed59ba2013-08-08 10:59:46 +0200136[$TYPE-$PRINTABLE_DISK-$BLK_SIZE-seq]
Erwan Veluafbbd642013-06-25 17:47:01 +0200137stonewall
138bs=$BLK_SIZE
Erwan Velubed59ba2013-08-08 10:59:46 +0200139filename=$disk
Erwan Veluafbbd642013-06-25 17:47:01 +0200140rw=$TYPE
Erwan Velubed59ba2013-08-08 10:59:46 +0200141write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-seq.results
142write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-seq.results
Erwan Veluafbbd642013-06-25 17:47:01 +0200143EOF
144ETA=$(($ETA + $RUNTIME))
145}
146
147gen_seq_fio() {
148for disk in $(echo $DISKS | tr "," " "); do
149 for mode in $(echo $MODES | tr "," " "); do
Erwan Velubed59ba2013-08-08 10:59:46 +0200150 gen_seq_suite "$mode" "$disk"
Erwan Veluafbbd642013-06-25 17:47:01 +0200151 done
152done
153}
154
155
156gen_para_suite() {
157TYPE=$1
158NEED_WALL=$2
159D=0
160for disk in $(echo $DISKS | tr "," " "); do
Erwan Velubed59ba2013-08-08 10:59:46 +0200161 PRINTABLE_DISK=$(diskname_to_printable $disk)
Erwan Veluafbbd642013-06-25 17:47:01 +0200162 cat >> $OUTFILE << EOF
Erwan Velubed59ba2013-08-08 10:59:46 +0200163[$TYPE-$PRINTABLE_DISK-$BLK_SIZE-para]
Erwan Veluafbbd642013-06-25 17:47:01 +0200164bs=$BLK_SIZE
165EOF
166
167if [ "$D" = 0 ]; then
168 echo "stonewall" >> $OUTFILE
169 D=1
170fi
171
172cat >> $OUTFILE << EOF
Erwan Velubed59ba2013-08-08 10:59:46 +0200173filename=$disk
Erwan Veluafbbd642013-06-25 17:47:01 +0200174rw=$TYPE
Erwan Velubed59ba2013-08-08 10:59:46 +0200175write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-para.results
176write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-para.results
Erwan Veluafbbd642013-06-25 17:47:01 +0200177EOF
178done
179
180ETA=$(($ETA + $RUNTIME))
181echo >> $OUTFILE
182}
183
184gen_para_fio() {
185for mode in $(echo $MODES | tr "," " "); do
186 gen_para_suite "$mode"
187done
188}
189
190gen_fio() {
191case $SEQ in
192 2)
193 gen_seq_fio
194 gen_para_fio
195 ;;
196 1)
197 gen_seq_fio
198 ;;
199 0)
200 gen_para_fio
201 ;;
202esac
203}
204
205parse_cmdline() {
Erwan Veluca143752013-07-15 11:10:27 +0200206while getopts "hacpsd:b:r:m:x:D:A:B:" opt; do
Erwan Veluafbbd642013-06-25 17:47:01 +0200207 case $opt in
208 h)
209 show_help
210 exit 0
211 ;;
212 b)
213 BLOCK_SIZE=$OPTARG
214 ;;
Erwan Velu76c7c632013-07-10 16:44:24 +0200215 c)
216 CACHED_IO="TRUE"
217 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200218 s)
219 if [ "$SEQ" = "-1" ]; then
220 SEQ=1
221 fi
222 ;;
Erwan Velua7419832013-07-11 09:56:28 +0200223 x)
224 PREFIX=$OPTARG
225 echo "$PREFIX" | grep -q "/"
226 if [ "$?" -eq 0 ]; then
227 mkdir -p $PREFIX
228 # No need to keep the prefix for the log files
229 # we do have a directory for that
230 PREFIX_FILENAME=""
231 else
232 # We need to keep the prefix for the log files
233 PREFIX_FILENAME=$PREFIX
234 fi
235 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200236 r)
237 RUNTIME=$OPTARG
238 ;;
239 p)
240 if [ "$SEQ" = "-1" ]; then
241 SEQ=0
242 fi
243 ;;
244 m)
245 MODES=$OPTARG;
246 ;;
247 d)
248 DISKS=$OPTARG
Erwan Velubed59ba2013-08-08 10:59:46 +0200249 PRINTABLE_DISKS=$(diskname_to_printable "$DISKS")
Erwan Veluafbbd642013-06-25 17:47:01 +0200250 ;;
Erwan Velu7d1ca6c2013-07-12 17:01:31 +0200251 D)
252 IODEPTH=$OPTARG
253 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200254 a)
255 SEQ=2
256 ;;
Erwan Veluca143752013-07-15 11:10:27 +0200257 B)
258 echo "exec_prerun=$OPTARG" >> $TEMPLATE
259 ;;
260 A)
261 echo "exec_postrun=$OPTARG" >> $TEMPLATE
262 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200263 \?)
264 echo "Invalid option: -$OPTARG" >&2
265 ;;
266 esac
267done
268
269if [ "$SEQ" = "-1" ]; then
270 SEQ=0
271fi
272
273SHORT_HOSTNAME=$(hostname -s)
274case $SEQ in
275 2)
Erwan Velubed59ba2013-08-08 10:59:46 +0200276 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$PRINTABLE_DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200277 ;;
278
279 1)
Erwan Velubed59ba2013-08-08 10:59:46 +0200280 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$PRINTABLE_DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200281 ;;
282 0)
Erwan Velubed59ba2013-08-08 10:59:46 +0200283 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$PRINTABLE_DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200284 ;;
285esac
286
287if [ -z "$DISKS" ]; then
288 echo "Missing DISKS !"
Erwan Velue1c6f2e2013-07-10 16:50:20 +0200289 echo "Please read the help !"
290 show_help
Erwan Veluafbbd642013-06-25 17:47:01 +0200291 exit 1
292fi
293
294}
295
Erwan Velu60238f02013-07-12 15:21:25 +0200296check_mode_order() {
297FOUND_WRITE="NO"
298CAUSE="You are reading data before writing them "
299
300# If no write occurs, let's show a different message
301echo $MODES | grep -q "write"
302if [ "$?" -ne 0 ]; then
303 CAUSE="You are reading data while never wrote them before"
304fi
305
306for mode in $(echo $MODES | tr "," " "); do
307 echo $mode | grep -q write
308 if [ "$?" -eq 0 ]; then
309 FOUND_WRITE="YES"
310 fi
311 echo $mode | grep -q "read"
312 if [ "$?" -eq 0 ]; then
313 if [ "$FOUND_WRITE" = "NO" ]; then
314 echo "###############################################################"
315 echo "# Warning : $CAUSE#"
316 echo "# On some storage devices, this could lead to invalid results #"
317 echo "# #"
318 echo "# Press Ctrl-C to adjust pattern order if you have doubts #"
319 echo "# Or Wait 5 seconds before the file will be created #"
320 echo "###############################################################"
321 sleep 5
322 # No need to try showing the message more than one time
323 return
324 fi
325 fi
326done
327}
328
Erwan Veluafbbd642013-06-25 17:47:01 +0200329
330########## MAIN
Erwan Veluafbbd642013-06-25 17:47:01 +0200331gen_template
Erwan Velu3b73c532013-07-15 12:33:44 +0200332parse_cmdline "$@"
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200333finish_template
334check_mode_order
Erwan Veluafbbd642013-06-25 17:47:01 +0200335
336echo "Generating $OUTFILE"
337cp -f $TEMPLATE $OUTFILE
338echo >> $OUTFILE
339
340for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
341 gen_fio
342done
343ETA_H=$(($ETA / 3600))
344ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
Erwan Veluaf360e32013-07-11 10:16:05 +0200345if [ "$ETA" = "0" ]; then
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200346 echo "Cannot estimate ETA as RUNTIME=0"
347else
348 echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
349fi