4cd9287f0f641902031c258902e65c42bccb6956
[csit.git] / resources / tools / dash / app / pal / report / graphs.py
1 # Copyright (c) 2022 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """
15 """
16
17 import re
18 import plotly.graph_objects as go
19 import pandas as pd
20
21 from copy import deepcopy
22
23 from ..utils.constants import Constants as C
24 from ..utils.utils import get_color
25
26
27 def get_short_version(version: str, dut_type: str="vpp") -> str:
28     """
29     """
30
31     if dut_type in ("trex", "dpdk"):
32         return version
33
34     s_version = str()
35     groups = re.search(
36         pattern=re.compile(r"^(\d{2}).(\d{2})-(rc0|rc1|rc2|release$)"),
37         string=version
38     )
39     if groups:
40         try:
41             s_version = \
42                 f"{groups.group(1)}.{groups.group(2)}.{groups.group(3)}".\
43                     replace("release", "rls")
44         except IndexError:
45             pass
46
47     return s_version
48
49
50 def select_iterative_data(data: pd.DataFrame, itm:dict) -> pd.DataFrame:
51     """
52     """
53
54     phy = itm["phy"].split("-")
55     if len(phy) == 4:
56         topo, arch, nic, drv = phy
57         if drv == "dpdk":
58             drv = ""
59         else:
60             drv += "-"
61             drv = drv.replace("_", "-")
62     else:
63         return None
64
65     core = str() if itm["dut"] == "trex" else f"{itm['core']}"
66     ttype = "ndrpdr" if itm["testtype"] in ("ndr", "pdr") else itm["testtype"]
67     dut_v100 = "none" if itm["dut"] == "trex" else itm["dut"]
68     dut_v101 = itm["dut"]
69
70     df = data.loc[(
71         (data["release"] == itm["rls"]) &
72         (
73             (
74                 (data["version"] == "1.0.0") &
75                 (data["dut_type"].str.lower() == dut_v100)
76             ) |
77             (
78                 (data["version"] == "1.0.1") &
79                 (data["dut_type"].str.lower() == dut_v101)
80             )
81         ) &
82         (data["test_type"] == ttype) &
83         (data["passed"] == True)
84     )]
85     regex_test = \
86         f"^.*[.|-]{nic}.*{itm['framesize']}-{core}-{drv}{itm['test']}-{ttype}$"
87     df = df[
88         (df.job.str.endswith(f"{topo}-{arch}")) &
89         (df.dut_version.str.contains(itm["dutver"].replace(".r", "-r").\
90             replace("rls", "release"))) &
91         (df.test_id.str.contains(regex_test, regex=True))
92     ]
93
94     return df
95
96
97 def graph_iterative(data: pd.DataFrame, sel:dict, layout: dict,
98         normalize: bool) -> tuple:
99     """
100     """
101
102     fig_tput = None
103     fig_lat = None
104
105     tput_traces = list()
106     y_tput_max = 0
107     lat_traces = list()
108     y_lat_max = 0
109     x_lat = list()
110     show_latency = False
111     show_tput = False
112     for idx, itm in enumerate(sel):
113         itm_data = select_iterative_data(data, itm)
114         if itm_data.empty:
115             continue
116         phy = itm["phy"].split("-")
117         topo_arch = f"{phy[0]}-{phy[1]}" if len(phy) == 4 else str()
118         norm_factor = (C.NORM_FREQUENCY / C.FREQUENCY[topo_arch]) \
119             if normalize else 1.0
120         if itm["testtype"] == "mrr":
121             y_data_raw = itm_data[C.VALUE_ITER[itm["testtype"]]].to_list()[0]
122             y_data = [(y * norm_factor) for y in y_data_raw]
123             if len(y_data) > 0:
124                 y_tput_max = \
125                     max(y_data) if max(y_data) > y_tput_max else y_tput_max
126         else:
127             y_data_raw = itm_data[C.VALUE_ITER[itm["testtype"]]].to_list()
128             y_data = [(y * norm_factor) for y in y_data_raw]
129             if y_data:
130                 y_tput_max = \
131                     max(y_data) if max(y_data) > y_tput_max else y_tput_max
132         nr_of_samples = len(y_data)
133         tput_kwargs = dict(
134             y=y_data,
135             name=(
136                 f"{idx + 1}. "
137                 f"({nr_of_samples:02d} "
138                 f"run{'s' if nr_of_samples > 1 else ''}) "
139                 f"{itm['id']}"
140             ),
141             hoverinfo=u"y+name",
142             boxpoints="all",
143             jitter=0.3,
144             marker=dict(color=get_color(idx))
145         )
146         tput_traces.append(go.Box(**tput_kwargs))
147         show_tput = True
148
149         if itm["testtype"] == "pdr":
150             y_lat_row = itm_data[C.VALUE_ITER["pdr-lat"]].to_list()
151             y_lat = [(y / norm_factor) for y in y_lat_row]
152             if y_lat:
153                 y_lat_max = max(y_lat) if max(y_lat) > y_lat_max else y_lat_max
154             nr_of_samples = len(y_lat)
155             lat_kwargs = dict(
156                 y=y_lat,
157                 name=(
158                     f"{idx + 1}. "
159                     f"({nr_of_samples:02d} "
160                     f"run{u's' if nr_of_samples > 1 else u''}) "
161                     f"{itm['id']}"
162                 ),
163                 hoverinfo="all",
164                 boxpoints="all",
165                 jitter=0.3,
166                 marker=dict(color=get_color(idx))
167             )
168             x_lat.append(idx + 1)
169             lat_traces.append(go.Box(**lat_kwargs))
170             show_latency = True
171         else:
172             lat_traces.append(go.Box())
173
174     if show_tput:
175         pl_tput = deepcopy(layout["plot-throughput"])
176         pl_tput["xaxis"]["tickvals"] = [i for i in range(len(sel))]
177         pl_tput["xaxis"]["ticktext"] = [str(i + 1) for i in range(len(sel))]
178         if y_tput_max:
179             pl_tput["yaxis"]["range"] = [0, (int(y_tput_max / 1e6) + 1) * 1e6]
180         fig_tput = go.Figure(data=tput_traces, layout=pl_tput)
181
182     if show_latency:
183         pl_lat = deepcopy(layout["plot-latency"])
184         pl_lat["xaxis"]["tickvals"] = [i for i in range(len(x_lat))]
185         pl_lat["xaxis"]["ticktext"] = x_lat
186         if y_lat_max:
187             pl_lat["yaxis"]["range"] = [0, (int(y_lat_max / 10) + 1) * 10]
188         fig_lat = go.Figure(data=lat_traces, layout=pl_lat)
189
190     return fig_tput, fig_lat
191
192
193 def table_comparison(data: pd.DataFrame, sel:dict,
194         normalize: bool) -> pd.DataFrame:
195     """
196     """
197     table = pd.DataFrame(
198         {
199             "Test Case": [
200                 "64b-2t1c-avf-eth-l2xcbase-eth-2memif-1dcr",
201                 "64b-2t1c-avf-eth-l2xcbase-eth-2vhostvr1024-1vm-vppl2xc",
202                 "64b-2t1c-avf-ethip4udp-ip4base-iacl50sl-10kflows",
203                 "78b-2t1c-avf-ethip6-ip6scale2m-rnd "],
204             "2106.0-8": [
205                 "14.45 +- 0.08",
206                 "9.63 +- 0.05",
207                 "9.7 +- 0.02",
208                 "8.95 +- 0.06"],
209             "2110.0-8": [
210                 "14.45 +- 0.08",
211                 "9.63 +- 0.05",
212                 "9.7 +- 0.02",
213                 "8.95 +- 0.06"],
214             "2110.0-9": [
215                 "14.45 +- 0.08",
216                 "9.63 +- 0.05",
217                 "9.7 +- 0.02",
218                 "8.95 +- 0.06"],
219             "2202.0-9": [
220                 "14.45 +- 0.08",
221                 "9.63 +- 0.05",
222                 "9.7 +- 0.02",
223                 "8.95 +- 0.06"],
224             "2110.0-9 vs 2110.0-8": [
225                 "-0.23 +-  0.62",
226                 "-1.37 +-   1.3",
227                 "+0.08 +-   0.2",
228                 "-2.16 +-  0.83"],
229             "2202.0-9 vs 2110.0-9": [
230                 "+6.95 +-  0.72",
231                 "+5.35 +-  1.26",
232                 "+4.48 +-  1.48",
233                 "+4.09 +-  0.95"]
234         }
235     )
236
237     return pd.DataFrame()  #table