blob: 3f9ab283840a54bef1c1ae2ef70bf2e1ccc7d759 [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
Erwan Velufdc0f3b2013-07-15 10:44:58 +020092finish_template() {
93cat >>$TEMPLATE <<EOF
Erwan Velu7d1ca6c2013-07-12 17:01:31 +020094iodepth=$IODEPTH
Erwan Veluafbbd642013-06-25 17:47:01 +020095EOF
Erwan Velu72fe3ef2013-07-10 16:38:33 +020096
97if [ "$RUNTIME" != "0" ]; then
98cat >>$TEMPLATE << EOF
99runtime=$RUNTIME
Erwan Velud1415112013-07-12 17:13:59 +0200100time_based
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200101EOF
102fi
103
Erwan Velu76c7c632013-07-10 16:44:24 +0200104if [ "$CACHED_IO" = "FALSE" ]; then
105cat >>$TEMPLATE << EOF
106direct=1
107EOF
108fi
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200109}
Erwan Velu76c7c632013-07-10 16:44:24 +0200110
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200111gen_template() {
112cat >$TEMPLATE << EOF
113[global]
114ioengine=libaio
115invalidate=1
116ramp_time=5
117EOF
Erwan Veluafbbd642013-06-25 17:47:01 +0200118}
119
120gen_seq_suite() {
121TYPE=$1
122cat >> $OUTFILE << EOF
123[$TYPE-$disk-$BLK_SIZE-seq]
124stonewall
125bs=$BLK_SIZE
126filename=/dev/$disk
127rw=$TYPE
Erwan Velua7419832013-07-11 09:56:28 +0200128write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
129write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results
Erwan Veluafbbd642013-06-25 17:47:01 +0200130EOF
131ETA=$(($ETA + $RUNTIME))
132}
133
134gen_seq_fio() {
135for disk in $(echo $DISKS | tr "," " "); do
136 for mode in $(echo $MODES | tr "," " "); do
137 gen_seq_suite "$mode"
138 done
139done
140}
141
142
143gen_para_suite() {
144TYPE=$1
145NEED_WALL=$2
146D=0
147for disk in $(echo $DISKS | tr "," " "); do
148 cat >> $OUTFILE << EOF
149[$TYPE-$disk-$BLK_SIZE-para]
150bs=$BLK_SIZE
151EOF
152
153if [ "$D" = 0 ]; then
154 echo "stonewall" >> $OUTFILE
155 D=1
156fi
157
158cat >> $OUTFILE << EOF
159filename=/dev/$disk
160rw=$TYPE
Erwan Velua7419832013-07-11 09:56:28 +0200161write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
162write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results
Erwan Veluafbbd642013-06-25 17:47:01 +0200163EOF
164done
165
166ETA=$(($ETA + $RUNTIME))
167echo >> $OUTFILE
168}
169
170gen_para_fio() {
171for mode in $(echo $MODES | tr "," " "); do
172 gen_para_suite "$mode"
173done
174}
175
176gen_fio() {
177case $SEQ in
178 2)
179 gen_seq_fio
180 gen_para_fio
181 ;;
182 1)
183 gen_seq_fio
184 ;;
185 0)
186 gen_para_fio
187 ;;
188esac
189}
190
191parse_cmdline() {
Erwan Velu7d1ca6c2013-07-12 17:01:31 +0200192while getopts "hacpsd:b:r:m:x:D:" opt; do
Erwan Veluafbbd642013-06-25 17:47:01 +0200193 case $opt in
194 h)
195 show_help
196 exit 0
197 ;;
198 b)
199 BLOCK_SIZE=$OPTARG
200 ;;
Erwan Velu76c7c632013-07-10 16:44:24 +0200201 c)
202 CACHED_IO="TRUE"
203 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200204 s)
205 if [ "$SEQ" = "-1" ]; then
206 SEQ=1
207 fi
208 ;;
Erwan Velua7419832013-07-11 09:56:28 +0200209 x)
210 PREFIX=$OPTARG
211 echo "$PREFIX" | grep -q "/"
212 if [ "$?" -eq 0 ]; then
213 mkdir -p $PREFIX
214 # No need to keep the prefix for the log files
215 # we do have a directory for that
216 PREFIX_FILENAME=""
217 else
218 # We need to keep the prefix for the log files
219 PREFIX_FILENAME=$PREFIX
220 fi
221 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200222 r)
223 RUNTIME=$OPTARG
224 ;;
225 p)
226 if [ "$SEQ" = "-1" ]; then
227 SEQ=0
228 fi
229 ;;
230 m)
231 MODES=$OPTARG;
232 ;;
233 d)
234 DISKS=$OPTARG
235 ;;
Erwan Velu7d1ca6c2013-07-12 17:01:31 +0200236 D)
237 IODEPTH=$OPTARG
238 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200239 a)
240 SEQ=2
241 ;;
242 \?)
243 echo "Invalid option: -$OPTARG" >&2
244 ;;
245 esac
246done
247
248if [ "$SEQ" = "-1" ]; then
249 SEQ=0
250fi
251
252SHORT_HOSTNAME=$(hostname -s)
253case $SEQ in
254 2)
Erwan Velua7419832013-07-11 09:56:28 +0200255 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200256 ;;
257
258 1)
Erwan Velua7419832013-07-11 09:56:28 +0200259 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200260 ;;
261 0)
Erwan Velua7419832013-07-11 09:56:28 +0200262 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200263 ;;
264esac
265
266if [ -z "$DISKS" ]; then
267 echo "Missing DISKS !"
Erwan Velue1c6f2e2013-07-10 16:50:20 +0200268 echo "Please read the help !"
269 show_help
Erwan Veluafbbd642013-06-25 17:47:01 +0200270 exit 1
271fi
272
273}
274
Erwan Velu60238f02013-07-12 15:21:25 +0200275check_mode_order() {
276FOUND_WRITE="NO"
277CAUSE="You are reading data before writing them "
278
279# If no write occurs, let's show a different message
280echo $MODES | grep -q "write"
281if [ "$?" -ne 0 ]; then
282 CAUSE="You are reading data while never wrote them before"
283fi
284
285for mode in $(echo $MODES | tr "," " "); do
286 echo $mode | grep -q write
287 if [ "$?" -eq 0 ]; then
288 FOUND_WRITE="YES"
289 fi
290 echo $mode | grep -q "read"
291 if [ "$?" -eq 0 ]; then
292 if [ "$FOUND_WRITE" = "NO" ]; then
293 echo "###############################################################"
294 echo "# Warning : $CAUSE#"
295 echo "# On some storage devices, this could lead to invalid results #"
296 echo "# #"
297 echo "# Press Ctrl-C to adjust pattern order if you have doubts #"
298 echo "# Or Wait 5 seconds before the file will be created #"
299 echo "###############################################################"
300 sleep 5
301 # No need to try showing the message more than one time
302 return
303 fi
304 fi
305done
306}
307
Erwan Veluafbbd642013-06-25 17:47:01 +0200308
309########## MAIN
Erwan Veluafbbd642013-06-25 17:47:01 +0200310gen_template
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200311parse_cmdline $@
312finish_template
313check_mode_order
Erwan Veluafbbd642013-06-25 17:47:01 +0200314
315echo "Generating $OUTFILE"
316cp -f $TEMPLATE $OUTFILE
317echo >> $OUTFILE
318
319for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do
320 gen_fio
321done
322ETA_H=$(($ETA / 3600))
323ETA_M=$((($ETA - ($ETA_H*3600)) / 60))
Erwan Veluaf360e32013-07-11 10:16:05 +0200324if [ "$ETA" = "0" ]; then
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200325 echo "Cannot estimate ETA as RUNTIME=0"
326else
327 echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
328fi