1 # Copyright (c) 2023 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 select_iterative_data(data: pd.DataFrame, itm:dict) -> pd.DataFrame:
28 """Select the data for graphs and tables from the provided data frame.
30 :param data: Data frame with data for graphs and tables.
31 :param itm: Item (in this case job name) which data will be selected from
33 :type data: pandas.DataFrame
35 :returns: A data frame with selected data.
36 :rtype: pandas.DataFrame
39 phy = itm["phy"].split("-")
41 topo, arch, nic, drv = phy
46 drv = drv.replace("_", "-")
50 core = str() if itm["dut"] == "trex" else f"{itm['core']}"
51 ttype = "ndrpdr" if itm["testtype"] in ("ndr", "pdr") else itm["testtype"]
53 (data["release"] == itm["rls"]) &
54 (data["test_type"] == ttype) &
55 (data["passed"] == True)
58 f"^.*[.|-]{nic}.*{itm['framesize']}-{core}-{drv}{itm['test']}-{ttype}$"
60 (df.job.str.endswith(f"{topo}-{arch}")) &
61 (df.dut_version.str.contains(itm["dutver"].replace(".r", "-r").\
62 replace("rls", "release"))) &
63 (df.test_id.str.contains(regex_test, regex=True))
69 def graph_iterative(data: pd.DataFrame, sel:dict, layout: dict,
70 normalize: bool) -> tuple:
71 """Generate the statistical box graph with iterative data (MRR, NDR and PDR,
72 for PDR also Latencies).
74 :param data: Data frame with iterative data.
75 :param sel: Selected tests.
76 :param layout: Layout of plot.ly graph.
77 :param normalize: If True, the data is normalized to CPU frquency
78 Constants.NORM_FREQUENCY.
79 :param data: pandas.DataFrame
82 :param normalize: bool
83 :returns: Tuple of graphs - throughput and latency.
84 :rtype: tuple(plotly.graph_objects.Figure, plotly.graph_objects.Figure)
97 for idx, itm in enumerate(sel):
98 itm_data = select_iterative_data(data, itm)
101 phy = itm["phy"].split("-")
102 topo_arch = f"{phy[0]}-{phy[1]}" if len(phy) == 4 else str()
103 norm_factor = (C.NORM_FREQUENCY / C.FREQUENCY[topo_arch]) \
104 if normalize else 1.0
105 if itm["testtype"] == "mrr":
106 y_data_raw = itm_data[C.VALUE_ITER[itm["testtype"]]].to_list()[0]
107 y_data = [(y * norm_factor) for y in y_data_raw]
110 max(y_data) if max(y_data) > y_tput_max else y_tput_max
112 y_data_raw = itm_data[C.VALUE_ITER[itm["testtype"]]].to_list()
113 y_data = [(y * norm_factor) for y in y_data_raw]
116 max(y_data) if max(y_data) > y_tput_max else y_tput_max
117 nr_of_samples = len(y_data)
122 f"({nr_of_samples:02d} "
123 f"run{'s' if nr_of_samples > 1 else ''}) "
129 marker=dict(color=get_color(idx))
131 tput_traces.append(go.Box(**tput_kwargs))
134 if itm["testtype"] == "pdr":
135 y_lat_row = itm_data[C.VALUE_ITER["pdr-lat"]].to_list()
136 y_lat = [(y / norm_factor) for y in y_lat_row]
138 y_lat_max = max(y_lat) if max(y_lat) > y_lat_max else y_lat_max
139 nr_of_samples = len(y_lat)
144 f"({nr_of_samples:02d} "
145 f"run{u's' if nr_of_samples > 1 else u''}) "
151 marker=dict(color=get_color(idx))
153 x_lat.append(idx + 1)
154 lat_traces.append(go.Box(**lat_kwargs))
157 lat_traces.append(go.Box())
160 pl_tput = deepcopy(layout["plot-throughput"])
161 pl_tput["xaxis"]["tickvals"] = [i for i in range(len(sel))]
162 pl_tput["xaxis"]["ticktext"] = [str(i + 1) for i in range(len(sel))]
164 pl_tput["yaxis"]["range"] = [0, (int(y_tput_max / 1e6) + 1) * 1e6]
165 fig_tput = go.Figure(data=tput_traces, layout=pl_tput)
168 pl_lat = deepcopy(layout["plot-latency"])
169 pl_lat["xaxis"]["tickvals"] = [i for i in range(len(x_lat))]
170 pl_lat["xaxis"]["ticktext"] = x_lat
172 pl_lat["yaxis"]["range"] = [0, (int(y_lat_max / 10) + 1) * 10]
173 fig_lat = go.Figure(data=lat_traces, layout=pl_lat)
175 return fig_tput, fig_lat