1 # Copyright (c) 2020 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 """Algorithms to generate plots.
21 from collections import OrderedDict
22 from copy import deepcopy
27 import plotly.offline as ploff
28 import plotly.graph_objs as plgo
30 from plotly.subplots import make_subplots
31 from plotly.exceptions import PlotlyError
33 from pal_utils import mean, stdev
36 COLORS = [u"SkyBlue", u"Olive", u"Purple", u"Coral", u"Indigo", u"Pink",
37 u"Chocolate", u"Brown", u"Magenta", u"Cyan", u"Orange", u"Black",
38 u"Violet", u"Blue", u"Yellow", u"BurlyWood", u"CadetBlue", u"Crimson",
39 u"DarkBlue", u"DarkCyan", u"DarkGreen", u"Green", u"GoldenRod",
40 u"LightGreen", u"LightSeaGreen", u"LightSkyBlue", u"Maroon",
41 u"MediumSeaGreen", u"SeaGreen", u"LightSlateGrey"]
43 REGEX_NIC = re.compile(r'(\d*ge\dp\d\D*\d*[a-z]*)-')
46 def generate_plots(spec, data):
47 """Generate all plots specified in the specification file.
49 :param spec: Specification read from the specification file.
50 :param data: Data to process.
51 :type spec: Specification
56 u"plot_nf_reconf_box_name": plot_nf_reconf_box_name,
57 u"plot_perf_box_name": plot_perf_box_name,
58 u"plot_lat_err_bars_name": plot_lat_err_bars_name,
59 u"plot_tsa_name": plot_tsa_name,
60 u"plot_http_server_perf_box": plot_http_server_perf_box,
61 u"plot_nf_heatmap": plot_nf_heatmap,
62 u"plot_lat_hdrh_bar_name": plot_lat_hdrh_bar_name,
63 u"plot_lat_hdrh_percentile": plot_lat_hdrh_percentile,
64 u"plot_hdrh_lat_by_percentile": plot_hdrh_lat_by_percentile
67 logging.info(u"Generating the plots ...")
68 for index, plot in enumerate(spec.plots):
70 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
71 plot[u"limits"] = spec.configuration[u"limits"]
72 generator[plot[u"algorithm"]](plot, data)
73 logging.info(u" Done.")
74 except NameError as err:
76 f"Probably algorithm {plot[u'algorithm']} is not defined: "
79 logging.info(u"Done.")
82 def plot_lat_hdrh_percentile(plot, input_data):
83 """Generate the plot(s) with algorithm: plot_lat_hdrh_percentile
84 specified in the specification file.
86 :param plot: Plot to generate.
87 :param input_data: Data to process.
88 :type plot: pandas.Series
89 :type input_data: InputData
93 plot_title = plot.get(u"title", u"")
95 f" Creating the data set for the {plot.get(u'type', u'')} "
98 data = input_data.filter_tests_by_name(
99 plot, params=[u"latency", u"parent", u"tags", u"type"])
100 if data is None or len(data[0][0]) == 0:
101 logging.error(u"No data.")
106 # Prepare the data for the plot
107 directions = [u"W-E", u"E-W"]
108 for color, test in enumerate(data[0][0]):
110 if test[u"type"] in (u"NDRPDR",):
111 if u"-pdr" in plot_title.lower():
113 elif u"-ndr" in plot_title.lower():
116 logging.warning(f"Invalid test type: {test[u'type']}")
118 name = re.sub(REGEX_NIC, u"", test[u"parent"].
119 replace(u'-ndrpdr', u'').
120 replace(u'2n1l-', u''))
121 for idx, direction in enumerate(
122 (u"direction1", u"direction2", )):
124 hdr_lat = test[u"latency"][ttype][direction][u"hdrh"]
125 # TODO: Workaround, HDRH data must be aligned to 4
126 # bytes, remove when not needed.
127 hdr_lat += u"=" * (len(hdr_lat) % 4)
131 decoded = hdrh.histogram.HdrHistogram.decode(hdr_lat)
132 for item in decoded.get_recorded_iterator():
133 percentile = item.percentile_level_iterated_to
134 if percentile != 100.0:
135 xaxis.append(100.0 / (100.0 - percentile))
136 yaxis.append(item.value_iterated_to)
139 f"Direction: {directions[idx]}<br>"
140 f"Percentile: {percentile:.5f}%<br>"
141 f"Latency: {item.value_iterated_to}uSec"
150 showlegend=bool(idx),
158 except hdrh.codec.HdrLengthException as err:
160 f"No or invalid data for HDRHistogram for the test "
165 logging.warning(f"Invalid test type: {test[u'type']}")
167 except (ValueError, KeyError) as err:
168 logging.warning(repr(err))
170 layout = deepcopy(plot[u"layout"])
172 layout[u"title"][u"text"] = \
173 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
174 fig[u"layout"].update(layout)
177 file_type = plot.get(u"output-file-type", u".html")
178 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
181 ploff.plot(fig, show_link=False, auto_open=False,
182 filename=f"{plot[u'output-file']}{file_type}")
183 except PlotlyError as err:
184 logging.error(f" Finished with error: {repr(err)}")
187 def plot_hdrh_lat_by_percentile(plot, input_data):
188 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile
189 specified in the specification file.
191 :param plot: Plot to generate.
192 :param input_data: Data to process.
193 :type plot: pandas.Series
194 :type input_data: InputData
199 f" Creating the data set for the {plot.get(u'type', u'')} "
200 f"{plot.get(u'title', u'')}."
202 if plot.get(u"include", None):
203 data = input_data.filter_tests_by_name(
205 params=[u"latency", u"throughput", u"parent", u"tags", u"type"]
207 elif plot.get(u"filter", None):
208 data = input_data.filter_data(plot, continue_on_error=True)
210 job = list(plot[u"data"].keys())[0]
211 build = str(plot[u"data"][job][0])
212 data = input_data.tests(job, build)
214 if data is None or len(data) == 0:
215 logging.error(u"No data.")
219 u"LAT0": u"No-load.",
220 u"PDR10": u"Low-load, 10% PDR.",
221 u"PDR50": u"Mid-load, 50% PDR.",
222 u"PDR90": u"High-load, 90% PDR.",
223 u"PDR": u"Full-load, 100% PDR.",
224 u"NDR10": u"Low-load, 10% NDR.",
225 u"NDR50": u"Mid-load, 50% NDR.",
226 u"NDR90": u"High-load, 90% NDR.",
227 u"NDR": u"Full-load, 100% NDR."
237 file_links = plot.get(u"output-file-links", None)
238 target_links = plot.get(u"target-links", None)
242 if test[u"type"] not in (u"NDRPDR",):
243 logging.warning(f"Invalid test type: {test[u'type']}")
245 name = re.sub(REGEX_NIC, u"", test[u"parent"].
246 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
248 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
249 except (IndexError, AttributeError, KeyError, ValueError):
251 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
253 logging.info(f" Generating the graph: {name_link}")
256 layout = deepcopy(plot[u"layout"])
258 for color, graph in enumerate(graphs):
259 for idx, direction in enumerate((u"direction1", u"direction2")):
263 f"<b>{desc[graph]}</b><br>"
264 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
265 f"Percentile: 0.0%<br>"
268 decoded = hdrh.histogram.HdrHistogram.decode(
269 test[u"latency"][graph][direction][u"hdrh"]
271 for item in decoded.get_recorded_iterator():
272 percentile = item.percentile_level_iterated_to
273 if percentile > 99.9:
275 xaxis.append(percentile)
276 yaxis.append(item.value_iterated_to)
278 f"<b>{desc[graph]}</b><br>"
279 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
280 f"Percentile: {percentile:.5f}%<br>"
281 f"Latency: {item.value_iterated_to}uSec"
289 legendgroup=desc[graph],
290 showlegend=bool(idx),
293 dash=u"solid" if idx % 2 else u"dash"
300 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
301 fig.update_layout(layout)
304 file_name = f"{plot[u'output-file']}-{name_link}.html"
305 logging.info(f" Writing file {file_name}")
309 ploff.plot(fig, show_link=False, auto_open=False,
311 # Add link to the file:
312 if file_links and target_links:
313 with open(file_links, u"a") as fw:
316 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
318 except FileNotFoundError as err:
320 f"Not possible to write the link to the file "
321 f"{file_links}\n{err}"
323 except PlotlyError as err:
324 logging.error(f" Finished with error: {repr(err)}")
326 except hdrh.codec.HdrLengthException as err:
327 logging.warning(repr(err))
330 except (ValueError, KeyError) as err:
331 logging.warning(repr(err))
335 def plot_lat_hdrh_bar_name(plot, input_data):
336 """Generate the plot(s) with algorithm: plot_lat_hdrh_bar_name
337 specified in the specification file.
339 :param plot: Plot to generate.
340 :param input_data: Data to process.
341 :type plot: pandas.Series
342 :type input_data: InputData
346 plot_title = plot.get(u"title", u"")
348 f" Creating the data set for the {plot.get(u'type', u'')} "
351 data = input_data.filter_tests_by_name(
352 plot, params=[u"latency", u"parent", u"tags", u"type"])
353 if data is None or len(data[0][0]) == 0:
354 logging.error(u"No data.")
357 # Prepare the data for the plot
358 directions = [u"W-E", u"E-W"]
361 for idx_row, test in enumerate(data[0][0]):
363 if test[u"type"] in (u"NDRPDR",):
364 if u"-pdr" in plot_title.lower():
366 elif u"-ndr" in plot_title.lower():
369 logging.warning(f"Invalid test type: {test[u'type']}")
371 name = re.sub(REGEX_NIC, u"", test[u"parent"].
372 replace(u'-ndrpdr', u'').
373 replace(u'2n1l-', u''))
375 for idx_col, direction in enumerate(
376 (u"direction1", u"direction2", )):
378 hdr_lat = test[u"latency"][ttype][direction][u"hdrh"]
379 # TODO: Workaround, HDRH data must be aligned to 4
380 # bytes, remove when not needed.
381 hdr_lat += u"=" * (len(hdr_lat) % 4)
385 decoded = hdrh.histogram.HdrHistogram.decode(hdr_lat)
386 total_count = decoded.get_total_count()
387 for item in decoded.get_recorded_iterator():
388 xaxis.append(item.value_iterated_to)
389 prob = float(item.count_added_in_this_iter_step) / \
394 f"Direction: {directions[idx_col]}<br>"
395 f"Latency: {item.value_iterated_to}uSec<br>"
396 f"Probability: {prob:.2f}%<br>"
398 f"{item.percentile_level_iterated_to:.2f}"
400 marker_color = [COLORS[idx_row], ] * len(yaxis)
401 marker_color[xaxis.index(
402 decoded.get_value_at_percentile(50.0))] = u"red"
403 marker_color[xaxis.index(
404 decoded.get_value_at_percentile(90.0))] = u"red"
405 marker_color[xaxis.index(
406 decoded.get_value_at_percentile(95.0))] = u"red"
413 marker={u"color": marker_color},
418 except hdrh.codec.HdrLengthException as err:
420 f"No or invalid data for HDRHistogram for the test "
424 if len(histograms) == 2:
425 traces.append(histograms)
428 logging.warning(f"Invalid test type: {test[u'type']}")
430 except (ValueError, KeyError) as err:
431 logging.warning(repr(err))
434 logging.warning(f"No data for {plot_title}.")
441 [{u"type": u"bar"}, {u"type": u"bar"}] for _ in range(len(tests))
446 gridcolor=u"rgb(220, 220, 220)",
447 linecolor=u"rgb(220, 220, 220)",
452 tickcolor=u"rgb(220, 220, 220)",
455 for idx_row, test in enumerate(tests):
456 for idx_col in range(2):
458 traces[idx_row][idx_col],
473 layout = deepcopy(plot[u"layout"])
475 layout[u"title"][u"text"] = \
476 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
477 layout[u"height"] = 250 * len(tests) + 130
479 layout[u"annotations"][2][u"y"] = 1.06 - 0.008 * len(tests)
480 layout[u"annotations"][3][u"y"] = 1.06 - 0.008 * len(tests)
482 for idx, test in enumerate(tests):
483 layout[u"annotations"].append({
488 u"text": f"<b>{test}</b>",
491 u"xanchor": u"center",
493 u"y": 1.0 - float(idx) * 1.06 / len(tests),
494 u"yanchor": u"bottom",
498 fig[u"layout"].update(layout)
501 file_type = plot.get(u"output-file-type", u".html")
502 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
505 ploff.plot(fig, show_link=False, auto_open=False,
506 filename=f"{plot[u'output-file']}{file_type}")
507 except PlotlyError as err:
508 logging.error(f" Finished with error: {repr(err)}")
511 def plot_nf_reconf_box_name(plot, input_data):
512 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
513 specified in the specification file.
515 :param plot: Plot to generate.
516 :param input_data: Data to process.
517 :type plot: pandas.Series
518 :type input_data: InputData
523 f" Creating the data set for the {plot.get(u'type', u'')} "
524 f"{plot.get(u'title', u'')}."
526 data = input_data.filter_tests_by_name(
527 plot, params=[u"result", u"parent", u"tags", u"type"]
530 logging.error(u"No data.")
533 # Prepare the data for the plot
534 y_vals = OrderedDict()
539 if y_vals.get(test[u"parent"], None) is None:
540 y_vals[test[u"parent"]] = list()
541 loss[test[u"parent"]] = list()
543 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
544 loss[test[u"parent"]].append(test[u"result"][u"loss"])
545 except (KeyError, TypeError):
546 y_vals[test[u"parent"]].append(None)
548 # Add None to the lists with missing data
550 nr_of_samples = list()
551 for val in y_vals.values():
552 if len(val) > max_len:
554 nr_of_samples.append(len(val))
555 for val in y_vals.values():
556 if len(val) < max_len:
557 val.extend([None for _ in range(max_len - len(val))])
561 df_y = pd.DataFrame(y_vals)
563 for i, col in enumerate(df_y.columns):
564 tst_name = re.sub(REGEX_NIC, u"",
565 col.lower().replace(u'-ndrpdr', u'').
566 replace(u'2n1l-', u''))
568 traces.append(plgo.Box(
569 x=[str(i + 1) + u'.'] * len(df_y[col]),
570 y=[y if y else None for y in df_y[col]],
573 f"({nr_of_samples[i]:02d} "
574 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
575 f"packets lost average: {mean(loss[col]):.1f}) "
576 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
582 layout = deepcopy(plot[u"layout"])
583 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
584 layout[u"yaxis"][u"title"] = u"<b>Implied Time Lost [s]</b>"
585 layout[u"legend"][u"font"][u"size"] = 14
586 layout[u"yaxis"].pop(u"range")
587 plpl = plgo.Figure(data=traces, layout=layout)
590 file_type = plot.get(u"output-file-type", u".html")
591 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
596 filename=f"{plot[u'output-file']}{file_type}"
598 except PlotlyError as err:
600 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
605 def plot_perf_box_name(plot, input_data):
606 """Generate the plot(s) with algorithm: plot_perf_box_name
607 specified in the specification file.
609 :param plot: Plot to generate.
610 :param input_data: Data to process.
611 :type plot: pandas.Series
612 :type input_data: InputData
617 f" Creating data set for the {plot.get(u'type', u'')} "
618 f"{plot.get(u'title', u'')}."
620 data = input_data.filter_tests_by_name(
621 plot, params=[u"throughput", u"parent", u"tags", u"type"])
623 logging.error(u"No data.")
626 # Prepare the data for the plot
627 y_vals = OrderedDict()
631 if y_vals.get(test[u"parent"], None) is None:
632 y_vals[test[u"parent"]] = list()
634 if (test[u"type"] in (u"NDRPDR", ) and
635 u"-pdr" in plot.get(u"title", u"").lower()):
636 y_vals[test[u"parent"]].\
637 append(test[u"throughput"][u"PDR"][u"LOWER"])
638 elif (test[u"type"] in (u"NDRPDR", ) and
639 u"-ndr" in plot.get(u"title", u"").lower()):
640 y_vals[test[u"parent"]]. \
641 append(test[u"throughput"][u"NDR"][u"LOWER"])
642 elif test[u"type"] in (u"SOAK", ):
643 y_vals[test[u"parent"]].\
644 append(test[u"throughput"][u"LOWER"])
647 except (KeyError, TypeError):
648 y_vals[test[u"parent"]].append(None)
650 # Add None to the lists with missing data
652 nr_of_samples = list()
653 for val in y_vals.values():
654 if len(val) > max_len:
656 nr_of_samples.append(len(val))
657 for val in y_vals.values():
658 if len(val) < max_len:
659 val.extend([None for _ in range(max_len - len(val))])
663 df_y = pd.DataFrame(y_vals)
666 for i, col in enumerate(df_y.columns):
667 tst_name = re.sub(REGEX_NIC, u"",
668 col.lower().replace(u'-ndrpdr', u'').
669 replace(u'2n1l-', u''))
672 x=[str(i + 1) + u'.'] * len(df_y[col]),
673 y=[y / 1000000 if y else None for y in df_y[col]],
676 f"({nr_of_samples[i]:02d} "
677 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
684 val_max = max(df_y[col])
686 y_max.append(int(val_max / 1000000) + 2)
687 except (ValueError, TypeError) as err:
688 logging.error(repr(err))
693 layout = deepcopy(plot[u"layout"])
694 if layout.get(u"title", None):
695 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
697 layout[u"yaxis"][u"range"] = [0, max(y_max)]
698 plpl = plgo.Figure(data=traces, layout=layout)
701 logging.info(f" Writing file {plot[u'output-file']}.html.")
706 filename=f"{plot[u'output-file']}.html"
708 except PlotlyError as err:
710 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
715 def plot_lat_err_bars_name(plot, input_data):
716 """Generate the plot(s) with algorithm: plot_lat_err_bars_name
717 specified in the specification file.
719 :param plot: Plot to generate.
720 :param input_data: Data to process.
721 :type plot: pandas.Series
722 :type input_data: InputData
726 plot_title = plot.get(u"title", u"")
728 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
730 data = input_data.filter_tests_by_name(
731 plot, params=[u"latency", u"parent", u"tags", u"type"])
733 logging.error(u"No data.")
736 # Prepare the data for the plot
737 y_tmp_vals = OrderedDict()
742 logging.debug(f"test[u'latency']: {test[u'latency']}\n")
743 except ValueError as err:
744 logging.warning(repr(err))
745 if y_tmp_vals.get(test[u"parent"], None) is None:
746 y_tmp_vals[test[u"parent"]] = [
747 list(), # direction1, min
748 list(), # direction1, avg
749 list(), # direction1, max
750 list(), # direction2, min
751 list(), # direction2, avg
752 list() # direction2, max
755 if test[u"type"] not in (u"NDRPDR", ):
756 logging.warning(f"Invalid test type: {test[u'type']}")
758 if u"-pdr" in plot_title.lower():
760 elif u"-ndr" in plot_title.lower():
764 f"Invalid test type: {test[u'type']}"
767 y_tmp_vals[test[u"parent"]][0].append(
768 test[u"latency"][ttype][u"direction1"][u"min"])
769 y_tmp_vals[test[u"parent"]][1].append(
770 test[u"latency"][ttype][u"direction1"][u"avg"])
771 y_tmp_vals[test[u"parent"]][2].append(
772 test[u"latency"][ttype][u"direction1"][u"max"])
773 y_tmp_vals[test[u"parent"]][3].append(
774 test[u"latency"][ttype][u"direction2"][u"min"])
775 y_tmp_vals[test[u"parent"]][4].append(
776 test[u"latency"][ttype][u"direction2"][u"avg"])
777 y_tmp_vals[test[u"parent"]][5].append(
778 test[u"latency"][ttype][u"direction2"][u"max"])
779 except (KeyError, TypeError) as err:
780 logging.warning(repr(err))
786 nr_of_samples = list()
787 for key, val in y_tmp_vals.items():
788 name = re.sub(REGEX_NIC, u"", key.replace(u'-ndrpdr', u'').
789 replace(u'2n1l-', u''))
790 x_vals.append(name) # dir 1
791 y_vals.append(mean(val[1]) if val[1] else None)
792 y_mins.append(mean(val[0]) if val[0] else None)
793 y_maxs.append(mean(val[2]) if val[2] else None)
794 nr_of_samples.append(len(val[1]) if val[1] else 0)
795 x_vals.append(name) # dir 2
796 y_vals.append(mean(val[4]) if val[4] else None)
797 y_mins.append(mean(val[3]) if val[3] else None)
798 y_maxs.append(mean(val[5]) if val[5] else None)
799 nr_of_samples.append(len(val[3]) if val[3] else 0)
804 for idx, _ in enumerate(x_vals):
805 if not bool(int(idx % 2)):
806 direction = u"West-East"
808 direction = u"East-West"
810 f"No. of Runs: {nr_of_samples[idx]}<br>"
811 f"Test: {x_vals[idx]}<br>"
812 f"Direction: {direction}<br>"
814 if isinstance(y_maxs[idx], float):
815 hovertext += f"Max: {y_maxs[idx]:.2f}uSec<br>"
816 if isinstance(y_vals[idx], float):
817 hovertext += f"Mean: {y_vals[idx]:.2f}uSec<br>"
818 if isinstance(y_mins[idx], float):
819 hovertext += f"Min: {y_mins[idx]:.2f}uSec"
821 if isinstance(y_maxs[idx], float) and isinstance(y_vals[idx], float):
822 array = [y_maxs[idx] - y_vals[idx], ]
825 if isinstance(y_mins[idx], float) and isinstance(y_vals[idx], float):
826 arrayminus = [y_vals[idx] - y_mins[idx], ]
828 arrayminus = [None, ]
829 traces.append(plgo.Scatter(
833 legendgroup=x_vals[idx],
834 showlegend=bool(int(idx % 2)),
840 arrayminus=arrayminus,
841 color=COLORS[int(idx / 2)]
845 color=COLORS[int(idx / 2)],
850 annotations.append(dict(
857 text=u"E-W" if bool(int(idx % 2)) else u"W-E",
867 file_type = plot.get(u"output-file-type", u".html")
868 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
869 layout = deepcopy(plot[u"layout"])
870 if layout.get(u"title", None):
871 layout[u"title"] = f"<b>Latency:</b> {layout[u'title']}"
872 layout[u"annotations"] = annotations
873 plpl = plgo.Figure(data=traces, layout=layout)
878 show_link=False, auto_open=False,
879 filename=f"{plot[u'output-file']}{file_type}"
881 except PlotlyError as err:
883 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
888 def plot_tsa_name(plot, input_data):
889 """Generate the plot(s) with algorithm:
891 specified in the specification file.
893 :param plot: Plot to generate.
894 :param input_data: Data to process.
895 :type plot: pandas.Series
896 :type input_data: InputData
900 plot_title = plot.get(u"title", u"")
902 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
904 data = input_data.filter_tests_by_name(
905 plot, params=[u"throughput", u"parent", u"tags", u"type"])
907 logging.error(u"No data.")
910 y_vals = OrderedDict()
914 if y_vals.get(test[u"parent"], None) is None:
915 y_vals[test[u"parent"]] = {
921 if test[u"type"] not in (u"NDRPDR",):
924 if u"-pdr" in plot_title.lower():
926 elif u"-ndr" in plot_title.lower():
931 if u"1C" in test[u"tags"]:
932 y_vals[test[u"parent"]][u"1"]. \
933 append(test[u"throughput"][ttype][u"LOWER"])
934 elif u"2C" in test[u"tags"]:
935 y_vals[test[u"parent"]][u"2"]. \
936 append(test[u"throughput"][ttype][u"LOWER"])
937 elif u"4C" in test[u"tags"]:
938 y_vals[test[u"parent"]][u"4"]. \
939 append(test[u"throughput"][ttype][u"LOWER"])
940 except (KeyError, TypeError):
944 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
948 for test_name, test_vals in y_vals.items():
949 for key, test_val in test_vals.items():
951 avg_val = sum(test_val) / len(test_val)
952 y_vals[test_name][key] = [avg_val, len(test_val)]
953 ideal = avg_val / (int(key) * 1000000.0)
954 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
955 y_1c_max[test_name] = ideal
961 pci_limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
962 for test_name, test_vals in y_vals.items():
964 if test_vals[u"1"][1]:
968 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
970 vals[name] = OrderedDict()
971 y_val_1 = test_vals[u"1"][0] / 1000000.0
972 y_val_2 = test_vals[u"2"][0] / 1000000.0 if test_vals[u"2"][0] \
974 y_val_4 = test_vals[u"4"][0] / 1000000.0 if test_vals[u"4"][0] \
977 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
978 vals[name][u"rel"] = [1.0, None, None]
979 vals[name][u"ideal"] = [
981 y_1c_max[test_name] * 2,
982 y_1c_max[test_name] * 4
984 vals[name][u"diff"] = [
985 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
987 vals[name][u"count"] = [
994 val_max = max(vals[name][u"val"])
995 except ValueError as err:
996 logging.error(repr(err))
999 y_max.append(val_max)
1002 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
1003 vals[name][u"diff"][1] = \
1004 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
1006 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
1007 vals[name][u"diff"][2] = \
1008 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
1009 except IndexError as err:
1010 logging.warning(f"No data for {test_name}")
1011 logging.warning(repr(err))
1014 if u"x520" in test_name:
1015 limit = plot[u"limits"][u"nic"][u"x520"]
1016 elif u"x710" in test_name:
1017 limit = plot[u"limits"][u"nic"][u"x710"]
1018 elif u"xxv710" in test_name:
1019 limit = plot[u"limits"][u"nic"][u"xxv710"]
1020 elif u"xl710" in test_name:
1021 limit = plot[u"limits"][u"nic"][u"xl710"]
1022 elif u"x553" in test_name:
1023 limit = plot[u"limits"][u"nic"][u"x553"]
1026 if limit > nic_limit:
1029 mul = 2 if u"ge2p" in test_name else 1
1030 if u"10ge" in test_name:
1031 limit = plot[u"limits"][u"link"][u"10ge"] * mul
1032 elif u"25ge" in test_name:
1033 limit = plot[u"limits"][u"link"][u"25ge"] * mul
1034 elif u"40ge" in test_name:
1035 limit = plot[u"limits"][u"link"][u"40ge"] * mul
1036 elif u"100ge" in test_name:
1037 limit = plot[u"limits"][u"link"][u"100ge"] * mul
1040 if limit > lnk_limit:
1044 annotations = list()
1049 threshold = 1.1 * max(y_max) # 10%
1050 except ValueError as err:
1053 nic_limit /= 1000000.0
1054 traces.append(plgo.Scatter(
1056 y=[nic_limit, ] * len(x_vals),
1057 name=f"NIC: {nic_limit:.2f}Mpps",
1066 annotations.append(dict(
1073 text=f"NIC: {nic_limit:.2f}Mpps",
1081 y_max.append(nic_limit)
1083 lnk_limit /= 1000000.0
1084 if lnk_limit < threshold:
1085 traces.append(plgo.Scatter(
1087 y=[lnk_limit, ] * len(x_vals),
1088 name=f"Link: {lnk_limit:.2f}Mpps",
1097 annotations.append(dict(
1104 text=f"Link: {lnk_limit:.2f}Mpps",
1112 y_max.append(lnk_limit)
1114 pci_limit /= 1000000.0
1115 if (pci_limit < threshold and
1116 (pci_limit < lnk_limit * 0.95 or lnk_limit > lnk_limit * 1.05)):
1117 traces.append(plgo.Scatter(
1119 y=[pci_limit, ] * len(x_vals),
1120 name=f"PCIe: {pci_limit:.2f}Mpps",
1129 annotations.append(dict(
1136 text=f"PCIe: {pci_limit:.2f}Mpps",
1144 y_max.append(pci_limit)
1146 # Perfect and measured:
1148 for name, val in vals.items():
1151 for idx in range(len(val[u"val"])):
1153 if isinstance(val[u"val"][idx], float):
1155 f"No. of Runs: {val[u'count'][idx]}<br>"
1156 f"Mean: {val[u'val'][idx]:.2f}Mpps<br>"
1158 if isinstance(val[u"diff"][idx], float):
1159 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
1160 if isinstance(val[u"rel"][idx], float):
1161 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
1162 hovertext.append(htext)
1169 mode=u"lines+markers",
1178 hoverinfo=u"text+name"
1185 name=f"{name} perfect",
1193 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1198 except (IndexError, ValueError, KeyError) as err:
1199 logging.warning(f"No data for {name}\n{repr(err)}")
1203 file_type = plot.get(u"output-file-type", u".html")
1204 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1205 layout = deepcopy(plot[u"layout"])
1206 if layout.get(u"title", None):
1207 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1208 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1209 layout[u"annotations"].extend(annotations)
1210 plpl = plgo.Figure(data=traces, layout=layout)
1217 filename=f"{plot[u'output-file']}{file_type}"
1219 except PlotlyError as err:
1221 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1226 def plot_http_server_perf_box(plot, input_data):
1227 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1228 specified in the specification file.
1230 :param plot: Plot to generate.
1231 :param input_data: Data to process.
1232 :type plot: pandas.Series
1233 :type input_data: InputData
1236 # Transform the data
1238 f" Creating the data set for the {plot.get(u'type', u'')} "
1239 f"{plot.get(u'title', u'')}."
1241 data = input_data.filter_data(plot)
1243 logging.error(u"No data.")
1246 # Prepare the data for the plot
1251 if y_vals.get(test[u"name"], None) is None:
1252 y_vals[test[u"name"]] = list()
1254 y_vals[test[u"name"]].append(test[u"result"])
1255 except (KeyError, TypeError):
1256 y_vals[test[u"name"]].append(None)
1258 # Add None to the lists with missing data
1260 nr_of_samples = list()
1261 for val in y_vals.values():
1262 if len(val) > max_len:
1264 nr_of_samples.append(len(val))
1265 for val in y_vals.values():
1266 if len(val) < max_len:
1267 val.extend([None for _ in range(max_len - len(val))])
1271 df_y = pd.DataFrame(y_vals)
1273 for i, col in enumerate(df_y.columns):
1276 f"({nr_of_samples[i]:02d} " \
1277 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1278 f"{col.lower().replace(u'-ndrpdr', u'')}"
1280 name_lst = name.split(u'-')
1283 for segment in name_lst:
1284 if (len(name) + len(segment) + 1) > 50 and split_name:
1287 name += segment + u'-'
1290 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1296 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1300 f" Writing file {plot[u'output-file']}"
1301 f"{plot[u'output-file-type']}."
1307 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1309 except PlotlyError as err:
1311 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1316 def plot_nf_heatmap(plot, input_data):
1317 """Generate the plot(s) with algorithm: plot_nf_heatmap
1318 specified in the specification file.
1320 :param plot: Plot to generate.
1321 :param input_data: Data to process.
1322 :type plot: pandas.Series
1323 :type input_data: InputData
1326 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1327 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1329 r'(\d+vm\d+t|\d+dcr\d+t).*$')
1332 # Transform the data
1334 f" Creating the data set for the {plot.get(u'type', u'')} "
1335 f"{plot.get(u'title', u'')}."
1337 data = input_data.filter_data(plot, continue_on_error=True)
1338 if data is None or data.empty:
1339 logging.error(u"No data.")
1345 for tag in test[u"tags"]:
1346 groups = re.search(regex_cn, tag)
1348 chain = str(groups.group(1))
1349 node = str(groups.group(2))
1353 groups = re.search(regex_test_name, test[u"name"])
1354 if groups and len(groups.groups()) == 3:
1356 f"{str(groups.group(1))}-"
1357 f"{str(groups.group(2))}-"
1358 f"{str(groups.group(3))}"
1362 if vals.get(chain, None) is None:
1363 vals[chain] = dict()
1364 if vals[chain].get(node, None) is None:
1365 vals[chain][node] = dict(
1373 if plot[u"include-tests"] == u"MRR":
1374 result = test[u"result"][u"receive-rate"]
1375 elif plot[u"include-tests"] == u"PDR":
1376 result = test[u"throughput"][u"PDR"][u"LOWER"]
1377 elif plot[u"include-tests"] == u"NDR":
1378 result = test[u"throughput"][u"NDR"][u"LOWER"]
1385 vals[chain][node][u"vals"].append(result)
1388 logging.error(u"No data.")
1394 txt_chains.append(key_c)
1395 for key_n in vals[key_c].keys():
1396 txt_nodes.append(key_n)
1397 if vals[key_c][key_n][u"vals"]:
1398 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1399 vals[key_c][key_n][u"mean"] = \
1400 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1401 vals[key_c][key_n][u"stdev"] = \
1402 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1403 txt_nodes = list(set(txt_nodes))
1405 def sort_by_int(value):
1406 """Makes possible to sort a list of strings which represent integers.
1408 :param value: Integer as a string.
1410 :returns: Integer representation of input parameter 'value'.
1415 txt_chains = sorted(txt_chains, key=sort_by_int)
1416 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1418 chains = [i + 1 for i in range(len(txt_chains))]
1419 nodes = [i + 1 for i in range(len(txt_nodes))]
1421 data = [list() for _ in range(len(chains))]
1422 for chain in chains:
1425 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1426 except (KeyError, IndexError):
1428 data[chain - 1].append(val)
1431 my_green = [[0.0, u"rgb(235, 249, 242)"],
1432 [1.0, u"rgb(45, 134, 89)"]]
1434 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1435 [1.0, u"rgb(57, 115, 172)"]]
1437 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1438 [1.0, u"rgb(102, 102, 102)"]]
1441 annotations = list()
1443 text = (u"Test: {name}<br>"
1448 for chain, _ in enumerate(txt_chains):
1450 for node, _ in enumerate(txt_nodes):
1451 if data[chain][node] is not None:
1460 text=str(data[chain][node]),
1468 hover_line.append(text.format(
1469 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1470 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1471 val=data[chain][node],
1472 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1473 hovertext.append(hover_line)
1481 title=plot.get(u"z-axis", u""),
1495 colorscale=my_green,
1501 for idx, item in enumerate(txt_nodes):
1519 for idx, item in enumerate(txt_chains):
1546 text=plot.get(u"x-axis", u""),
1563 text=plot.get(u"y-axis", u""),
1572 updatemenus = list([
1583 u"colorscale": [my_green, ],
1584 u"reversescale": False
1593 u"colorscale": [my_blue, ],
1594 u"reversescale": False
1603 u"colorscale": [my_grey, ],
1604 u"reversescale": False
1615 layout = deepcopy(plot[u"layout"])
1616 except KeyError as err:
1617 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1620 layout[u"annotations"] = annotations
1621 layout[u'updatemenus'] = updatemenus
1625 plpl = plgo.Figure(data=traces, layout=layout)
1628 logging.info(f" Writing file {plot[u'output-file']}.html")
1633 filename=f"{plot[u'output-file']}.html"
1635 except PlotlyError as err:
1637 f" Finished with error: {repr(err)}".replace(u"\n", u" ")