Commit | Line | Data |
---|---|---|
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 | ||
22 | BLK_SIZE= | |
23 | BLOCK_SIZE=4k | |
24 | SEQ=-1 | |
25 | TEMPLATE=/tmp/template.fio | |
26 | OUTFILE= | |
27 | DISKS= | |
28 | RUNTIME=300 | |
29 | ETA=0 | |
30 | MODES="read,write,randread,randwrite" | |
31 | SHORT_HOSTNAME= | |
76c7c63e | 32 | CACHED_IO="FALSE" |
afbbd646 EV |
33 | |
34 | show_help() { | |
35 | PROG=$(basename $0) | |
36 | echo "usage of $PROG:" | |
37 | cat << EOF | |
38 | -h : Show this help & exit | |
76c7c63e | 39 | -c : Enable cached-based IOs |
e1c6f2e1 | 40 | Disabled by default |
afbbd646 | 41 | -a : Run sequential test then parallel one |
e1c6f2e1 | 42 | Disabled by default |
afbbd646 EV |
43 | -s : Run sequential test (default value) |
44 | one test after another then one disk after another | |
e1c6f2e1 | 45 | Disabled by default |
afbbd646 EV |
46 | -p : Run parallel test |
47 | one test after anoter but all disks at the same time | |
e1c6f2e1 | 48 | Enabled by default |
afbbd646 EV |
49 | -d disk1[,disk2,disk3,..] : Run the tests on the selected disks |
50 | Separated each disk with a comma | |
51 | Disk name shall be "sdxx", /dev/ shall NOT be used here | |
e1c6f2e1 | 52 | -r seconds : Time in seconds per benchmark |
72fe3ef1 | 53 | 0 means till the end of the device |
e1c6f2e1 | 54 | Default is 300 seconds |
afbbd646 EV |
55 | -b blocksize[,blocksize1, ...] : The blocksizes to test under fio format (4k, 1m, ...) |
56 | Separated each blocksize with a comma | |
e1c6f2e1 | 57 | Default is 4k |
afbbd646 | 58 | -m mode1,[mode2,mode3, ...] : Define the fio IO profile to use like read, write, randread, randwrite |
e1c6f2e1 | 59 | Default is "read,write,randread,randwrite" |
afbbd646 EV |
60 | |
61 | Example: | |
62 | ||
63 | $PROG -d sdb,sdc,sdd,sde -a -b 4k,128k,1m -r 100 -a | |
64 | ||
65 | Will generate an fio file that will run | |
66 | - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with read,write,randread,randwrite tests | |
67 | ETA ~ 4 tests * 4 disks * 100 seconds | |
68 | - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with read,write,randread,randwrite tests | |
69 | ETA ~ 4 tests * 4 disks * 100 seconds | |
70 | - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with read,write,randread,randwrite tests | |
71 | ETA ~ 4 tests * 4 disks * 100 seconds | |
72 | - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with read,write,randread,randwrite tests | |
73 | ETA ~ 4 tests * 100 seconds | |
74 | - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with read,write,randread,randwrite tests | |
75 | ETA ~ 4 tests * 100 seconds | |
76 | - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with read,write,randread,randwrite tests | |
77 | ETA ~ 4 tests * 100 seconds | |
78 | ||
79 | Generating localhost-4k,128k,1m-all-read,write,randread,randwrite-sdb,sdc,sdd,sde.fio | |
80 | Estimated Time = 6000 seconds : 1 hour 40 minutes | |
81 | EOF | |
82 | } | |
83 | ||
84 | gen_template() { | |
85 | cat >$TEMPLATE << EOF | |
86 | [global] | |
87 | ioengine=libaio | |
88 | invalidate=1 | |
afbbd646 | 89 | ramp_time=5 |
72fe3ef1 | 90 | EOF |
afbbd646 | 91 | |
72fe3ef1 EV |
92 | if [ "$RUNTIME" != "0" ]; then |
93 | cat >>$TEMPLATE << EOF | |
94 | runtime=$RUNTIME | |
afbbd646 | 95 | EOF |
72fe3ef1 EV |
96 | fi |
97 | ||
76c7c63e EV |
98 | if [ "$CACHED_IO" = "FALSE" ]; then |
99 | cat >>$TEMPLATE << EOF | |
100 | direct=1 | |
101 | EOF | |
102 | fi | |
103 | ||
afbbd646 EV |
104 | } |
105 | ||
106 | gen_seq_suite() { | |
107 | TYPE=$1 | |
108 | cat >> $OUTFILE << EOF | |
109 | [$TYPE-$disk-$BLK_SIZE-seq] | |
110 | stonewall | |
111 | bs=$BLK_SIZE | |
112 | filename=/dev/$disk | |
113 | rw=$TYPE | |
114 | write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results | |
115 | write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-seq.results | |
116 | EOF | |
117 | ETA=$(($ETA + $RUNTIME)) | |
118 | } | |
119 | ||
120 | gen_seq_fio() { | |
121 | for disk in $(echo $DISKS | tr "," " "); do | |
122 | for mode in $(echo $MODES | tr "," " "); do | |
123 | gen_seq_suite "$mode" | |
124 | done | |
125 | done | |
126 | } | |
127 | ||
128 | ||
129 | gen_para_suite() { | |
130 | TYPE=$1 | |
131 | NEED_WALL=$2 | |
132 | D=0 | |
133 | for disk in $(echo $DISKS | tr "," " "); do | |
134 | cat >> $OUTFILE << EOF | |
135 | [$TYPE-$disk-$BLK_SIZE-para] | |
136 | bs=$BLK_SIZE | |
137 | EOF | |
138 | ||
139 | if [ "$D" = 0 ]; then | |
140 | echo "stonewall" >> $OUTFILE | |
141 | D=1 | |
142 | fi | |
143 | ||
144 | cat >> $OUTFILE << EOF | |
145 | filename=/dev/$disk | |
146 | rw=$TYPE | |
147 | write_bw_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results | |
148 | write_iops_log=$SHORT_HOSTNAME-$BLK_SIZE-$disk-$TYPE-para.results | |
149 | EOF | |
150 | done | |
151 | ||
152 | ETA=$(($ETA + $RUNTIME)) | |
153 | echo >> $OUTFILE | |
154 | } | |
155 | ||
156 | gen_para_fio() { | |
157 | for mode in $(echo $MODES | tr "," " "); do | |
158 | gen_para_suite "$mode" | |
159 | done | |
160 | } | |
161 | ||
162 | gen_fio() { | |
163 | case $SEQ in | |
164 | 2) | |
165 | gen_seq_fio | |
166 | gen_para_fio | |
167 | ;; | |
168 | 1) | |
169 | gen_seq_fio | |
170 | ;; | |
171 | 0) | |
172 | gen_para_fio | |
173 | ;; | |
174 | esac | |
175 | } | |
176 | ||
177 | parse_cmdline() { | |
76c7c63e | 178 | while getopts "hacpsd:b:r:m:" opt; do |
afbbd646 EV |
179 | case $opt in |
180 | h) | |
181 | show_help | |
182 | exit 0 | |
183 | ;; | |
184 | b) | |
185 | BLOCK_SIZE=$OPTARG | |
186 | ;; | |
76c7c63e EV |
187 | c) |
188 | CACHED_IO="TRUE" | |
189 | ;; | |
afbbd646 EV |
190 | s) |
191 | if [ "$SEQ" = "-1" ]; then | |
192 | SEQ=1 | |
193 | fi | |
194 | ;; | |
195 | r) | |
196 | RUNTIME=$OPTARG | |
197 | ;; | |
198 | p) | |
199 | if [ "$SEQ" = "-1" ]; then | |
200 | SEQ=0 | |
201 | fi | |
202 | ;; | |
203 | m) | |
204 | MODES=$OPTARG; | |
205 | ;; | |
206 | d) | |
207 | DISKS=$OPTARG | |
208 | ;; | |
209 | a) | |
210 | SEQ=2 | |
211 | ;; | |
212 | \?) | |
213 | echo "Invalid option: -$OPTARG" >&2 | |
214 | ;; | |
215 | esac | |
216 | done | |
217 | ||
218 | if [ "$SEQ" = "-1" ]; then | |
219 | SEQ=0 | |
220 | fi | |
221 | ||
222 | SHORT_HOSTNAME=$(hostname -s) | |
223 | case $SEQ in | |
224 | 2) | |
225 | OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$DISKS.fio | |
226 | ;; | |
227 | ||
228 | 1) | |
229 | OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$DISKS.fio | |
230 | ;; | |
231 | 0) | |
232 | OUTFILE=$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$DISKS.fio | |
233 | ;; | |
234 | esac | |
235 | ||
236 | if [ -z "$DISKS" ]; then | |
237 | echo "Missing DISKS !" | |
e1c6f2e1 EV |
238 | echo "Please read the help !" |
239 | show_help | |
afbbd646 EV |
240 | exit 1 |
241 | fi | |
242 | ||
243 | } | |
244 | ||
245 | ||
246 | ########## MAIN | |
247 | parse_cmdline $@ | |
248 | gen_template | |
249 | ||
250 | echo "Generating $OUTFILE" | |
251 | cp -f $TEMPLATE $OUTFILE | |
252 | echo >> $OUTFILE | |
253 | ||
254 | for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do | |
255 | gen_fio | |
256 | done | |
257 | ETA_H=$(($ETA / 3600)) | |
258 | ETA_M=$((($ETA - ($ETA_H*3600)) / 60)) | |
72fe3ef1 EV |
259 | if [ "$ETA_M" = "0" ]; then |
260 | echo "Cannot estimate ETA as RUNTIME=0" | |
261 | else | |
262 | echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes" | |
263 | fi |