Add support for measuring storage performance use fio
[yardstick.git] / yardstick / benchmark / scenarios / storage / fio_benchmark.bash
1 #!/bin/sh
2
3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 set -e
13
14 # Commandline arguments
15 FIO_FILENAME=$1
16 shift
17 OPTIONS="$@"
18 OUTPUT_FILE="yardstick-fio.log"
19
20 # setup data file for fio
21 setup()
22 {
23     if [ ! -f $FIO_FILENAME ]; then
24         dd if=/dev/zero of=$FIO_FILENAME bs=1M count=1024 oflag=direct > /dev/null 2>&1
25     fi
26 }
27
28 # run fio test
29 run_test()
30 {
31     fio $OPTIONS --output=$OUTPUT_FILE
32 }
33
34 # write the result to stdout in json format
35 output_json()
36 {
37     read_bw=$(grep "READ.*aggrb"  $OUTPUT_FILE | awk -F [=\ ,] '{printf $9}')
38     write_bw=$(grep "WRITE.*aggrb" $OUTPUT_FILE | awk -F [=\ ,] '{printf $8}')
39     eval $(grep -e '\ lat.*stdev' -e "read.*iops" -e "write.*iops" -e "trim.*iops" $OUTPUT_FILE | sed 'N;s/\n/ /g' | grep read | awk -F [=\ ,\(\)] '{printf("read_iops=%s; read_lat_unit=%s; read_lat=%s", $12, $24, $33)}')
40     eval $(grep -e '\ lat.*stdev' -e "read.*iops" -e "write.*iops" -e "trim.*iops" $OUTPUT_FILE | sed 'N;s/\n/ /g' | grep write | awk -F [=\ ,\(\)] '{printf("write_iops=%s; write_lat_unit=%s; write_lat=%s", $11, $23, $32)}')
41
42     read_bw=${read_bw:-N/A}
43     write_bw=${write_bw:-N/A}
44     read_iops=${read_iops:-N/A}
45     write_iops=${write_iops:-N/A}
46     if [ "x$read_lat" = "x" ]; then
47         read_lat="N/A"
48     else
49         read_lat=$read_lat$read_lat_unit
50     fi
51     if [ "x$write_lat" = "x" ]; then
52         write_lat="N/A"
53     else
54         write_lat=$write_lat$write_lat_unit
55     fi
56
57     echo -e "{ \
58         \"read_bw\":\"$read_bw\", \
59         \"write_bw\":\"$write_bw\", \
60         \"read_iops\":\"$read_iops\", \
61         \"write_iops\":\"$write_iops\", \
62         \"read_lat\":\"$read_lat\", \
63         \"write_lat\":\"$write_lat\" \
64     }"
65 }
66
67 # main entry
68 main()
69 {
70     # setup the test
71     setup
72
73     # run the test
74     run_test >/dev/null
75
76     # output result
77     output_json
78 }
79
80 main
81