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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 import plotly.graph_objects as go
21 from copy import deepcopy
23 from ..utils.constants import Constants as C
24 from ..utils.utils import get_color
27 def get_short_version(version: str, dut_type: str="vpp") -> str:
28 """Returns the short version of DUT without build number.
30 :param version: Original version string.
31 :param dut_type: DUT type.
34 :returns: Short verion string.
38 if dut_type in ("trex", "dpdk"):
43 pattern=re.compile(r"^(\d{2}).(\d{2})-(rc0|rc1|rc2|release$)"),
49 f"{groups.group(1)}.{groups.group(2)}.{groups.group(3)}".\
50 replace("release", "rls")
57 def select_iterative_data(data: pd.DataFrame, itm:dict) -> pd.DataFrame:
58 """Select the data for graphs and tables from the provided data frame.
60 :param data: Data frame with data for graphs and tables.
61 :param itm: Item (in this case job name) which data will be selected from
63 :type data: pandas.DataFrame
65 :returns: A data frame with selected data.
66 :rtype: pandas.DataFrame
69 phy = itm["phy"].split("-")
71 topo, arch, nic, drv = phy
76 drv = drv.replace("_", "-")
80 core = str() if itm["dut"] == "trex" else f"{itm['core']}"
81 ttype = "ndrpdr" if itm["testtype"] in ("ndr", "pdr") else itm["testtype"]
82 dut_v100 = "none" if itm["dut"] == "trex" else itm["dut"]
86 (data["release"] == itm["rls"]) &
89 (data["version"] == "1.0.0") &
90 (data["dut_type"].str.lower() == dut_v100)
93 (data["version"] == "1.0.1") &
94 (data["dut_type"].str.lower() == dut_v101)
97 (data["test_type"] == ttype) &
98 (data["passed"] == True)
101 f"^.*[.|-]{nic}.*{itm['framesize']}-{core}-{drv}{itm['test']}-{ttype}$"
103 (df.job.str.endswith(f"{topo}-{arch}")) &
104 (df.dut_version.str.contains(itm["dutver"].replace(".r", "-r").\
105 replace("rls", "release"))) &
106 (df.test_id.str.contains(regex_test, regex=True))
112 def graph_iterative(data: pd.DataFrame, sel:dict, layout: dict,
113 normalize: bool) -> tuple:
114 """Generate the statistical box graph with iterative data (MRR, NDR and PDR,
115 for PDR also Latencies).
117 :param data: Data frame with iterative data.
118 :param sel: Selected tests.
119 :param layout: Layout of plot.ly graph.
120 :param normalize: If True, the data is normalized to CPU frquency
121 Constants.NORM_FREQUENCY.
122 :param data: pandas.DataFrame
125 :param normalize: bool
126 :returns: Tuple of graphs - throughput and latency.
127 :rtype: tuple(plotly.graph_objects.Figure, plotly.graph_objects.Figure)
140 for idx, itm in enumerate(sel):
141 itm_data = select_iterative_data(data, itm)
144 phy = itm["phy"].split("-")
145 topo_arch = f"{phy[0]}-{phy[1]}" if len(phy) == 4 else str()
146 norm_factor = (C.NORM_FREQUENCY / C.FREQUENCY[topo_arch]) \
147 if normalize else 1.0
148 if itm["testtype"] == "mrr":
149 y_data_raw = itm_data[C.VALUE_ITER[itm["testtype"]]].to_list()[0]
150 y_data = [(y * norm_factor) for y in y_data_raw]
153 max(y_data) if max(y_data) > y_tput_max else y_tput_max
155 y_data_raw = itm_data[C.VALUE_ITER[itm["testtype"]]].to_list()
156 y_data = [(y * norm_factor) for y in y_data_raw]
159 max(y_data) if max(y_data) > y_tput_max else y_tput_max
160 nr_of_samples = len(y_data)
165 f"({nr_of_samples:02d} "
166 f"run{'s' if nr_of_samples > 1 else ''}) "
172 marker=dict(color=get_color(idx))
174 tput_traces.append(go.Box(**tput_kwargs))
177 if itm["testtype"] == "pdr":
178 y_lat_row = itm_data[C.VALUE_ITER["pdr-lat"]].to_list()
179 y_lat = [(y / norm_factor) for y in y_lat_row]
181 y_lat_max = max(y_lat) if max(y_lat) > y_lat_max else y_lat_max
182 nr_of_samples = len(y_lat)
187 f"({nr_of_samples:02d} "
188 f"run{u's' if nr_of_samples > 1 else u''}) "
194 marker=dict(color=get_color(idx))
196 x_lat.append(idx + 1)
197 lat_traces.append(go.Box(**lat_kwargs))
200 lat_traces.append(go.Box())
203 pl_tput = deepcopy(layout["plot-throughput"])
204 pl_tput["xaxis"]["tickvals"] = [i for i in range(len(sel))]
205 pl_tput["xaxis"]["ticktext"] = [str(i + 1) for i in range(len(sel))]
207 pl_tput["yaxis"]["range"] = [0, (int(y_tput_max / 1e6) + 1) * 1e6]
208 fig_tput = go.Figure(data=tput_traces, layout=pl_tput)
211 pl_lat = deepcopy(layout["plot-latency"])
212 pl_lat["xaxis"]["tickvals"] = [i for i in range(len(x_lat))]
213 pl_lat["xaxis"]["ticktext"] = x_lat
215 pl_lat["yaxis"]["range"] = [0, (int(y_lat_max / 10) + 1) * 10]
216 fig_lat = go.Figure(data=lat_traces, layout=pl_lat)
218 return fig_tput, fig_lat
221 def table_comparison(data: pd.DataFrame, sel:dict,
222 normalize: bool) -> pd.DataFrame:
223 """Generate the comparison table with selected tests.
225 :param data: Data frame with iterative data.
226 :param sel: Selected tests.
227 :param normalize: If True, the data is normalized to CPU frquency
228 Constants.NORM_FREQUENCY.
229 :param data: pandas.DataFrame
231 :param normalize: bool
232 :returns: Comparison table.
233 :rtype: pandas.DataFrame
235 table = pd.DataFrame(
238 # "64b-2t1c-avf-eth-l2xcbase-eth-2memif-1dcr",
239 # "64b-2t1c-avf-eth-l2xcbase-eth-2vhostvr1024-1vm-vppl2xc",
240 # "64b-2t1c-avf-ethip4udp-ip4base-iacl50sl-10kflows",
241 # "78b-2t1c-avf-ethip6-ip6scale2m-rnd "],
262 # "2110.0-9 vs 2110.0-8": [
267 # "2202.0-9 vs 2110.0-9": [