blob: 6d3220daf1a4d93568a20f5950272a8f1198ac37 [file] [log] [blame]
Erwan Veluafbbd642013-06-25 17:47:01 +02001#!/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
Erwan Velu60238f02013-07-12 15:21:25 +020030MODES="write,randwrite,read,randread"
Erwan Veluafbbd642013-06-25 17:47:01 +020031SHORT_HOSTNAME=
Erwan Velu76c7c632013-07-10 16:44:24 +020032CACHED_IO="FALSE"
Erwan Velua7419832013-07-11 09:56:28 +020033PREFIX=""
34PREFIX_FILENAME=""
Erwan Velu7d1ca6c2013-07-12 17:01:31 +020035IODEPTH=1
Erwan Veluafbbd642013-06-25 17:47:01 +020036
37show_help() {
38 PROG=$(basename $0)
39 echo "usage of $PROG:"
40 cat << EOF
41-h : Show this help & exit
Erwan Velu76c7c632013-07-10 16:44:24 +020042-c : Enable cached-based IOs
Erwan Velue1c6f2e2013-07-10 16:50:20 +020043 Disabled by default
Erwan Veluafbbd642013-06-25 17:47:01 +020044-a : Run sequential test then parallel one
Erwan Velue1c6f2e2013-07-10 16:50:20 +020045 Disabled by default
Erwan Veluafbbd642013-06-25 17:47:01 +020046-s : Run sequential test (default value)
47 one test after another then one disk after another
Erwan Velue1c6f2e2013-07-10 16:50:20 +020048 Disabled by default
Erwan Veluafbbd642013-06-25 17:47:01 +020049-p : Run parallel test
50 one test after anoter but all disks at the same time
Erwan Velue1c6f2e2013-07-10 16:50:20 +020051 Enabled by default
Erwan Velu7d1ca6c2013-07-12 17:01:31 +020052-D iodepth : Run with the specified iodepth
53 Default is 32
Erwan Veluafbbd642013-06-25 17:47:01 +020054-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
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 Velue1c6f2e2013-07-10 16:50:20 +020059 Default is 300 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 Velue1c6f2e2013-07-10 16:50:20 +020062 Default is 4k
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 Velu60238f02013-07-12 15:21:25 +020064 Default is "write,randwrite,read,randread"
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 Veluafbbd642013-06-25 17:47:01 +020068
69Example:
70
Erwan Velua7419832013-07-11 09:56:28 +020071$PROG -d sdb,sdc,sdd,sde -a -b 4k,128k,1m -r 100 -a -x dellr720-day2/
Erwan Veluafbbd642013-06-25 17:47:01 +020072
73 Will generate an fio file that will run
Erwan Velu60238f02013-07-12 15:21:25 +020074 - 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 +020075 ETA ~ 4 tests * 4 disks * 100 seconds
Erwan Velu60238f02013-07-12 15:21:25 +020076 - 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 +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 = 1m 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 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 +020081 ETA ~ 4 tests * 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 = 128k 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 = 1m with write,randwrite,read,randread tests
Erwan Veluafbbd642013-06-25 17:47:01 +020085 ETA ~ 4 tests * 100 seconds
86
Erwan Velu60238f02013-07-12 15:21:25 +020087Generating dellr720-day2/localhost-4k,128k,1m-all-write,randwrite,read,randread-sdb,sdc,sdd,sde.fio
Erwan Veluafbbd642013-06-25 17:47:01 +020088Estimated Time = 6000 seconds : 1 hour 40 minutes
89EOF
90}
91
92gen_template() {
93cat >$TEMPLATE << EOF
94[global]
95ioengine=libaio
Erwan Velu7d1ca6c2013-07-12 17:01:31 +020096iodepth=$IODEPTH
Erwan Veluafbbd642013-06-25 17:47:01 +020097invalidate=1
Erwan Veluafbbd642013-06-25 17:47:01 +020098ramp_time=5
Erwan Veluafbbd642013-06-25 17:47:01 +020099EOF
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200100
101if [ "$RUNTIME" != "0" ]; then
102cat >>$TEMPLATE << EOF
103runtime=$RUNTIME
Erwan Velud1415112013-07-12 17:13:59 +0200104time_based
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200105EOF
106fi
107
Erwan Velu76c7c632013-07-10 16:44:24 +0200108if [ "$CACHED_IO" = "FALSE" ]; then
109cat >>$TEMPLATE << EOF
110direct=1
111EOF
112fi
113
Erwan Veluafbbd642013-06-25 17:47:01 +0200114}
115
116gen_seq_suite() {
117TYPE=$1
118cat >> $OUTFILE << EOF
119[$TYPE-$disk-$BLK_SIZE-seq]
120stonewall
121bs=$BLK_SIZE
122filename=/dev/$disk
123rw=$TYPE
Erwan Velua7419832013-07-11 09:56:28 +0200124write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
125write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
Erwan Veluafbbd642013-06-25 17:47:01 +0200126EOF
127ETA=$(($ETA + $RUNTIME))
128}
129
130gen_seq_fio() {
131for disk in $(echo $DISKS | tr "," " "); do
132 for mode in $(echo $MODES | tr "," " "); do
133 gen_seq_suite "$mode"
134 done
135done
136}
137
138
139gen_para_suite() {
140TYPE=$1
141NEED_WALL=$2
142D=0
143for disk in $(echo $DISKS | tr "," " "); do
144 cat >> $OUTFILE << EOF
145[$TYPE-$disk-$BLK_SIZE-para]
146bs=$BLK_SIZE
147EOF
148
149if [ "$D" = 0 ]; then
150 echo "stonewall" >> $OUTFILE
151 D=1
152fi
153
154cat >> $OUTFILE << EOF
155filename=/dev/$disk
156rw=$TYPE
Erwan Velua7419832013-07-11 09:56:28 +0200157write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
158write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
Erwan Veluafbbd642013-06-25 17:47:01 +0200159EOF
160done
161
162ETA=$(($ETA + $RUNTIME))
163echo >> $OUTFILE
164}
165
166gen_para_fio() {
167for mode in $(echo $MODES | tr "," " "); do
168 gen_para_suite "$mode"
169done
170}
171
172gen_fio() {
173case $SEQ in
174 2)
175 gen_seq_fio
176 gen_para_fio
177 ;;
178 1)
179 gen_seq_fio
180 ;;
181 0)
182 gen_para_fio
183 ;;
184esac
185}
186
187parse_cmdline() {
Erwan Velu7d1ca6c2013-07-12 17:01:31 +0200188while getopts "hacpsd:b:r:m:x:D:" opt; do
Erwan Veluafbbd642013-06-25 17:47:01 +0200189 case $opt in
190 h)
191 show_help
192 exit 0
193 ;;
194 b)
195 BLOCK_SIZE=$OPTARG
196 ;;
Erwan Velu76c7c632013-07-10 16:44:24 +0200197 c)
198 CACHED_IO="TRUE"
199 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200200 s)
201 if [ "$SEQ" = "-1" ]; then
202 SEQ=1
203 fi
204 ;;
Erwan Velua7419832013-07-11 09:56:28 +0200205 x)
206 PREFIX=$OPTARG
207 echo "$PREFIX" | grep -q "/"
208 if [ "$?" -eq 0 ]; then
209 mkdir -p $PREFIX
210 # No need to keep the prefix for the log files
211 # we do have a directory for that
212 PREFIX_FILENAME=""
213 else
214 # We need to keep the prefix for the log files
215 PREFIX_FILENAME=$PREFIX
216 fi
217 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200218 r)
219 RUNTIME=$OPTARG
220 ;;
221 p)
222 if [ "$SEQ" = "-1" ]; then
223 SEQ=0
224 fi
225 ;;
226 m)
227 MODES=$OPTARG;
228 ;;
229 d)
230 DISKS=$OPTARG
231 ;;
Erwan Velu7d1ca6c2013-07-12 17:01:31 +0200232 D)
233 IODEPTH=$OPTARG
234 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200235 a)
236 SEQ=2
237 ;;
238 \?)
239 echo "Invalid option: -$OPTARG" >&2
240 ;;
241 esac
242done
243
244if [ "$SEQ" = "-1" ]; then
245 SEQ=0
246fi
247
248SHORT_HOSTNAME=$(hostname -s)
249case $SEQ in
250 2)
Erwan Velua7419832013-07-11 09:56:28 +0200251 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200252 ;;
253
254 1)
Erwan Velua7419832013-07-11 09:56:28 +0200255 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200256 ;;
257 0)
Erwan Velua7419832013-07-11 09:56:28 +0200258 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200259 ;;
260esac
261
262if [ -z "$DISKS" ]; then
263 echo "Missing DISKS !"
Erwan Velue1c6f2e2013-07-10 16:50:20 +0200264 echo "Please read the help !"
265 show_help
Erwan Veluafbbd642013-06-25 17:47:01 +0200266 exit 1
267fi
268
269}
270
Erwan Velu60238f02013-07-12 15:21:25 +0200271check_mode_order() {
272FOUND_WRITE="NO"
273CAUSE="You are reading data before writing them "
274
275# If no write occurs, let's show a different message
276echo $MODES | grep -q "write"
277if [ "$?" -ne 0 ]; then
278 CAUSE="You are reading data while never wrote them before"
279fi
280
281for mode in $(echo $MODES | tr "," " "); do
282 echo $mode | grep -q write
283 if [ "$?" -eq 0 ]; then
284 FOUND_WRITE="YES"
285 fi
286 echo $mode | grep -q "read"
287 if [ "$?" -eq 0 ]; then
288 if [ "$FOUND_WRITE" = "NO" ]; then
289 echo "###############################################################"
290 echo "# Warning : $CAUSE#"
291 echo "# On some storage devices, this could lead to invalid results #"
292 echo "# #"
293 echo "# Press Ctrl-C to adjust pattern order if you have doubts #"
294 echo "# Or Wait 5 seconds before the file will be created #"
295 echo "###############################################################"
296 sleep 5
297 # No need to try showing the message more than one time
298 return
299 fi
300 fi
301done
302}
303
Erwan Veluafbbd642013-06-25 17:47:01 +0200304
305########## MAIN
306parse_cmdline $@
Erwan Velu60238f02013-07-12 15:21:25 +0200307check_mode_order
Erwan Veluafbbd642013-06-25 17:47:01 +0200308gen_template
309
310echo "Generating $OUTFILE"
311cp -f $TEMPLATE $OUTFILE
312echo >> $OUTFILE
313
314for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
315 gen_fio
316done
317ETA_H=$(($ETA / 3600))
318ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
Erwan Veluaf360e32013-07-11 10:16:05 +0200319if [ "$ETA" = "0" ]; then
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200320 echo "Cannot estimate ETA as RUNTIME=0"
321else
322 echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
323fi