1 # Copyright (c) 2019 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*-')
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
66 logging.info(u"Generating the plots ...")
67 for index, plot in enumerate(spec.plots):
69 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
70 plot[u"limits"] = spec.configuration[u"limits"]
71 generator[plot[u"algorithm"]](plot, data)
72 logging.info(u" Done.")
73 except NameError as err:
75 f"Probably algorithm {plot[u'algorithm']} is not defined: "
78 logging.info(u"Done.")
81 def plot_lat_hdrh_percentile(plot, input_data):
82 """Generate the plot(s) with algorithm: plot_lat_hdrh_percentile
83 specified in the specification file.
85 :param plot: Plot to generate.
86 :param input_data: Data to process.
87 :type plot: pandas.Series
88 :type input_data: InputData
92 plot_title = plot.get(u"title", u"")
94 f" Creating the data set for the {plot.get(u'type', u'')} "
97 data = input_data.filter_tests_by_name(
98 plot, params=[u"latency", u"parent", u"tags", u"type"])
99 if data is None or len(data[0][0]) == 0:
100 logging.error(u"No data.")
105 # Prepare the data for the plot
106 directions = [u"W-E", u"E-W"]
107 for color, test in enumerate(data[0][0]):
109 if test[u"type"] in (u"NDRPDR",):
110 if u"-pdr" in plot_title.lower():
112 elif u"-ndr" in plot_title.lower():
115 logging.warning(f"Invalid test type: {test[u'type']}")
117 name = re.sub(REGEX_NIC, u"", test[u"parent"].
118 replace(u'-ndrpdr', u'').
119 replace(u'2n1l-', u'').
120 replace(u'avf-', 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_lat_hdrh_bar_name(plot, input_data):
188 """Generate the plot(s) with algorithm: plot_lat_hdrh_bar_name
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
198 plot_title = plot.get(u"title", u"")
200 f" Creating the data set for the {plot.get(u'type', u'')} "
203 data = input_data.filter_tests_by_name(
204 plot, params=[u"latency", u"parent", u"tags", u"type"])
205 if data is None or len(data[0][0]) == 0:
206 logging.error(u"No data.")
209 # Prepare the data for the plot
210 directions = [u"W-E", u"E-W"]
213 for idx_row, test in enumerate(data[0][0]):
215 if test[u"type"] in (u"NDRPDR",):
216 if u"-pdr" in plot_title.lower():
218 elif u"-ndr" in plot_title.lower():
221 logging.warning(f"Invalid test type: {test[u'type']}")
223 name = re.sub(REGEX_NIC, u"", test[u"parent"].
224 replace(u'-ndrpdr', u'').
225 replace(u'2n1l-', u''))
227 for idx_col, direction in enumerate(
228 (u"direction1", u"direction2", )):
230 hdr_lat = test[u"latency"][ttype][direction][u"hdrh"]
231 # TODO: Workaround, HDRH data must be aligned to 4
232 # bytes, remove when not needed.
233 hdr_lat += u"=" * (len(hdr_lat) % 4)
237 decoded = hdrh.histogram.HdrHistogram.decode(hdr_lat)
238 total_count = decoded.get_total_count()
239 for item in decoded.get_recorded_iterator():
240 xaxis.append(item.value_iterated_to)
241 prob = float(item.count_added_in_this_iter_step) / \
246 f"Direction: {directions[idx_col]}<br>"
247 f"Latency: {item.value_iterated_to}uSec<br>"
248 f"Probability: {prob:.2f}%<br>"
250 f"{item.percentile_level_iterated_to:.2f}"
252 marker_color = [COLORS[idx_row], ] * len(yaxis)
253 marker_color[xaxis.index(
254 decoded.get_value_at_percentile(50.0))] = u"red"
255 marker_color[xaxis.index(
256 decoded.get_value_at_percentile(90.0))] = u"red"
257 marker_color[xaxis.index(
258 decoded.get_value_at_percentile(95.0))] = u"red"
265 marker={u"color": marker_color},
270 except hdrh.codec.HdrLengthException as err:
272 f"No or invalid data for HDRHistogram for the test "
276 if len(histograms) == 2:
277 traces.append(histograms)
280 logging.warning(f"Invalid test type: {test[u'type']}")
282 except (ValueError, KeyError) as err:
283 logging.warning(repr(err))
286 logging.warning(f"No data for {plot_title}.")
293 [{u"type": u"bar"}, {u"type": u"bar"}] for _ in range(len(tests))
298 gridcolor=u"rgb(220, 220, 220)",
299 linecolor=u"rgb(220, 220, 220)",
304 tickcolor=u"rgb(220, 220, 220)",
307 for idx_row, test in enumerate(tests):
308 for idx_col in range(2):
310 traces[idx_row][idx_col],
325 layout = deepcopy(plot[u"layout"])
327 layout[u"title"][u"text"] = \
328 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
329 layout[u"height"] = 250 * len(tests) + 130
331 layout[u"annotations"][2][u"y"] = 1.06 - 0.008 * len(tests)
332 layout[u"annotations"][3][u"y"] = 1.06 - 0.008 * len(tests)
334 for idx, test in enumerate(tests):
335 layout[u"annotations"].append({
340 u"text": f"<b>{test}</b>",
343 u"xanchor": u"center",
345 u"y": 1.0 - float(idx) * 1.06 / len(tests),
346 u"yanchor": u"bottom",
350 fig[u"layout"].update(layout)
353 file_type = plot.get(u"output-file-type", u".html")
354 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
357 ploff.plot(fig, show_link=False, auto_open=False,
358 filename=f"{plot[u'output-file']}{file_type}")
359 except PlotlyError as err:
360 logging.error(f" Finished with error: {repr(err)}")
363 def plot_nf_reconf_box_name(plot, input_data):
364 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
365 specified in the specification file.
367 :param plot: Plot to generate.
368 :param input_data: Data to process.
369 :type plot: pandas.Series
370 :type input_data: InputData
375 f" Creating the data set for the {plot.get(u'type', u'')} "
376 f"{plot.get(u'title', u'')}."
378 data = input_data.filter_tests_by_name(
379 plot, params=[u"result", u"parent", u"tags", u"type"]
382 logging.error(u"No data.")
385 # Prepare the data for the plot
386 y_vals = OrderedDict()
391 if y_vals.get(test[u"parent"], None) is None:
392 y_vals[test[u"parent"]] = list()
393 loss[test[u"parent"]] = list()
395 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
396 loss[test[u"parent"]].append(test[u"result"][u"loss"])
397 except (KeyError, TypeError):
398 y_vals[test[u"parent"]].append(None)
400 # Add None to the lists with missing data
402 nr_of_samples = list()
403 for val in y_vals.values():
404 if len(val) > max_len:
406 nr_of_samples.append(len(val))
407 for val in y_vals.values():
408 if len(val) < max_len:
409 val.extend([None for _ in range(max_len - len(val))])
413 df_y = pd.DataFrame(y_vals)
415 for i, col in enumerate(df_y.columns):
416 tst_name = re.sub(REGEX_NIC, u"",
417 col.lower().replace(u'-ndrpdr', u'').
418 replace(u'2n1l-', u''))
420 traces.append(plgo.Box(
421 x=[str(i + 1) + u'.'] * len(df_y[col]),
422 y=[y if y else None for y in df_y[col]],
425 f"({nr_of_samples[i]:02d} "
426 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
427 f"packets lost average: {mean(loss[col]):.1f}) "
428 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
434 layout = deepcopy(plot[u"layout"])
435 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
436 layout[u"yaxis"][u"title"] = u"<b>Implied Time Lost [s]</b>"
437 layout[u"legend"][u"font"][u"size"] = 14
438 layout[u"yaxis"].pop(u"range")
439 plpl = plgo.Figure(data=traces, layout=layout)
442 file_type = plot.get(u"output-file-type", u".html")
443 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
448 filename=f"{plot[u'output-file']}{file_type}"
450 except PlotlyError as err:
452 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
457 def plot_perf_box_name(plot, input_data):
458 """Generate the plot(s) with algorithm: plot_perf_box_name
459 specified in the specification file.
461 :param plot: Plot to generate.
462 :param input_data: Data to process.
463 :type plot: pandas.Series
464 :type input_data: InputData
469 f" Creating data set for the {plot.get(u'type', u'')} "
470 f"{plot.get(u'title', u'')}."
472 data = input_data.filter_tests_by_name(
473 plot, params=[u"throughput", u"parent", u"tags", u"type"])
475 logging.error(u"No data.")
478 # Prepare the data for the plot
479 y_vals = OrderedDict()
483 if y_vals.get(test[u"parent"], None) is None:
484 y_vals[test[u"parent"]] = list()
486 if (test[u"type"] in (u"NDRPDR", ) and
487 u"-pdr" in plot.get(u"title", u"").lower()):
488 y_vals[test[u"parent"]].\
489 append(test[u"throughput"][u"PDR"][u"LOWER"])
490 elif (test[u"type"] in (u"NDRPDR", ) and
491 u"-ndr" in plot.get(u"title", u"").lower()):
492 y_vals[test[u"parent"]]. \
493 append(test[u"throughput"][u"NDR"][u"LOWER"])
494 elif test[u"type"] in (u"SOAK", ):
495 y_vals[test[u"parent"]].\
496 append(test[u"throughput"][u"LOWER"])
499 except (KeyError, TypeError):
500 y_vals[test[u"parent"]].append(None)
502 # Add None to the lists with missing data
504 nr_of_samples = list()
505 for val in y_vals.values():
506 if len(val) > max_len:
508 nr_of_samples.append(len(val))
509 for val in y_vals.values():
510 if len(val) < max_len:
511 val.extend([None for _ in range(max_len - len(val))])
515 df_y = pd.DataFrame(y_vals)
518 for i, col in enumerate(df_y.columns):
519 tst_name = re.sub(REGEX_NIC, u"",
520 col.lower().replace(u'-ndrpdr', u'').
521 replace(u'2n1l-', u''))
524 x=[str(i + 1) + u'.'] * len(df_y[col]),
525 y=[y / 1000000 if y else None for y in df_y[col]],
528 f"({nr_of_samples[i]:02d} "
529 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
536 val_max = max(df_y[col])
538 y_max.append(int(val_max / 1000000) + 2)
539 except (ValueError, TypeError) as err:
540 logging.error(repr(err))
545 layout = deepcopy(plot[u"layout"])
546 if layout.get(u"title", None):
547 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
549 layout[u"yaxis"][u"range"] = [0, max(y_max)]
550 plpl = plgo.Figure(data=traces, layout=layout)
553 logging.info(f" Writing file {plot[u'output-file']}.html.")
558 filename=f"{plot[u'output-file']}.html"
560 except PlotlyError as err:
562 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
567 def plot_lat_err_bars_name(plot, input_data):
568 """Generate the plot(s) with algorithm: plot_lat_err_bars_name
569 specified in the specification file.
571 :param plot: Plot to generate.
572 :param input_data: Data to process.
573 :type plot: pandas.Series
574 :type input_data: InputData
578 plot_title = plot.get(u"title", u"")
580 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
582 data = input_data.filter_tests_by_name(
583 plot, params=[u"latency", u"parent", u"tags", u"type"])
585 logging.error(u"No data.")
588 # Prepare the data for the plot
589 y_tmp_vals = OrderedDict()
594 logging.debug(f"test[u'latency']: {test[u'latency']}\n")
595 except ValueError as err:
596 logging.warning(repr(err))
597 if y_tmp_vals.get(test[u"parent"], None) is None:
598 y_tmp_vals[test[u"parent"]] = [
599 list(), # direction1, min
600 list(), # direction1, avg
601 list(), # direction1, max
602 list(), # direction2, min
603 list(), # direction2, avg
604 list() # direction2, max
607 if test[u"type"] not in (u"NDRPDR", ):
608 logging.warning(f"Invalid test type: {test[u'type']}")
610 if u"-pdr" in plot_title.lower():
612 elif u"-ndr" in plot_title.lower():
616 f"Invalid test type: {test[u'type']}"
619 y_tmp_vals[test[u"parent"]][0].append(
620 test[u"latency"][ttype][u"direction1"][u"min"])
621 y_tmp_vals[test[u"parent"]][1].append(
622 test[u"latency"][ttype][u"direction1"][u"avg"])
623 y_tmp_vals[test[u"parent"]][2].append(
624 test[u"latency"][ttype][u"direction1"][u"max"])
625 y_tmp_vals[test[u"parent"]][3].append(
626 test[u"latency"][ttype][u"direction2"][u"min"])
627 y_tmp_vals[test[u"parent"]][4].append(
628 test[u"latency"][ttype][u"direction2"][u"avg"])
629 y_tmp_vals[test[u"parent"]][5].append(
630 test[u"latency"][ttype][u"direction2"][u"max"])
631 except (KeyError, TypeError) as err:
632 logging.warning(repr(err))
638 nr_of_samples = list()
639 for key, val in y_tmp_vals.items():
640 name = re.sub(REGEX_NIC, u"", key.replace(u'-ndrpdr', u'').
641 replace(u'2n1l-', u''))
642 x_vals.append(name) # dir 1
643 y_vals.append(mean(val[1]) if val[1] else None)
644 y_mins.append(mean(val[0]) if val[0] else None)
645 y_maxs.append(mean(val[2]) if val[2] else None)
646 nr_of_samples.append(len(val[1]) if val[1] else 0)
647 x_vals.append(name) # dir 2
648 y_vals.append(mean(val[4]) if val[4] else None)
649 y_mins.append(mean(val[3]) if val[3] else None)
650 y_maxs.append(mean(val[5]) if val[5] else None)
651 nr_of_samples.append(len(val[3]) if val[3] else 0)
656 for idx, _ in enumerate(x_vals):
657 if not bool(int(idx % 2)):
658 direction = u"West-East"
660 direction = u"East-West"
662 f"No. of Runs: {nr_of_samples[idx]}<br>"
663 f"Test: {x_vals[idx]}<br>"
664 f"Direction: {direction}<br>"
666 if isinstance(y_maxs[idx], float):
667 hovertext += f"Max: {y_maxs[idx]:.2f}uSec<br>"
668 if isinstance(y_vals[idx], float):
669 hovertext += f"Mean: {y_vals[idx]:.2f}uSec<br>"
670 if isinstance(y_mins[idx], float):
671 hovertext += f"Min: {y_mins[idx]:.2f}uSec"
673 if isinstance(y_maxs[idx], float) and isinstance(y_vals[idx], float):
674 array = [y_maxs[idx] - y_vals[idx], ]
677 if isinstance(y_mins[idx], float) and isinstance(y_vals[idx], float):
678 arrayminus = [y_vals[idx] - y_mins[idx], ]
680 arrayminus = [None, ]
681 traces.append(plgo.Scatter(
685 legendgroup=x_vals[idx],
686 showlegend=bool(int(idx % 2)),
692 arrayminus=arrayminus,
693 color=COLORS[int(idx / 2)]
697 color=COLORS[int(idx / 2)],
702 annotations.append(dict(
709 text=u"E-W" if bool(int(idx % 2)) else u"W-E",
719 file_type = plot.get(u"output-file-type", u".html")
720 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
721 layout = deepcopy(plot[u"layout"])
722 if layout.get(u"title", None):
723 layout[u"title"] = f"<b>Latency:</b> {layout[u'title']}"
724 layout[u"annotations"] = annotations
725 plpl = plgo.Figure(data=traces, layout=layout)
730 show_link=False, auto_open=False,
731 filename=f"{plot[u'output-file']}{file_type}"
733 except PlotlyError as err:
735 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
740 def plot_tsa_name(plot, input_data):
741 """Generate the plot(s) with algorithm:
743 specified in the specification file.
745 :param plot: Plot to generate.
746 :param input_data: Data to process.
747 :type plot: pandas.Series
748 :type input_data: InputData
752 plot_title = plot.get(u"title", u"")
754 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
756 data = input_data.filter_tests_by_name(
757 plot, params=[u"throughput", u"parent", u"tags", u"type"])
759 logging.error(u"No data.")
762 y_vals = OrderedDict()
766 if y_vals.get(test[u"parent"], None) is None:
767 y_vals[test[u"parent"]] = {
773 if test[u"type"] not in (u"NDRPDR",):
776 if u"-pdr" in plot_title.lower():
778 elif u"-ndr" in plot_title.lower():
783 if u"1C" in test[u"tags"]:
784 y_vals[test[u"parent"]][u"1"]. \
785 append(test[u"throughput"][ttype][u"LOWER"])
786 elif u"2C" in test[u"tags"]:
787 y_vals[test[u"parent"]][u"2"]. \
788 append(test[u"throughput"][ttype][u"LOWER"])
789 elif u"4C" in test[u"tags"]:
790 y_vals[test[u"parent"]][u"4"]. \
791 append(test[u"throughput"][ttype][u"LOWER"])
792 except (KeyError, TypeError):
796 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
800 for test_name, test_vals in y_vals.items():
801 for key, test_val in test_vals.items():
803 avg_val = sum(test_val) / len(test_val)
804 y_vals[test_name][key] = [avg_val, len(test_val)]
805 ideal = avg_val / (int(key) * 1000000.0)
806 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
807 y_1c_max[test_name] = ideal
813 pci_limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
814 for test_name, test_vals in y_vals.items():
816 if test_vals[u"1"][1]:
820 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
822 vals[name] = OrderedDict()
823 y_val_1 = test_vals[u"1"][0] / 1000000.0
824 y_val_2 = test_vals[u"2"][0] / 1000000.0 if test_vals[u"2"][0] \
826 y_val_4 = test_vals[u"4"][0] / 1000000.0 if test_vals[u"4"][0] \
829 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
830 vals[name][u"rel"] = [1.0, None, None]
831 vals[name][u"ideal"] = [
833 y_1c_max[test_name] * 2,
834 y_1c_max[test_name] * 4
836 vals[name][u"diff"] = [
837 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
839 vals[name][u"count"] = [
846 val_max = max(vals[name][u"val"])
847 except ValueError as err:
848 logging.error(repr(err))
851 y_max.append(val_max)
854 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
855 vals[name][u"diff"][1] = \
856 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
858 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
859 vals[name][u"diff"][2] = \
860 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
861 except IndexError as err:
862 logging.warning(f"No data for {test_name}")
863 logging.warning(repr(err))
866 if u"x520" in test_name:
867 limit = plot[u"limits"][u"nic"][u"x520"]
868 elif u"x710" in test_name:
869 limit = plot[u"limits"][u"nic"][u"x710"]
870 elif u"xxv710" in test_name:
871 limit = plot[u"limits"][u"nic"][u"xxv710"]
872 elif u"xl710" in test_name:
873 limit = plot[u"limits"][u"nic"][u"xl710"]
874 elif u"x553" in test_name:
875 limit = plot[u"limits"][u"nic"][u"x553"]
878 if limit > nic_limit:
881 mul = 2 if u"ge2p" in test_name else 1
882 if u"10ge" in test_name:
883 limit = plot[u"limits"][u"link"][u"10ge"] * mul
884 elif u"25ge" in test_name:
885 limit = plot[u"limits"][u"link"][u"25ge"] * mul
886 elif u"40ge" in test_name:
887 limit = plot[u"limits"][u"link"][u"40ge"] * mul
888 elif u"100ge" in test_name:
889 limit = plot[u"limits"][u"link"][u"100ge"] * mul
892 if limit > lnk_limit:
901 threshold = 1.1 * max(y_max) # 10%
902 except ValueError as err:
905 nic_limit /= 1000000.0
906 traces.append(plgo.Scatter(
908 y=[nic_limit, ] * len(x_vals),
909 name=f"NIC: {nic_limit:.2f}Mpps",
918 annotations.append(dict(
925 text=f"NIC: {nic_limit:.2f}Mpps",
933 y_max.append(nic_limit)
935 lnk_limit /= 1000000.0
936 if lnk_limit < threshold:
937 traces.append(plgo.Scatter(
939 y=[lnk_limit, ] * len(x_vals),
940 name=f"Link: {lnk_limit:.2f}Mpps",
949 annotations.append(dict(
956 text=f"Link: {lnk_limit:.2f}Mpps",
964 y_max.append(lnk_limit)
966 pci_limit /= 1000000.0
967 if (pci_limit < threshold and
968 (pci_limit < lnk_limit * 0.95 or lnk_limit > lnk_limit * 1.05)):
969 traces.append(plgo.Scatter(
971 y=[pci_limit, ] * len(x_vals),
972 name=f"PCIe: {pci_limit:.2f}Mpps",
981 annotations.append(dict(
988 text=f"PCIe: {pci_limit:.2f}Mpps",
996 y_max.append(pci_limit)
998 # Perfect and measured:
1000 for name, val in vals.items():
1003 for idx in range(len(val[u"val"])):
1005 if isinstance(val[u"val"][idx], float):
1007 f"No. of Runs: {val[u'count'][idx]}<br>"
1008 f"Mean: {val[u'val'][idx]:.2f}Mpps<br>"
1010 if isinstance(val[u"diff"][idx], float):
1011 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
1012 if isinstance(val[u"rel"][idx], float):
1013 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
1014 hovertext.append(htext)
1021 mode=u"lines+markers",
1030 hoverinfo=u"text+name"
1037 name=f"{name} perfect",
1045 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1050 except (IndexError, ValueError, KeyError) as err:
1051 logging.warning(f"No data for {name}\n{repr(err)}")
1055 file_type = plot.get(u"output-file-type", u".html")
1056 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1057 layout = deepcopy(plot[u"layout"])
1058 if layout.get(u"title", None):
1059 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1060 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1061 layout[u"annotations"].extend(annotations)
1062 plpl = plgo.Figure(data=traces, layout=layout)
1069 filename=f"{plot[u'output-file']}{file_type}"
1071 except PlotlyError as err:
1073 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1078 def plot_http_server_perf_box(plot, input_data):
1079 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1080 specified in the specification file.
1082 :param plot: Plot to generate.
1083 :param input_data: Data to process.
1084 :type plot: pandas.Series
1085 :type input_data: InputData
1088 # Transform the data
1090 f" Creating the data set for the {plot.get(u'type', u'')} "
1091 f"{plot.get(u'title', u'')}."
1093 data = input_data.filter_data(plot)
1095 logging.error(u"No data.")
1098 # Prepare the data for the plot
1103 if y_vals.get(test[u"name"], None) is None:
1104 y_vals[test[u"name"]] = list()
1106 y_vals[test[u"name"]].append(test[u"result"])
1107 except (KeyError, TypeError):
1108 y_vals[test[u"name"]].append(None)
1110 # Add None to the lists with missing data
1112 nr_of_samples = list()
1113 for val in y_vals.values():
1114 if len(val) > max_len:
1116 nr_of_samples.append(len(val))
1117 for val in y_vals.values():
1118 if len(val) < max_len:
1119 val.extend([None for _ in range(max_len - len(val))])
1123 df_y = pd.DataFrame(y_vals)
1125 for i, col in enumerate(df_y.columns):
1128 f"({nr_of_samples[i]:02d} " \
1129 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1130 f"{col.lower().replace(u'-ndrpdr', u'')}"
1132 name_lst = name.split(u'-')
1135 for segment in name_lst:
1136 if (len(name) + len(segment) + 1) > 50 and split_name:
1139 name += segment + u'-'
1142 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1148 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1152 f" Writing file {plot[u'output-file']}"
1153 f"{plot[u'output-file-type']}."
1159 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1161 except PlotlyError as err:
1163 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1168 def plot_nf_heatmap(plot, input_data):
1169 """Generate the plot(s) with algorithm: plot_nf_heatmap
1170 specified in the specification file.
1172 :param plot: Plot to generate.
1173 :param input_data: Data to process.
1174 :type plot: pandas.Series
1175 :type input_data: InputData
1178 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1179 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1181 r'(\d+vm\d+t|\d+dcr\d+t).*$')
1184 # Transform the data
1186 f" Creating the data set for the {plot.get(u'type', u'')} "
1187 f"{plot.get(u'title', u'')}."
1189 data = input_data.filter_data(plot, continue_on_error=True)
1190 if data is None or data.empty:
1191 logging.error(u"No data.")
1197 for tag in test[u"tags"]:
1198 groups = re.search(regex_cn, tag)
1200 chain = str(groups.group(1))
1201 node = str(groups.group(2))
1205 groups = re.search(regex_test_name, test[u"name"])
1206 if groups and len(groups.groups()) == 3:
1208 f"{str(groups.group(1))}-"
1209 f"{str(groups.group(2))}-"
1210 f"{str(groups.group(3))}"
1214 if vals.get(chain, None) is None:
1215 vals[chain] = dict()
1216 if vals[chain].get(node, None) is None:
1217 vals[chain][node] = dict(
1225 if plot[u"include-tests"] == u"MRR":
1226 result = test[u"result"][u"receive-rate"]
1227 elif plot[u"include-tests"] == u"PDR":
1228 result = test[u"throughput"][u"PDR"][u"LOWER"]
1229 elif plot[u"include-tests"] == u"NDR":
1230 result = test[u"throughput"][u"NDR"][u"LOWER"]
1237 vals[chain][node][u"vals"].append(result)
1240 logging.error(u"No data.")
1246 txt_chains.append(key_c)
1247 for key_n in vals[key_c].keys():
1248 txt_nodes.append(key_n)
1249 if vals[key_c][key_n][u"vals"]:
1250 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1251 vals[key_c][key_n][u"mean"] = \
1252 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1253 vals[key_c][key_n][u"stdev"] = \
1254 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1255 txt_nodes = list(set(txt_nodes))
1257 def sort_by_int(value):
1258 """Makes possible to sort a list of strings which represent integers.
1260 :param value: Integer as a string.
1262 :returns: Integer representation of input parameter 'value'.
1267 txt_chains = sorted(txt_chains, key=sort_by_int)
1268 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1270 chains = [i + 1 for i in range(len(txt_chains))]
1271 nodes = [i + 1 for i in range(len(txt_nodes))]
1273 data = [list() for _ in range(len(chains))]
1274 for chain in chains:
1277 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1278 except (KeyError, IndexError):
1280 data[chain - 1].append(val)
1283 my_green = [[0.0, u"rgb(235, 249, 242)"],
1284 [1.0, u"rgb(45, 134, 89)"]]
1286 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1287 [1.0, u"rgb(57, 115, 172)"]]
1289 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1290 [1.0, u"rgb(102, 102, 102)"]]
1293 annotations = list()
1295 text = (u"Test: {name}<br>"
1300 for chain, _ in enumerate(txt_chains):
1302 for node, _ in enumerate(txt_nodes):
1303 if data[chain][node] is not None:
1312 text=str(data[chain][node]),
1320 hover_line.append(text.format(
1321 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1322 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1323 val=data[chain][node],
1324 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1325 hovertext.append(hover_line)
1333 title=plot.get(u"z-axis", u""),
1347 colorscale=my_green,
1353 for idx, item in enumerate(txt_nodes):
1371 for idx, item in enumerate(txt_chains):
1398 text=plot.get(u"x-axis", u""),
1415 text=plot.get(u"y-axis", u""),
1424 updatemenus = list([
1435 u"colorscale": [my_green, ],
1436 u"reversescale": False
1445 u"colorscale": [my_blue, ],
1446 u"reversescale": False
1455 u"colorscale": [my_grey, ],
1456 u"reversescale": False
1467 layout = deepcopy(plot[u"layout"])
1468 except KeyError as err:
1469 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1472 layout[u"annotations"] = annotations
1473 layout[u'updatemenus'] = updatemenus
1477 plpl = plgo.Figure(data=traces, layout=layout)
1481 f" Writing file {plot[u'output-file']}"
1482 f"{plot[u'output-file-type']}."
1488 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1490 except PlotlyError as err:
1492 f" Finished with error: {repr(err)}".replace(u"\n", u" ")