Merge "opnfvresultdb: Add mapping for VPP TCs"
[vswitchperf.git] / ci / plot-results.sh
1 #!/bin/bash
2 #
3 # Copyright 2017 Intel Corporation.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #   http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Script for graphical representation of VSPERF results
18 #
19 # Usage:
20 #   ./create_graph ["test names" [filter [directory]]]
21 #
22 # where:
23 #       "test names" is a !!! quoted !!! string with vsperf testcase names separated
24 #           by spaces
25 #           Default value: "phy2phy_tput"
26 #
27 #       "filter" is used to select matching VSPERF results; Its value
28 #           will be used as PATTERN of grep command executed on selected
29 #           csv result files.
30 #           Default value: ",OvsDpdkVhost,"
31 #
32 #       "directory" is a directory name, where vsperf results (i.e. results_*
33 #           subdirectories) are located
34 #           Default value: "/tmp"
35 #
36 # Example of invocation:
37 #   ./create_graph "phy2phy_tput phy2phy_cont pvp_cont pvvp_cont" ",OvsVanilla,"
38
39 TESTS="phy2phy_tput"    # default set of TCs to be plotted
40 FILTER=",OvsDpdkVhost," # default filter to be applied on matching CSV files
41 NUMBER_OF_RESULTS=50    # max number of recent results to be compared in graph
42 CSV_RESULT_COL=2        # column number with result to be plotted, e.g. 2 for rx_throughput_fps
43 B2B_CSV_RESULT_COL=1    # column number with result to be plotted for back2back TCs
44 CSV_PKT_SIZE_COL=12     # column number with frame/packet size
45 B2B_CSV_PKT_SIZE_COL=4  # column number with frame/packet size for back2back TCs
46 NUMBER_OF_PKT_SIZES=0   # to be detected automatically
47 MAX_NUMBER_OF_PKT_SIZES=10
48 DIR="/tmp"              # directory where vsperf results are stored
49 PNG_PREFIX='vsperf_'
50 TYPE="TPUT"             # customization of graph for TPUT or B2B
51
52 function clean_data() {
53     rm -rf *csv
54     rm -rf *plot
55     rm -rf *png
56 }
57
58 function prepare_data() {
59     for test_name in $TESTS; do
60         FIRST=1
61         CSV_LIST=`grep -r ",${test_name}," ${DIR}/results_*/*csv | grep $FILTER | cut -d':' -f1 | uniq | sort | tail -n ${NUMBER_OF_RESULTS}`
62         for result_file in $CSV_LIST ; do
63             tmp_dir=`dirname $result_file`
64             TIMESTAMP=`basename $tmp_dir | cut -d'_' -f2-`
65             if [ $FIRST -eq 1 ] ; then
66                 NUMBER_OF_PKT_SIZES=$((`wc -l ${result_file} | cut -d' ' -f1`-1))
67                 if [ $NUMBER_OF_PKT_SIZES -gt $MAX_NUMBER_OF_PKT_SIZES ] ; then
68                     NUMBER_OF_PKT_SIZES=$MAX_NUMBER_OF_PKT_SIZES
69                 fi
70                 if grep back2back ${result_file} &> /dev/null ; then
71                     PKT_SIZE_COL=$B2B_CSV_PKT_SIZE_COL
72                     RES_COL=$B2B_CSV_RESULT_COL
73                     TYPE="B2B"
74                 else
75                     PKT_SIZE_COL=$CSV_PKT_SIZE_COL
76                     RES_COL=$CSV_RESULT_COL
77                     TYPE="TPUT"
78                 fi
79                 RESULT_HEADER=`tail -n+2 ${result_file} | head -n ${NUMBER_OF_PKT_SIZES} | cut -d',' -f${PKT_SIZE_COL} | paste -d',' -s`
80                 echo "[$TYPE] Date/PKT Size [B],${RESULT_HEADER}" > "${test_name}.csv"
81                 FIRST=0
82             fi
83             RESULT_4ALL_PKT_SIZES=`tail -n+2 ${result_file} | head -n ${NUMBER_OF_PKT_SIZES} | cut -d',' -f${RES_COL} | paste -d',' -s`
84             echo "${TIMESTAMP},${RESULT_4ALL_PKT_SIZES}" >> "${test_name}.csv"
85         done
86     done
87 }
88
89 function plot_data() {
90     echo "Created graphs:"
91     SUFFIX=`echo $FILTER | tr -d -C [:alnum:]`
92     for TEST_CSV in *csv; do
93         [ ! -f $TEST_CSV ] && continue
94         TEST_NAME=`basename ${TEST_CSV} .csv`"_${SUFFIX}"
95         OUTPUT="$TEST_NAME.plot"
96         cat > $OUTPUT <<- EOM
97 set datafile separator ","
98 set xdata time
99 set timefmt "%Y-%m-%d_%H:%M:%S"
100 set format x "%m-%d"
101 set xlabel "date"
102 set format y "%8.0f"
103 set term png size 1024,768
104 EOM
105
106         if grep '^\[B2B\]' ${TEST_CSV} &> /dev/null ; then
107             echo 'set ylabel "frames"' >> $OUTPUT
108             echo 'set log y' >> $OUTPUT
109             echo 'set yrange [1:]' >> $OUTPUT
110         else
111             echo 'set ylabel "fps"' >> $OUTPUT
112             echo 'set yrange [0:]' >> $OUTPUT
113         fi
114
115         iter=0
116         echo "set title \"$TEST_NAME\"" >> $OUTPUT
117         echo "set output \"${PNG_PREFIX}${TEST_NAME}.png\"" >> $OUTPUT
118         echo -n "plot " >> $OUTPUT
119         SEP=""
120         while [ $iter -lt $NUMBER_OF_PKT_SIZES ] ; do
121             COL=$((2+$iter))
122             echo $"$SEP '$TEST_CSV' using 1:$COL with linespoints title columnheader($COL) \\" >> $OUTPUT
123             iter=$(($iter+1))
124             SEP=","
125         done
126         echo -e "\t${PNG_PREFIX}${TEST_NAME}.png"
127         gnuplot $OUTPUT
128     done
129 }
130
131 #
132 # Main body
133 #
134
135 # override default set of TESTS if specified by 1st parameter
136 if [ "$1" != "" ] ; then
137     TESTS="$1"
138 fi
139
140 # override default filter if specified by 2nd parameter
141 if [ "$2" != "" ] ; then
142     FILTER="$2"
143 fi
144
145 # override default directory with results by 3rd parameter
146 if [ "$3" != "" ] ; then
147     DIR="$3"
148 fi
149 clean_data
150
151 echo -e "Plot data input:"
152 echo -e "\tTESTS: $TESTS"
153 echo -e "\tFilter: $FILTER"
154 echo -e "\tResults direcotry: $DIR"
155
156 prepare_data
157 plot_data