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 test in 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"
153 except hdrh.codec.HdrLengthException as err:
155 f"No or invalid data for HDRHistogram for the test "
160 logging.warning(f"Invalid test type: {test[u'type']}")
162 except (ValueError, KeyError) as err:
163 logging.warning(repr(err))
165 layout = deepcopy(plot[u"layout"])
167 layout[u"title"][u"text"] = \
168 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
169 fig[u"layout"].update(layout)
172 file_type = plot.get(u"output-file-type", u".html")
173 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
176 ploff.plot(fig, show_link=False, auto_open=False,
177 filename=f"{plot[u'output-file']}{file_type}")
178 except PlotlyError as err:
179 logging.error(f" Finished with error: {repr(err)}")
182 def plot_lat_hdrh_bar_name(plot, input_data):
183 """Generate the plot(s) with algorithm: plot_lat_hdrh_bar_name
184 specified in the specification file.
186 :param plot: Plot to generate.
187 :param input_data: Data to process.
188 :type plot: pandas.Series
189 :type input_data: InputData
193 plot_title = plot.get(u"title", u"")
195 f" Creating the data set for the {plot.get(u'type', u'')} "
198 data = input_data.filter_tests_by_name(
199 plot, params=[u"latency", u"parent", u"tags", u"type"])
200 if data is None or len(data[0][0]) == 0:
201 logging.error(u"No data.")
204 # Prepare the data for the plot
205 directions = [u"W-E", u"E-W"]
208 for idx_row, test in enumerate(data[0][0]):
210 if test[u"type"] in (u"NDRPDR",):
211 if u"-pdr" in plot_title.lower():
213 elif u"-ndr" in plot_title.lower():
216 logging.warning(f"Invalid test type: {test[u'type']}")
218 name = re.sub(REGEX_NIC, u"", test[u"parent"].
219 replace(u'-ndrpdr', u'').
220 replace(u'2n1l-', u''))
222 for idx_col, direction in enumerate(
223 (u"direction1", u"direction2", )):
225 hdr_lat = test[u"latency"][ttype][direction][u"hdrh"]
226 # TODO: Workaround, HDRH data must be aligned to 4
227 # bytes, remove when not needed.
228 hdr_lat += u"=" * (len(hdr_lat) % 4)
232 decoded = hdrh.histogram.HdrHistogram.decode(hdr_lat)
233 total_count = decoded.get_total_count()
234 for item in decoded.get_recorded_iterator():
235 xaxis.append(item.value_iterated_to)
236 prob = float(item.count_added_in_this_iter_step) / \
241 f"Direction: {directions[idx_col]}<br>"
242 f"Latency: {item.value_iterated_to}uSec<br>"
243 f"Probability: {prob:.2f}%<br>"
245 f"{item.percentile_level_iterated_to:.2f}"
247 marker_color = [COLORS[idx_row], ] * len(yaxis)
248 marker_color[xaxis.index(
249 decoded.get_value_at_percentile(50.0))] = u"red"
250 marker_color[xaxis.index(
251 decoded.get_value_at_percentile(90.0))] = u"red"
252 marker_color[xaxis.index(
253 decoded.get_value_at_percentile(95.0))] = u"red"
260 marker={u"color": marker_color},
265 except hdrh.codec.HdrLengthException as err:
267 f"No or invalid data for HDRHistogram for the test "
271 if len(histograms) == 2:
272 traces.append(histograms)
275 logging.warning(f"Invalid test type: {test[u'type']}")
277 except (ValueError, KeyError) as err:
278 logging.warning(repr(err))
281 logging.warning(f"No data for {plot_title}.")
288 [{u"type": u"bar"}, {u"type": u"bar"}] for _ in range(len(tests))
293 gridcolor=u"rgb(220, 220, 220)",
294 linecolor=u"rgb(220, 220, 220)",
299 tickcolor=u"rgb(220, 220, 220)",
302 for idx_row, test in enumerate(tests):
303 for idx_col in range(2):
305 traces[idx_row][idx_col],
320 layout = deepcopy(plot[u"layout"])
322 layout[u"title"][u"text"] = \
323 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
324 layout[u"height"] = 250 * len(tests) + 130
326 layout[u"annotations"][2][u"y"] = 1.06 - 0.008 * len(tests)
327 layout[u"annotations"][3][u"y"] = 1.06 - 0.008 * len(tests)
329 for idx, test in enumerate(tests):
330 layout[u"annotations"].append({
335 u"text": f"<b>{test}</b>",
338 u"xanchor": u"center",
340 u"y": 1.0 - float(idx) * 1.06 / len(tests),
341 u"yanchor": u"bottom",
345 fig[u"layout"].update(layout)
348 file_type = plot.get(u"output-file-type", u".html")
349 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
352 ploff.plot(fig, show_link=False, auto_open=False,
353 filename=f"{plot[u'output-file']}{file_type}")
354 except PlotlyError as err:
355 logging.error(f" Finished with error: {repr(err)}")
358 def plot_nf_reconf_box_name(plot, input_data):
359 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
360 specified in the specification file.
362 :param plot: Plot to generate.
363 :param input_data: Data to process.
364 :type plot: pandas.Series
365 :type input_data: InputData
370 f" Creating the data set for the {plot.get(u'type', u'')} "
371 f"{plot.get(u'title', u'')}."
373 data = input_data.filter_tests_by_name(
374 plot, params=[u"result", u"parent", u"tags", u"type"]
377 logging.error(u"No data.")
380 # Prepare the data for the plot
381 y_vals = OrderedDict()
386 if y_vals.get(test[u"parent"], None) is None:
387 y_vals[test[u"parent"]] = list()
388 loss[test[u"parent"]] = list()
390 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
391 loss[test[u"parent"]].append(test[u"result"][u"loss"])
392 except (KeyError, TypeError):
393 y_vals[test[u"parent"]].append(None)
395 # Add None to the lists with missing data
397 nr_of_samples = list()
398 for val in y_vals.values():
399 if len(val) > max_len:
401 nr_of_samples.append(len(val))
402 for val in y_vals.values():
403 if len(val) < max_len:
404 val.extend([None for _ in range(max_len - len(val))])
408 df_y = pd.DataFrame(y_vals)
410 for i, col in enumerate(df_y.columns):
411 tst_name = re.sub(REGEX_NIC, u"",
412 col.lower().replace(u'-ndrpdr', u'').
413 replace(u'2n1l-', u''))
415 traces.append(plgo.Box(
416 x=[str(i + 1) + u'.'] * len(df_y[col]),
417 y=[y if y else None for y in df_y[col]],
420 f"({nr_of_samples[i]:02d} "
421 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
422 f"packets lost average: {mean(loss[col]):.1f}) "
423 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
429 layout = deepcopy(plot[u"layout"])
430 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
431 layout[u"yaxis"][u"title"] = u"<b>Implied Time Lost [s]</b>"
432 layout[u"legend"][u"font"][u"size"] = 14
433 layout[u"yaxis"].pop(u"range")
434 plpl = plgo.Figure(data=traces, layout=layout)
437 file_type = plot.get(u"output-file-type", u".html")
438 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
443 filename=f"{plot[u'output-file']}{file_type}"
445 except PlotlyError as err:
447 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
452 def plot_perf_box_name(plot, input_data):
453 """Generate the plot(s) with algorithm: plot_perf_box_name
454 specified in the specification file.
456 :param plot: Plot to generate.
457 :param input_data: Data to process.
458 :type plot: pandas.Series
459 :type input_data: InputData
464 f" Creating data set for the {plot.get(u'type', u'')} "
465 f"{plot.get(u'title', u'')}."
467 data = input_data.filter_tests_by_name(
468 plot, params=[u"throughput", u"parent", u"tags", u"type"])
470 logging.error(u"No data.")
473 # Prepare the data for the plot
474 y_vals = OrderedDict()
478 if y_vals.get(test[u"parent"], None) is None:
479 y_vals[test[u"parent"]] = list()
481 if (test[u"type"] in (u"NDRPDR", ) and
482 u"-pdr" in plot.get(u"title", u"").lower()):
483 y_vals[test[u"parent"]].\
484 append(test[u"throughput"][u"PDR"][u"LOWER"])
485 elif (test[u"type"] in (u"NDRPDR", ) and
486 u"-ndr" in plot.get(u"title", u"").lower()):
487 y_vals[test[u"parent"]]. \
488 append(test[u"throughput"][u"NDR"][u"LOWER"])
489 elif test[u"type"] in (u"SOAK", ):
490 y_vals[test[u"parent"]].\
491 append(test[u"throughput"][u"LOWER"])
494 except (KeyError, TypeError):
495 y_vals[test[u"parent"]].append(None)
497 # Add None to the lists with missing data
499 nr_of_samples = list()
500 for val in y_vals.values():
501 if len(val) > max_len:
503 nr_of_samples.append(len(val))
504 for val in y_vals.values():
505 if len(val) < max_len:
506 val.extend([None for _ in range(max_len - len(val))])
510 df_y = pd.DataFrame(y_vals)
513 for i, col in enumerate(df_y.columns):
514 tst_name = re.sub(REGEX_NIC, u"",
515 col.lower().replace(u'-ndrpdr', u'').
516 replace(u'2n1l-', u''))
519 x=[str(i + 1) + u'.'] * len(df_y[col]),
520 y=[y / 1000000 if y else None for y in df_y[col]],
523 f"({nr_of_samples[i]:02d} "
524 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
531 val_max = max(df_y[col])
533 y_max.append(int(val_max / 1000000) + 2)
534 except (ValueError, TypeError) as err:
535 logging.error(repr(err))
540 layout = deepcopy(plot[u"layout"])
541 if layout.get(u"title", None):
542 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
544 layout[u"yaxis"][u"range"] = [0, max(y_max)]
545 plpl = plgo.Figure(data=traces, layout=layout)
548 logging.info(f" Writing file {plot[u'output-file']}.html.")
553 filename=f"{plot[u'output-file']}.html"
555 except PlotlyError as err:
557 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
562 def plot_lat_err_bars_name(plot, input_data):
563 """Generate the plot(s) with algorithm: plot_lat_err_bars_name
564 specified in the specification file.
566 :param plot: Plot to generate.
567 :param input_data: Data to process.
568 :type plot: pandas.Series
569 :type input_data: InputData
573 plot_title = plot.get(u"title", u"")
575 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
577 data = input_data.filter_tests_by_name(
578 plot, params=[u"latency", u"parent", u"tags", u"type"])
580 logging.error(u"No data.")
583 # Prepare the data for the plot
584 y_tmp_vals = OrderedDict()
589 logging.debug(f"test[u'latency']: {test[u'latency']}\n")
590 except ValueError as err:
591 logging.warning(repr(err))
592 if y_tmp_vals.get(test[u"parent"], None) is None:
593 y_tmp_vals[test[u"parent"]] = [
594 list(), # direction1, min
595 list(), # direction1, avg
596 list(), # direction1, max
597 list(), # direction2, min
598 list(), # direction2, avg
599 list() # direction2, max
602 if test[u"type"] not in (u"NDRPDR", ):
603 logging.warning(f"Invalid test type: {test[u'type']}")
605 if u"-pdr" in plot_title.lower():
607 elif u"-ndr" in plot_title.lower():
611 f"Invalid test type: {test[u'type']}"
614 y_tmp_vals[test[u"parent"]][0].append(
615 test[u"latency"][ttype][u"direction1"][u"min"])
616 y_tmp_vals[test[u"parent"]][1].append(
617 test[u"latency"][ttype][u"direction1"][u"avg"])
618 y_tmp_vals[test[u"parent"]][2].append(
619 test[u"latency"][ttype][u"direction1"][u"max"])
620 y_tmp_vals[test[u"parent"]][3].append(
621 test[u"latency"][ttype][u"direction2"][u"min"])
622 y_tmp_vals[test[u"parent"]][4].append(
623 test[u"latency"][ttype][u"direction2"][u"avg"])
624 y_tmp_vals[test[u"parent"]][5].append(
625 test[u"latency"][ttype][u"direction2"][u"max"])
626 except (KeyError, TypeError) as err:
627 logging.warning(repr(err))
633 nr_of_samples = list()
634 for key, val in y_tmp_vals.items():
635 name = re.sub(REGEX_NIC, u"", key.replace(u'-ndrpdr', u'').
636 replace(u'2n1l-', u''))
637 x_vals.append(name) # dir 1
638 y_vals.append(mean(val[1]) if val[1] else None)
639 y_mins.append(mean(val[0]) if val[0] else None)
640 y_maxs.append(mean(val[2]) if val[2] else None)
641 nr_of_samples.append(len(val[1]) if val[1] else 0)
642 x_vals.append(name) # dir 2
643 y_vals.append(mean(val[4]) if val[4] else None)
644 y_mins.append(mean(val[3]) if val[3] else None)
645 y_maxs.append(mean(val[5]) if val[5] else None)
646 nr_of_samples.append(len(val[3]) if val[3] else 0)
651 for idx, _ in enumerate(x_vals):
652 if not bool(int(idx % 2)):
653 direction = u"West-East"
655 direction = u"East-West"
657 f"No. of Runs: {nr_of_samples[idx]}<br>"
658 f"Test: {x_vals[idx]}<br>"
659 f"Direction: {direction}<br>"
661 if isinstance(y_maxs[idx], float):
662 hovertext += f"Max: {y_maxs[idx]:.2f}uSec<br>"
663 if isinstance(y_vals[idx], float):
664 hovertext += f"Mean: {y_vals[idx]:.2f}uSec<br>"
665 if isinstance(y_mins[idx], float):
666 hovertext += f"Min: {y_mins[idx]:.2f}uSec"
668 if isinstance(y_maxs[idx], float) and isinstance(y_vals[idx], float):
669 array = [y_maxs[idx] - y_vals[idx], ]
672 if isinstance(y_mins[idx], float) and isinstance(y_vals[idx], float):
673 arrayminus = [y_vals[idx] - y_mins[idx], ]
675 arrayminus = [None, ]
676 traces.append(plgo.Scatter(
680 legendgroup=x_vals[idx],
681 showlegend=bool(int(idx % 2)),
687 arrayminus=arrayminus,
688 color=COLORS[int(idx / 2)]
692 color=COLORS[int(idx / 2)],
697 annotations.append(dict(
704 text=u"E-W" if bool(int(idx % 2)) else u"W-E",
714 file_type = plot.get(u"output-file-type", u".html")
715 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
716 layout = deepcopy(plot[u"layout"])
717 if layout.get(u"title", None):
718 layout[u"title"] = f"<b>Latency:</b> {layout[u'title']}"
719 layout[u"annotations"] = annotations
720 plpl = plgo.Figure(data=traces, layout=layout)
725 show_link=False, auto_open=False,
726 filename=f"{plot[u'output-file']}{file_type}"
728 except PlotlyError as err:
730 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
735 def plot_tsa_name(plot, input_data):
736 """Generate the plot(s) with algorithm:
738 specified in the specification file.
740 :param plot: Plot to generate.
741 :param input_data: Data to process.
742 :type plot: pandas.Series
743 :type input_data: InputData
747 plot_title = plot.get(u"title", u"")
749 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
751 data = input_data.filter_tests_by_name(
752 plot, params=[u"throughput", u"parent", u"tags", u"type"])
754 logging.error(u"No data.")
757 y_vals = OrderedDict()
761 if y_vals.get(test[u"parent"], None) is None:
762 y_vals[test[u"parent"]] = {
768 if test[u"type"] not in (u"NDRPDR",):
771 if u"-pdr" in plot_title.lower():
773 elif u"-ndr" in plot_title.lower():
778 if u"1C" in test[u"tags"]:
779 y_vals[test[u"parent"]][u"1"]. \
780 append(test[u"throughput"][ttype][u"LOWER"])
781 elif u"2C" in test[u"tags"]:
782 y_vals[test[u"parent"]][u"2"]. \
783 append(test[u"throughput"][ttype][u"LOWER"])
784 elif u"4C" in test[u"tags"]:
785 y_vals[test[u"parent"]][u"4"]. \
786 append(test[u"throughput"][ttype][u"LOWER"])
787 except (KeyError, TypeError):
791 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
795 for test_name, test_vals in y_vals.items():
796 for key, test_val in test_vals.items():
798 avg_val = sum(test_val) / len(test_val)
799 y_vals[test_name][key] = [avg_val, len(test_val)]
800 ideal = avg_val / (int(key) * 1000000.0)
801 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
802 y_1c_max[test_name] = ideal
808 pci_limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
809 for test_name, test_vals in y_vals.items():
811 if test_vals[u"1"][1]:
815 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
817 vals[name] = OrderedDict()
818 y_val_1 = test_vals[u"1"][0] / 1000000.0
819 y_val_2 = test_vals[u"2"][0] / 1000000.0 if test_vals[u"2"][0] \
821 y_val_4 = test_vals[u"4"][0] / 1000000.0 if test_vals[u"4"][0] \
824 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
825 vals[name][u"rel"] = [1.0, None, None]
826 vals[name][u"ideal"] = [
828 y_1c_max[test_name] * 2,
829 y_1c_max[test_name] * 4
831 vals[name][u"diff"] = [
832 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
834 vals[name][u"count"] = [
841 val_max = max(vals[name][u"val"])
842 except ValueError as err:
843 logging.error(repr(err))
846 y_max.append(val_max)
849 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
850 vals[name][u"diff"][1] = \
851 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
853 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
854 vals[name][u"diff"][2] = \
855 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
856 except IndexError as err:
857 logging.warning(f"No data for {test_name}")
858 logging.warning(repr(err))
861 if u"x520" in test_name:
862 limit = plot[u"limits"][u"nic"][u"x520"]
863 elif u"x710" in test_name:
864 limit = plot[u"limits"][u"nic"][u"x710"]
865 elif u"xxv710" in test_name:
866 limit = plot[u"limits"][u"nic"][u"xxv710"]
867 elif u"xl710" in test_name:
868 limit = plot[u"limits"][u"nic"][u"xl710"]
869 elif u"x553" in test_name:
870 limit = plot[u"limits"][u"nic"][u"x553"]
873 if limit > nic_limit:
876 mul = 2 if u"ge2p" in test_name else 1
877 if u"10ge" in test_name:
878 limit = plot[u"limits"][u"link"][u"10ge"] * mul
879 elif u"25ge" in test_name:
880 limit = plot[u"limits"][u"link"][u"25ge"] * mul
881 elif u"40ge" in test_name:
882 limit = plot[u"limits"][u"link"][u"40ge"] * mul
883 elif u"100ge" in test_name:
884 limit = plot[u"limits"][u"link"][u"100ge"] * mul
887 if limit > lnk_limit:
896 threshold = 1.1 * max(y_max) # 10%
897 except ValueError as err:
900 nic_limit /= 1000000.0
901 traces.append(plgo.Scatter(
903 y=[nic_limit, ] * len(x_vals),
904 name=f"NIC: {nic_limit:.2f}Mpps",
913 annotations.append(dict(
920 text=f"NIC: {nic_limit:.2f}Mpps",
928 y_max.append(nic_limit)
930 lnk_limit /= 1000000.0
931 if lnk_limit < threshold:
932 traces.append(plgo.Scatter(
934 y=[lnk_limit, ] * len(x_vals),
935 name=f"Link: {lnk_limit:.2f}Mpps",
944 annotations.append(dict(
951 text=f"Link: {lnk_limit:.2f}Mpps",
959 y_max.append(lnk_limit)
961 pci_limit /= 1000000.0
962 if (pci_limit < threshold and
963 (pci_limit < lnk_limit * 0.95 or lnk_limit > lnk_limit * 1.05)):
964 traces.append(plgo.Scatter(
966 y=[pci_limit, ] * len(x_vals),
967 name=f"PCIe: {pci_limit:.2f}Mpps",
976 annotations.append(dict(
983 text=f"PCIe: {pci_limit:.2f}Mpps",
991 y_max.append(pci_limit)
993 # Perfect and measured:
995 for name, val in vals.items():
998 for idx in range(len(val[u"val"])):
1000 if isinstance(val[u"val"][idx], float):
1002 f"No. of Runs: {val[u'count'][idx]}<br>"
1003 f"Mean: {val[u'val'][idx]:.2f}Mpps<br>"
1005 if isinstance(val[u"diff"][idx], float):
1006 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
1007 if isinstance(val[u"rel"][idx], float):
1008 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
1009 hovertext.append(htext)
1016 mode=u"lines+markers",
1025 hoverinfo=u"text+name"
1032 name=f"{name} perfect",
1040 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1045 except (IndexError, ValueError, KeyError) as err:
1046 logging.warning(f"No data for {name}\n{repr(err)}")
1050 file_type = plot.get(u"output-file-type", u".html")
1051 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1052 layout = deepcopy(plot[u"layout"])
1053 if layout.get(u"title", None):
1054 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1055 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1056 layout[u"annotations"].extend(annotations)
1057 plpl = plgo.Figure(data=traces, layout=layout)
1064 filename=f"{plot[u'output-file']}{file_type}"
1066 except PlotlyError as err:
1068 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1073 def plot_http_server_perf_box(plot, input_data):
1074 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1075 specified in the specification file.
1077 :param plot: Plot to generate.
1078 :param input_data: Data to process.
1079 :type plot: pandas.Series
1080 :type input_data: InputData
1083 # Transform the data
1085 f" Creating the data set for the {plot.get(u'type', u'')} "
1086 f"{plot.get(u'title', u'')}."
1088 data = input_data.filter_data(plot)
1090 logging.error(u"No data.")
1093 # Prepare the data for the plot
1098 if y_vals.get(test[u"name"], None) is None:
1099 y_vals[test[u"name"]] = list()
1101 y_vals[test[u"name"]].append(test[u"result"])
1102 except (KeyError, TypeError):
1103 y_vals[test[u"name"]].append(None)
1105 # Add None to the lists with missing data
1107 nr_of_samples = list()
1108 for val in y_vals.values():
1109 if len(val) > max_len:
1111 nr_of_samples.append(len(val))
1112 for val in y_vals.values():
1113 if len(val) < max_len:
1114 val.extend([None for _ in range(max_len - len(val))])
1118 df_y = pd.DataFrame(y_vals)
1120 for i, col in enumerate(df_y.columns):
1123 f"({nr_of_samples[i]:02d} " \
1124 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1125 f"{col.lower().replace(u'-ndrpdr', u'')}"
1127 name_lst = name.split(u'-')
1130 for segment in name_lst:
1131 if (len(name) + len(segment) + 1) > 50 and split_name:
1134 name += segment + u'-'
1137 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1143 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1147 f" Writing file {plot[u'output-file']}"
1148 f"{plot[u'output-file-type']}."
1154 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1156 except PlotlyError as err:
1158 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1163 def plot_nf_heatmap(plot, input_data):
1164 """Generate the plot(s) with algorithm: plot_nf_heatmap
1165 specified in the specification file.
1167 :param plot: Plot to generate.
1168 :param input_data: Data to process.
1169 :type plot: pandas.Series
1170 :type input_data: InputData
1173 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1174 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1176 r'(\d+vm\d+t|\d+dcr\d+t).*$')
1179 # Transform the data
1181 f" Creating the data set for the {plot.get(u'type', u'')} "
1182 f"{plot.get(u'title', u'')}."
1184 data = input_data.filter_data(plot, continue_on_error=True)
1185 if data is None or data.empty:
1186 logging.error(u"No data.")
1192 for tag in test[u"tags"]:
1193 groups = re.search(regex_cn, tag)
1195 chain = str(groups.group(1))
1196 node = str(groups.group(2))
1200 groups = re.search(regex_test_name, test[u"name"])
1201 if groups and len(groups.groups()) == 3:
1203 f"{str(groups.group(1))}-"
1204 f"{str(groups.group(2))}-"
1205 f"{str(groups.group(3))}"
1209 if vals.get(chain, None) is None:
1210 vals[chain] = dict()
1211 if vals[chain].get(node, None) is None:
1212 vals[chain][node] = dict(
1220 if plot[u"include-tests"] == u"MRR":
1221 result = test[u"result"][u"receive-rate"]
1222 elif plot[u"include-tests"] == u"PDR":
1223 result = test[u"throughput"][u"PDR"][u"LOWER"]
1224 elif plot[u"include-tests"] == u"NDR":
1225 result = test[u"throughput"][u"NDR"][u"LOWER"]
1232 vals[chain][node][u"vals"].append(result)
1235 logging.error(u"No data.")
1241 txt_chains.append(key_c)
1242 for key_n in vals[key_c].keys():
1243 txt_nodes.append(key_n)
1244 if vals[key_c][key_n][u"vals"]:
1245 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1246 vals[key_c][key_n][u"mean"] = \
1247 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1248 vals[key_c][key_n][u"stdev"] = \
1249 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1250 txt_nodes = list(set(txt_nodes))
1252 def sort_by_int(value):
1253 """Makes possible to sort a list of strings which represent integers.
1255 :param value: Integer as a string.
1257 :returns: Integer representation of input parameter 'value'.
1262 txt_chains = sorted(txt_chains, key=sort_by_int)
1263 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1265 chains = [i + 1 for i in range(len(txt_chains))]
1266 nodes = [i + 1 for i in range(len(txt_nodes))]
1268 data = [list() for _ in range(len(chains))]
1269 for chain in chains:
1272 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1273 except (KeyError, IndexError):
1275 data[chain - 1].append(val)
1278 my_green = [[0.0, u"rgb(235, 249, 242)"],
1279 [1.0, u"rgb(45, 134, 89)"]]
1281 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1282 [1.0, u"rgb(57, 115, 172)"]]
1284 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1285 [1.0, u"rgb(102, 102, 102)"]]
1288 annotations = list()
1290 text = (u"Test: {name}<br>"
1295 for chain, _ in enumerate(txt_chains):
1297 for node, _ in enumerate(txt_nodes):
1298 if data[chain][node] is not None:
1307 text=str(data[chain][node]),
1315 hover_line.append(text.format(
1316 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1317 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1318 val=data[chain][node],
1319 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1320 hovertext.append(hover_line)
1328 title=plot.get(u"z-axis", u""),
1342 colorscale=my_green,
1348 for idx, item in enumerate(txt_nodes):
1366 for idx, item in enumerate(txt_chains):
1393 text=plot.get(u"x-axis", u""),
1410 text=plot.get(u"y-axis", u""),
1419 updatemenus = list([
1430 u"colorscale": [my_green, ],
1431 u"reversescale": False
1440 u"colorscale": [my_blue, ],
1441 u"reversescale": False
1450 u"colorscale": [my_grey, ],
1451 u"reversescale": False
1462 layout = deepcopy(plot[u"layout"])
1463 except KeyError as err:
1464 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1467 layout[u"annotations"] = annotations
1468 layout[u'updatemenus'] = updatemenus
1472 plpl = plgo.Figure(data=traces, layout=layout)
1476 f" Writing file {plot[u'output-file']}"
1477 f"{plot[u'output-file-type']}."
1483 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1485 except PlotlyError as err:
1487 f" Finished with error: {repr(err)}".replace(u"\n", u" ")