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.
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, get_hdrh_latencies
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 if itm["testtype"] in ("ndr", "pdr"):
52 elif itm["testtype"] == "mrr":
54 elif itm["area"] == "hoststack":
55 test_type = "hoststack"
57 (data["release"] == itm["rls"]) &
58 (data["test_type"] == test_type) &
59 (data["passed"] == True)
62 core = str() if itm["dut"] == "trex" else f"{itm['core']}"
63 ttype = "ndrpdr" if itm["testtype"] in ("ndr", "pdr") else itm["testtype"]
65 f"^.*[.|-]{nic}.*{itm['framesize']}-{core}-{drv}{itm['test']}-{ttype}$"
67 (df.job.str.endswith(f"{topo}-{arch}")) &
68 (df.dut_version.str.contains(itm["dutver"].replace(".r", "-r").\
69 replace("rls", "release"))) &
70 (df.test_id.str.contains(regex_test, regex=True))
76 def graph_iterative(data: pd.DataFrame, sel:dict, layout: dict,
77 normalize: bool) -> tuple:
78 """Generate the statistical box graph with iterative data (MRR, NDR and PDR,
79 for PDR also Latencies).
81 :param data: Data frame with iterative data.
82 :param sel: Selected tests.
83 :param layout: Layout of plot.ly graph.
84 :param normalize: If True, the data is normalized to CPU frequency
85 Constants.NORM_FREQUENCY.
86 :param data: pandas.DataFrame
89 :param normalize: bool
90 :returns: Tuple of graphs - throughput and latency.
91 :rtype: tuple(plotly.graph_objects.Figure, plotly.graph_objects.Figure)
105 for idx, itm in enumerate(sel):
107 itm_data = select_iterative_data(data, itm)
111 phy = itm["phy"].split("-")
112 topo_arch = f"{phy[0]}-{phy[1]}" if len(phy) == 4 else str()
113 norm_factor = (C.NORM_FREQUENCY / C.FREQUENCY[topo_arch]) \
114 if normalize else 1.0
116 if itm["area"] == "hoststack":
117 ttype = f"hoststack-{itm['testtype']}"
119 ttype = itm["testtype"]
121 y_units.update(itm_data[C.UNIT[ttype]].unique().tolist())
123 if itm["testtype"] == "mrr":
124 y_data_raw = itm_data[C.VALUE_ITER[ttype]].to_list()[0]
126 y_data_raw = itm_data[C.VALUE_ITER[ttype]].to_list()
127 y_data = [(y * norm_factor) for y in y_data_raw]
129 y_tput_max = max(max(y_data), y_tput_max)
131 nr_of_samples = len(y_data)
135 "csit release": itm["rls"],
137 "dut version": itm["dutver"],
140 f"{itm['area']}-{itm['framesize']}-{itm['core']}-"
141 f"{itm['test']}-{itm['testtype']}"
145 if itm["testtype"] == "mrr":
146 metadata["csit-ref"] = (
147 f"{itm_data['job'].to_list()[0]}/",
148 f"{itm_data['build'].to_list()[0]}"
150 customdata = [{"metadata": metadata}, ] * nr_of_samples
152 for _, row in itm_data.iterrows():
153 metadata["csit-ref"] = f"{row['job']}/{row['build']}"
154 customdata.append({"metadata": deepcopy(metadata)})
159 f"({nr_of_samples:02d} "
160 f"run{'s' if nr_of_samples > 1 else ''}) "
166 marker=dict(color=get_color(idx)),
167 customdata=customdata
169 tput_traces.append(go.Box(**tput_kwargs))
174 for _, row in itm_data.iterrows():
175 hdrh = get_hdrh_latencies(
177 f"{metadata['infra']}-{metadata['test']}"
179 metadata["csit-ref"] = f"{row['job']}/{row['build']}"
181 "metadata": deepcopy(metadata),
185 y_lat_row = itm_data[C.VALUE_ITER["latency"]].to_list()
186 y_lat = [(y / norm_factor) for y in y_lat_row]
189 y_lat_max = max(max(y_lat), y_lat_max)
192 nr_of_samples = len(y_lat)
197 f"({nr_of_samples:02d} "
198 f"run{u's' if nr_of_samples > 1 else u''}) "
204 marker=dict(color=get_color(idx)),
205 customdata=customdata
207 x_lat.append(idx + 1)
208 lat_traces.append(go.Box(**lat_kwargs))
211 lat_traces.append(go.Box())
214 pl_tput = deepcopy(layout["plot-throughput"])
215 pl_tput["xaxis"]["tickvals"] = [i for i in range(len(sel))]
216 pl_tput["xaxis"]["ticktext"] = [str(i + 1) for i in range(len(sel))]
217 pl_tput["yaxis"]["title"] = f"Throughput [{'|'.join(sorted(y_units))}]"
219 pl_tput["yaxis"]["range"] = [0, (int(y_tput_max / 1e6) + 2) * 1e6]
220 fig_tput = go.Figure(data=tput_traces, layout=pl_tput)
223 pl_lat = deepcopy(layout["plot-latency"])
224 pl_lat["xaxis"]["tickvals"] = [i for i in range(len(x_lat))]
225 pl_lat["xaxis"]["ticktext"] = x_lat
227 pl_lat["yaxis"]["range"] = [0, (int(y_lat_max / 10) + 1) * 10]
228 fig_lat = go.Figure(data=lat_traces, layout=pl_lat)
230 return fig_tput, fig_lat