Commit | Line | Data |
---|---|---|
10ee8843 | 1 | #!/bin/bash |
afbbd646 EV |
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 | |
fa07eaa6 | 20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
afbbd646 EV |
21 | |
22 | BLK_SIZE= | |
23 | BLOCK_SIZE=4k | |
24 | SEQ=-1 | |
31952e1d VS |
25 | TEMPLATE=$(mktemp "${TMPDIR:-${TEMP:-/tmp}}/template.fio.XXXXXX") || exit $? |
26 | trap 'rm -f "$TEMPLATE"' EXIT | |
afbbd646 EV |
27 | OUTFILE= |
28 | DISKS= | |
bed59bab | 29 | PRINTABLE_DISKS= |
afbbd646 EV |
30 | RUNTIME=300 |
31 | ETA=0 | |
60238f0e | 32 | MODES="write,randwrite,read,randread" |
afbbd646 | 33 | SHORT_HOSTNAME= |
76c7c63e | 34 | CACHED_IO="FALSE" |
a7419837 EV |
35 | PREFIX="" |
36 | PREFIX_FILENAME="" | |
7d1ca6cf | 37 | IODEPTH=1 |
afbbd646 EV |
38 | |
39 | show_help() { | |
40 | PROG=$(basename $0) | |
41 | echo "usage of $PROG:" | |
42 | cat << EOF | |
43 | -h : Show this help & exit | |
76c7c63e | 44 | -c : Enable cached-based IOs |
e1c6f2e1 | 45 | Disabled by default |
afbbd646 | 46 | -a : Run sequential test then parallel one |
e1c6f2e1 | 47 | Disabled by default |
afbbd646 EV |
48 | -s : Run sequential test (default value) |
49 | one test after another then one disk after another | |
e1c6f2e1 | 50 | Disabled by default |
afbbd646 | 51 | -p : Run parallel test |
fc002f14 | 52 | one test after another but all disks at the same time |
e1c6f2e1 | 53 | Enabled by default |
7d1ca6cf | 54 | -D iodepth : Run with the specified iodepth |
80139d2d | 55 | Default is $IODEPTH |
afbbd646 EV |
56 | -d disk1[,disk2,disk3,..] : Run the tests on the selected disks |
57 | Separated each disk with a comma | |
f6facd21 LM |
58 | -z filesize : Specify the working file size, if you are passing filepaths to -d |
59 | Disabled by default | |
e1c6f2e1 | 60 | -r seconds : Time in seconds per benchmark |
72fe3ef1 | 61 | 0 means till the end of the device |
80139d2d | 62 | Default is $RUNTIME seconds |
afbbd646 EV |
63 | -b blocksize[,blocksize1, ...] : The blocksizes to test under fio format (4k, 1m, ...) |
64 | Separated each blocksize with a comma | |
80139d2d | 65 | Default is $BLOCK_SIZE |
afbbd646 | 66 | -m mode1,[mode2,mode3, ...] : Define the fio IO profile to use like read, write, randread, randwrite |
80139d2d | 67 | Default is "$MODES" |
a7419837 EV |
68 | -x prefix : Add a prefix to the fio filename |
69 | Useful to let a context associated with the file | |
70 | If the prefix features a / (slash), prefix will be considered as a directory | |
ca143750 EV |
71 | -A cmd_to_run : System command to run after each job (exec_postrun in fio) |
72 | -B cmd_to_run : System command to run before each job (exec_prerun in fio) | |
afbbd646 EV |
73 | |
74 | Example: | |
75 | ||
bed59bab | 76 | $PROG -d /dev/sdb,/dev/sdc,/dev/sdd,/dev/sde -a -b 4k,128k,1m -r 100 -a -x dellr720-day2/ |
afbbd646 EV |
77 | |
78 | Will generate an fio file that will run | |
60238f0e | 79 | - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with write,randwrite,read,randread tests |
afbbd646 | 80 | ETA ~ 4 tests * 4 disks * 100 seconds |
60238f0e | 81 | - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with write,randwrite,read,randread tests |
afbbd646 | 82 | ETA ~ 4 tests * 4 disks * 100 seconds |
60238f0e | 83 | - a sequential bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with write,randwrite,read,randread tests |
afbbd646 | 84 | ETA ~ 4 tests * 4 disks * 100 seconds |
60238f0e | 85 | - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 4k with write,randwrite,read,randread tests |
afbbd646 | 86 | ETA ~ 4 tests * 100 seconds |
60238f0e | 87 | - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 128k with write,randwrite,read,randread tests |
afbbd646 | 88 | ETA ~ 4 tests * 100 seconds |
60238f0e | 89 | - a parallel bench on /dev/sdb /dev/sdc /dev/sdd /dev/sde for block size = 1m with write,randwrite,read,randread tests |
afbbd646 EV |
90 | ETA ~ 4 tests * 100 seconds |
91 | ||
60238f0e | 92 | Generating dellr720-day2/localhost-4k,128k,1m-all-write,randwrite,read,randread-sdb,sdc,sdd,sde.fio |
afbbd646 EV |
93 | Estimated Time = 6000 seconds : 1 hour 40 minutes |
94 | EOF | |
95 | } | |
96 | ||
fdc0f3b6 | 97 | finish_template() { |
ea0542d9 | 98 | echo "iodepth=$IODEPTH" >> $TEMPLATE |
afbbd646 | 99 | |
72fe3ef1 | 100 | if [ "$RUNTIME" != "0" ]; then |
ea0542d9 EV |
101 | echo "runtime=$RUNTIME" >> $TEMPLATE |
102 | echo "time_based" >> $TEMPLATE | |
72fe3ef1 EV |
103 | fi |
104 | ||
76c7c63e | 105 | if [ "$CACHED_IO" = "FALSE" ]; then |
ea0542d9 | 106 | echo "direct=1" >> $TEMPLATE |
76c7c63e | 107 | fi |
fdc0f3b6 | 108 | } |
76c7c63e | 109 | |
bed59bab EV |
110 | |
111 | diskname_to_printable() { | |
112 | COUNT=0 | |
113 | for disk in $(echo $@ | tr "," " "); do | |
114 | R=$(basename $disk | sed 's|/|_|g') | |
115 | COUNT=$(($COUNT + 1)) | |
116 | if [ $COUNT -eq 1 ]; then | |
117 | P="$R" | |
118 | else | |
119 | P="$P,$R" | |
120 | fi | |
121 | done | |
122 | echo $P | |
123 | } | |
124 | ||
fdc0f3b6 EV |
125 | gen_template() { |
126 | cat >$TEMPLATE << EOF | |
127 | [global] | |
128 | ioengine=libaio | |
129 | invalidate=1 | |
130 | ramp_time=5 | |
131 | EOF | |
afbbd646 EV |
132 | } |
133 | ||
134 | gen_seq_suite() { | |
135 | TYPE=$1 | |
bed59bab EV |
136 | disk=$2 |
137 | PRINTABLE_DISK=$(diskname_to_printable $disk) | |
afbbd646 | 138 | cat >> $OUTFILE << EOF |
bed59bab | 139 | [$TYPE-$PRINTABLE_DISK-$BLK_SIZE-seq] |
afbbd646 EV |
140 | stonewall |
141 | bs=$BLK_SIZE | |
bed59bab | 142 | filename=$disk |
afbbd646 | 143 | rw=$TYPE |
bed59bab EV |
144 | write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-seq.results |
145 | write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-seq.results | |
afbbd646 EV |
146 | EOF |
147 | ETA=$(($ETA + $RUNTIME)) | |
148 | } | |
149 | ||
150 | gen_seq_fio() { | |
151 | for disk in $(echo $DISKS | tr "," " "); do | |
152 | for mode in $(echo $MODES | tr "," " "); do | |
bed59bab | 153 | gen_seq_suite "$mode" "$disk" |
afbbd646 EV |
154 | done |
155 | done | |
156 | } | |
157 | ||
158 | ||
159 | gen_para_suite() { | |
160 | TYPE=$1 | |
161 | NEED_WALL=$2 | |
162 | D=0 | |
163 | for disk in $(echo $DISKS | tr "," " "); do | |
bed59bab | 164 | PRINTABLE_DISK=$(diskname_to_printable $disk) |
afbbd646 | 165 | cat >> $OUTFILE << EOF |
bed59bab | 166 | [$TYPE-$PRINTABLE_DISK-$BLK_SIZE-para] |
afbbd646 EV |
167 | bs=$BLK_SIZE |
168 | EOF | |
169 | ||
170 | if [ "$D" = 0 ]; then | |
171 | echo "stonewall" >> $OUTFILE | |
172 | D=1 | |
173 | fi | |
174 | ||
175 | cat >> $OUTFILE << EOF | |
bed59bab | 176 | filename=$disk |
afbbd646 | 177 | rw=$TYPE |
bed59bab EV |
178 | write_bw_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-para.results |
179 | write_iops_log=${PREFIX_FILENAME}$SHORT_HOSTNAME-$BLK_SIZE-$PRINTABLE_DISK-$TYPE-para.results | |
afbbd646 EV |
180 | EOF |
181 | done | |
182 | ||
183 | ETA=$(($ETA + $RUNTIME)) | |
184 | echo >> $OUTFILE | |
185 | } | |
186 | ||
187 | gen_para_fio() { | |
188 | for mode in $(echo $MODES | tr "," " "); do | |
189 | gen_para_suite "$mode" | |
190 | done | |
191 | } | |
192 | ||
193 | gen_fio() { | |
194 | case $SEQ in | |
195 | 2) | |
196 | gen_seq_fio | |
197 | gen_para_fio | |
198 | ;; | |
199 | 1) | |
200 | gen_seq_fio | |
201 | ;; | |
202 | 0) | |
203 | gen_para_fio | |
204 | ;; | |
205 | esac | |
206 | } | |
207 | ||
208 | parse_cmdline() { | |
f6facd21 | 209 | while getopts "hacpsd:b:r:m:x:z:D:A:B:" opt; do |
afbbd646 EV |
210 | case $opt in |
211 | h) | |
212 | show_help | |
213 | exit 0 | |
214 | ;; | |
215 | b) | |
216 | BLOCK_SIZE=$OPTARG | |
217 | ;; | |
76c7c63e EV |
218 | c) |
219 | CACHED_IO="TRUE" | |
220 | ;; | |
afbbd646 EV |
221 | s) |
222 | if [ "$SEQ" = "-1" ]; then | |
223 | SEQ=1 | |
224 | fi | |
225 | ;; | |
a7419837 EV |
226 | x) |
227 | PREFIX=$OPTARG | |
228 | echo "$PREFIX" | grep -q "/" | |
229 | if [ "$?" -eq 0 ]; then | |
230 | mkdir -p $PREFIX | |
231 | # No need to keep the prefix for the log files | |
232 | # we do have a directory for that | |
233 | PREFIX_FILENAME="" | |
234 | else | |
235 | # We need to keep the prefix for the log files | |
236 | PREFIX_FILENAME=$PREFIX | |
237 | fi | |
238 | ;; | |
afbbd646 EV |
239 | r) |
240 | RUNTIME=$OPTARG | |
241 | ;; | |
242 | p) | |
243 | if [ "$SEQ" = "-1" ]; then | |
244 | SEQ=0 | |
245 | fi | |
246 | ;; | |
247 | m) | |
248 | MODES=$OPTARG; | |
249 | ;; | |
250 | d) | |
251 | DISKS=$OPTARG | |
bed59bab | 252 | PRINTABLE_DISKS=$(diskname_to_printable "$DISKS") |
afbbd646 | 253 | ;; |
7d1ca6cf EV |
254 | D) |
255 | IODEPTH=$OPTARG | |
256 | ;; | |
afbbd646 EV |
257 | a) |
258 | SEQ=2 | |
259 | ;; | |
ca143750 EV |
260 | B) |
261 | echo "exec_prerun=$OPTARG" >> $TEMPLATE | |
262 | ;; | |
263 | A) | |
264 | echo "exec_postrun=$OPTARG" >> $TEMPLATE | |
265 | ;; | |
f6facd21 LM |
266 | z) |
267 | FSIZE=$OPTARG | |
268 | echo "size=$FSIZE" >> $TEMPLATE | |
269 | ;; | |
afbbd646 EV |
270 | \?) |
271 | echo "Invalid option: -$OPTARG" >&2 | |
272 | ;; | |
273 | esac | |
274 | done | |
275 | ||
276 | if [ "$SEQ" = "-1" ]; then | |
277 | SEQ=0 | |
278 | fi | |
279 | ||
280 | SHORT_HOSTNAME=$(hostname -s) | |
281 | case $SEQ in | |
282 | 2) | |
bed59bab | 283 | OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-all-$MODES-$PRINTABLE_DISKS.fio |
afbbd646 EV |
284 | ;; |
285 | ||
286 | 1) | |
bed59bab | 287 | OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-sequential-$MODES-$PRINTABLE_DISKS.fio |
afbbd646 EV |
288 | ;; |
289 | 0) | |
bed59bab | 290 | OUTFILE=${PREFIX}$SHORT_HOSTNAME-$BLOCK_SIZE-parallel-$MODES-$PRINTABLE_DISKS.fio |
afbbd646 EV |
291 | ;; |
292 | esac | |
293 | ||
294 | if [ -z "$DISKS" ]; then | |
295 | echo "Missing DISKS !" | |
e1c6f2e1 EV |
296 | echo "Please read the help !" |
297 | show_help | |
afbbd646 EV |
298 | exit 1 |
299 | fi | |
300 | ||
301 | } | |
302 | ||
60238f0e EV |
303 | check_mode_order() { |
304 | FOUND_WRITE="NO" | |
305 | CAUSE="You are reading data before writing them " | |
306 | ||
307 | # If no write occurs, let's show a different message | |
308 | echo $MODES | grep -q "write" | |
309 | if [ "$?" -ne 0 ]; then | |
310 | CAUSE="You are reading data while never wrote them before" | |
311 | fi | |
312 | ||
313 | for mode in $(echo $MODES | tr "," " "); do | |
314 | echo $mode | grep -q write | |
315 | if [ "$?" -eq 0 ]; then | |
316 | FOUND_WRITE="YES" | |
317 | fi | |
318 | echo $mode | grep -q "read" | |
319 | if [ "$?" -eq 0 ]; then | |
320 | if [ "$FOUND_WRITE" = "NO" ]; then | |
321 | echo "###############################################################" | |
322 | echo "# Warning : $CAUSE#" | |
323 | echo "# On some storage devices, this could lead to invalid results #" | |
324 | echo "# #" | |
325 | echo "# Press Ctrl-C to adjust pattern order if you have doubts #" | |
326 | echo "# Or Wait 5 seconds before the file will be created #" | |
327 | echo "###############################################################" | |
328 | sleep 5 | |
329 | # No need to try showing the message more than one time | |
330 | return | |
331 | fi | |
332 | fi | |
333 | done | |
334 | } | |
335 | ||
afbbd646 EV |
336 | |
337 | ########## MAIN | |
fdc0f3b6 | 338 | gen_template |
3b73c537 | 339 | parse_cmdline "$@" |
fdc0f3b6 | 340 | finish_template |
60238f0e | 341 | check_mode_order |
afbbd646 EV |
342 | |
343 | echo "Generating $OUTFILE" | |
344 | cp -f $TEMPLATE $OUTFILE | |
345 | echo >> $OUTFILE | |
346 | ||
347 | for BLK_SIZE in $(echo $BLOCK_SIZE | tr "," " "); do | |
348 | gen_fio | |
349 | done | |
350 | ETA_H=$(($ETA / 3600)) | |
351 | ETA_M=$((($ETA - ($ETA_H*3600)) / 60)) | |
af360e39 | 352 | if [ "$ETA" = "0" ]; then |
72fe3ef1 EV |
353 | echo "Cannot estimate ETA as RUNTIME=0" |
354 | else | |
355 | echo "Estimated Time = $ETA seconds : $ETA_H hour $ETA_M minutes" | |
356 | fi |