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.
14 """Implementation of graphs for iterative data.
17 import plotly.graph_objects as go
20 from copy import deepcopy
22 from ..utils.constants import Constants as C
23 from ..utils.utils import get_color, get_hdrh_latencies
26 def select_iterative_data(data: pd.DataFrame, itm:dict) -> pd.DataFrame:
27 """Select the data for graphs and tables from the provided data frame.
29 :param data: Data frame with data for graphs and tables.
30 :param itm: Item (in this case job name) which data will be selected from
32 :type data: pandas.DataFrame
34 :returns: A data frame with selected data.
35 :rtype: pandas.DataFrame
38 phy = itm["phy"].split("-")
40 topo, arch, nic, drv = phy
45 drv = drv.replace("_", "-")
49 if itm["testtype"] in ("ndr", "pdr"):
51 elif itm["testtype"] == "mrr":
53 elif itm["area"] == "hoststack":
54 test_type = "hoststack"
56 (data["release"] == itm["rls"]) &
57 (data["test_type"] == test_type) &
58 (data["passed"] == True)
61 core = str() if itm["dut"] == "trex" else f"{itm['core']}"
62 ttype = "ndrpdr" if itm["testtype"] in ("ndr", "pdr") else itm["testtype"]
64 f"^.*[.|-]{nic}.*{itm['framesize']}-{core}-{drv}{itm['test']}-{ttype}$"
66 (df.job.str.endswith(f"{topo}-{arch}")) &
67 (df.dut_version.str.contains(itm["dutver"].replace(".r", "-r").\
68 replace("rls", "release"))) &
69 (df.test_id.str.contains(regex_test, regex=True))
75 def graph_iterative(data: pd.DataFrame, sel:dict, layout: dict,
76 normalize: bool) -> tuple:
77 """Generate the statistical box graph with iterative data (MRR, NDR and PDR,
78 for PDR also Latencies).
80 :param data: Data frame with iterative data.
81 :param sel: Selected tests.
82 :param layout: Layout of plot.ly graph.
83 :param normalize: If True, the data is normalized to CPU frequency
84 Constants.NORM_FREQUENCY.
85 :param data: pandas.DataFrame
88 :param normalize: bool
89 :returns: Tuple of graphs - throughput and latency.
90 :rtype: tuple(plotly.graph_objects.Figure, plotly.graph_objects.Figure)
104 for idx, itm in enumerate(sel):
106 itm_data = select_iterative_data(data, itm)
110 phy = itm["phy"].split("-")
111 topo_arch = f"{phy[0]}-{phy[1]}" if len(phy) == 4 else str()
112 norm_factor = (C.NORM_FREQUENCY / C.FREQUENCY[topo_arch]) \
113 if normalize else 1.0
115 if itm["area"] == "hoststack":
116 ttype = f"hoststack-{itm['testtype']}"
118 ttype = itm["testtype"]
120 y_units.update(itm_data[C.UNIT[ttype]].unique().tolist())
122 if itm["testtype"] == "mrr":
123 y_data_raw = itm_data[C.VALUE_ITER[ttype]].to_list()[0]
125 y_data_raw = itm_data[C.VALUE_ITER[ttype]].to_list()
126 y_data = [(y * norm_factor) for y in y_data_raw]
128 y_tput_max = max(max(y_data), y_tput_max)
130 nr_of_samples = len(y_data)
135 f"({nr_of_samples:02d} "
136 f"run{'s' if nr_of_samples > 1 else ''}) "
142 marker=dict(color=get_color(idx))
144 tput_traces.append(go.Box(**tput_kwargs))
149 for _, row in itm_data.iterrows():
151 get_hdrh_latencies(row, f"{row['job']}/{row['build']}")
154 y_lat_row = itm_data[C.VALUE_ITER["latency"]].to_list()
155 y_lat = [(y / norm_factor) for y in y_lat_row]
158 y_lat_max = max(max(y_lat), y_lat_max)
161 nr_of_samples = len(y_lat)
166 f"({nr_of_samples:02d} "
167 f"run{u's' if nr_of_samples > 1 else u''}) "
173 marker=dict(color=get_color(idx)),
174 customdata=customdata
176 x_lat.append(idx + 1)
177 lat_traces.append(go.Box(**lat_kwargs))
180 lat_traces.append(go.Box())
183 pl_tput = deepcopy(layout["plot-throughput"])
184 pl_tput["xaxis"]["tickvals"] = [i for i in range(len(sel))]
185 pl_tput["xaxis"]["ticktext"] = [str(i + 1) for i in range(len(sel))]
186 pl_tput["yaxis"]["title"] = f"Throughput [{'|'.join(sorted(y_units))}]"
188 pl_tput["yaxis"]["range"] = [0, (int(y_tput_max / 1e6) + 2) * 1e6]
189 fig_tput = go.Figure(data=tput_traces, layout=pl_tput)
192 pl_lat = deepcopy(layout["plot-latency"])
193 pl_lat["xaxis"]["tickvals"] = [i for i in range(len(x_lat))]
194 pl_lat["xaxis"]["ticktext"] = x_lat
196 pl_lat["yaxis"]["range"] = [0, (int(y_lat_max / 10) + 1) * 10]
197 fig_lat = go.Figure(data=lat_traces, layout=pl_lat)
199 return fig_tput, fig_lat