blob: 49cbd5032b7a51773fc1ff8ed65953cd65fb54dc [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 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 Velua7419832013-07-11 09:56:28 +020073$PROG -d sdb,sdc,sdd,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() {
95cat >>$TEMPLATE <<EOF
Erwan Velu7d1ca6c2013-07-12 17:01:31 +020096iodepth=$IODEPTH
Erwan Veluafbbd642013-06-25 17:47:01 +020097EOF
Erwan Velu72fe3ef2013-07-10 16:38:33 +020098
99if [ "$RUNTIME" != "0" ]; then
100cat >>$TEMPLATE << EOF
101runtime=$RUNTIME
Erwan Velud1415112013-07-12 17:13:59 +0200102time_based
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200103EOF
104fi
105
Erwan Velu76c7c632013-07-10 16:44:24 +0200106if [ "$CACHED_IO" = "FALSE" ]; then
107cat >>$TEMPLATE << EOF
108direct=1
109EOF
110fi
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200111}
Erwan Velu76c7c632013-07-10 16:44:24 +0200112
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200113gen_template() {
114cat >$TEMPLATE << EOF
115[global]
116ioengine=libaio
117invalidate=1
118ramp_time=5
119EOF
Erwan Veluafbbd642013-06-25 17:47:01 +0200120}
121
122gen_seq_suite() {
123TYPE=$1
124cat >> $OUTFILE << EOF
125[$TYPE-$disk-$BLK_SIZE-seq]
126stonewall
127bs=$BLK_SIZE
128filename=/dev/$disk
129rw=$TYPE
Erwan Velua7419832013-07-11 09:56:28 +0200130write_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
Erwan Veluafbbd642013-06-25 17:47:01 +0200132EOF
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
Erwan Velua7419832013-07-11 09:56:28 +0200163write_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
Erwan Veluafbbd642013-06-25 17:47:01 +0200165EOF
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() {
Erwan Veluca143752013-07-15 11:10:27 +0200194while getopts "hacpsd:b:r:m:x:D:A:B:" opt; do
Erwan Veluafbbd642013-06-25 17:47:01 +0200195 case $opt in
196 h)
197 show_help
198 exit 0
199 ;;
200 b)
201 BLOCK_SIZE=$OPTARG
202 ;;
Erwan Velu76c7c632013-07-10 16:44:24 +0200203 c)
204 CACHED_IO="TRUE"
205 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200206 s)
207 if [ "$SEQ" = "-1" ]; then
208 SEQ=1
209 fi
210 ;;
Erwan Velua7419832013-07-11 09:56:28 +0200211 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 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200224 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 ;;
Erwan Velu7d1ca6c2013-07-12 17:01:31 +0200238 D)
239 IODEPTH=$OPTARG
240 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200241 a)
242 SEQ=2
243 ;;
Erwan Veluca143752013-07-15 11:10:27 +0200244 B)
245 echo "exec_prerun=$OPTARG" >> $TEMPLATE
246 ;;
247 A)
248 echo "exec_postrun=$OPTARG" >> $TEMPLATE
249 ;;
Erwan Veluafbbd642013-06-25 17:47:01 +0200250 \?)
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)
Erwan Velua7419832013-07-11 09:56:28 +0200263 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200264 ;;
265
266 1)
Erwan Velua7419832013-07-11 09:56:28 +0200267 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200268 ;;
269 0)
Erwan Velua7419832013-07-11 09:56:28 +0200270 OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$DISKS.fio
Erwan Veluafbbd642013-06-25 17:47:01 +0200271 ;;
272esac
273
274if [ -z "$DISKS" ]; then
275 echo "Missing DISKS !"
Erwan Velue1c6f2e2013-07-10 16:50:20 +0200276 echo "Please read the help !"
277 show_help
Erwan Veluafbbd642013-06-25 17:47:01 +0200278 exit 1
279fi
280
281}
282
Erwan Velu60238f02013-07-12 15:21:25 +0200283check_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
Erwan Veluafbbd642013-06-25 17:47:01 +0200316
317########## MAIN
Erwan Veluafbbd642013-06-25 17:47:01 +0200318gen_template
Erwan Velufdc0f3b2013-07-15 10:44:58 +0200319parse_cmdline $@
320finish_template
321check_mode_order
Erwan Veluafbbd642013-06-25 17:47:01 +0200322
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))
Erwan Veluaf360e32013-07-11 10:16:05 +0200332if [ "$ETA" = "0" ]; then
Erwan Velu72fe3ef2013-07-10 16:38:33 +0200333 echo "Cannot estimate ETA as RUNTIME=0"
334else
335 echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes"
336fi