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'').
226 replace(u'avf-', u''))
228 for idx_col, direction in enumerate(
229 (u"direction1", u"direction2", )):
231 hdr_lat = test[u"latency"][ttype][direction][u"hdrh"]
232 # TODO: Workaround, HDRH data must be aligned to 4
233 # bytes, remove when not needed.
234 hdr_lat += u"=" * (len(hdr_lat) % 4)
238 decoded = hdrh.histogram.HdrHistogram.decode(hdr_lat)
239 total_count = decoded.get_total_count()
240 for item in decoded.get_recorded_iterator():
241 xaxis.append(item.value_iterated_to)
242 prob = float(item.count_added_in_this_iter_step) / \
247 f"Direction: {directions[idx_col]}<br>"
248 f"Latency: {item.value_iterated_to}uSec<br>"
249 f"Probability: {prob:.2f}%<br>"
251 f"{item.percentile_level_iterated_to:.2f}"
253 marker_color = [COLORS[idx_row], ] * len(yaxis)
254 marker_color[xaxis.index(
255 decoded.get_value_at_percentile(50.0))] = u"red"
256 marker_color[xaxis.index(
257 decoded.get_value_at_percentile(90.0))] = u"red"
258 marker_color[xaxis.index(
259 decoded.get_value_at_percentile(95.0))] = u"red"
266 marker={u"color": marker_color},
271 except hdrh.codec.HdrLengthException as err:
273 f"No or invalid data for HDRHistogram for the test "
277 if len(histograms) == 2:
278 traces.append(histograms)
281 logging.warning(f"Invalid test type: {test[u'type']}")
283 except (ValueError, KeyError) as err:
284 logging.warning(repr(err))
287 logging.warning(f"No data for {plot_title}.")
294 [{u"type": u"bar"}, {u"type": u"bar"}] for _ in range(len(tests))
299 gridcolor=u"rgb(220, 220, 220)",
300 linecolor=u"rgb(220, 220, 220)",
305 tickcolor=u"rgb(220, 220, 220)",
308 for idx_row, test in enumerate(tests):
309 for idx_col in range(2):
311 traces[idx_row][idx_col],
326 layout = deepcopy(plot[u"layout"])
328 layout[u"title"][u"text"] = \
329 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
330 layout[u"height"] = 250 * len(tests) + 130
332 layout[u"annotations"][2][u"y"] = 1.06 - 0.008 * len(tests)
333 layout[u"annotations"][3][u"y"] = 1.06 - 0.008 * len(tests)
335 for idx, test in enumerate(tests):
336 layout[u"annotations"].append({
341 u"text": f"<b>{test}</b>",
344 u"xanchor": u"center",
346 u"y": 1.0 - float(idx) * 1.06 / len(tests),
347 u"yanchor": u"bottom",
351 fig[u"layout"].update(layout)
354 file_type = plot.get(u"output-file-type", u".html")
355 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
358 ploff.plot(fig, show_link=False, auto_open=False,
359 filename=f"{plot[u'output-file']}{file_type}")
360 except PlotlyError as err:
361 logging.error(f" Finished with error: {repr(err)}")
364 def plot_nf_reconf_box_name(plot, input_data):
365 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
366 specified in the specification file.
368 :param plot: Plot to generate.
369 :param input_data: Data to process.
370 :type plot: pandas.Series
371 :type input_data: InputData
376 f" Creating the data set for the {plot.get(u'type', u'')} "
377 f"{plot.get(u'title', u'')}."
379 data = input_data.filter_tests_by_name(
380 plot, params=[u"result", u"parent", u"tags", u"type"]
383 logging.error(u"No data.")
386 # Prepare the data for the plot
387 y_vals = OrderedDict()
392 if y_vals.get(test[u"parent"], None) is None:
393 y_vals[test[u"parent"]] = list()
394 loss[test[u"parent"]] = list()
396 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
397 loss[test[u"parent"]].append(test[u"result"][u"loss"])
398 except (KeyError, TypeError):
399 y_vals[test[u"parent"]].append(None)
401 # Add None to the lists with missing data
403 nr_of_samples = list()
404 for val in y_vals.values():
405 if len(val) > max_len:
407 nr_of_samples.append(len(val))
408 for val in y_vals.values():
409 if len(val) < max_len:
410 val.extend([None for _ in range(max_len - len(val))])
414 df_y = pd.DataFrame(y_vals)
416 for i, col in enumerate(df_y.columns):
417 tst_name = re.sub(REGEX_NIC, u"",
418 col.lower().replace(u'-ndrpdr', u'').
419 replace(u'2n1l-', u'').replace(u'avf-', u''))
421 traces.append(plgo.Box(
422 x=[str(i + 1) + u'.'] * len(df_y[col]),
423 y=[y if y else None for y in df_y[col]],
426 f"({nr_of_samples[i]:02d} "
427 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
428 f"packets lost average: {mean(loss[col]):.1f}) "
429 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
435 layout = deepcopy(plot[u"layout"])
436 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
437 layout[u"yaxis"][u"title"] = u"<b>Implied Time Lost [s]</b>"
438 layout[u"legend"][u"font"][u"size"] = 14
439 layout[u"yaxis"].pop(u"range")
440 plpl = plgo.Figure(data=traces, layout=layout)
443 file_type = plot.get(u"output-file-type", u".html")
444 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
449 filename=f"{plot[u'output-file']}{file_type}"
451 except PlotlyError as err:
453 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
458 def plot_perf_box_name(plot, input_data):
459 """Generate the plot(s) with algorithm: plot_perf_box_name
460 specified in the specification file.
462 :param plot: Plot to generate.
463 :param input_data: Data to process.
464 :type plot: pandas.Series
465 :type input_data: InputData
470 f" Creating data set for the {plot.get(u'type', u'')} "
471 f"{plot.get(u'title', u'')}."
473 data = input_data.filter_tests_by_name(
474 plot, params=[u"throughput", u"parent", u"tags", u"type"])
476 logging.error(u"No data.")
479 # Prepare the data for the plot
480 y_vals = OrderedDict()
484 if y_vals.get(test[u"parent"], None) is None:
485 y_vals[test[u"parent"]] = list()
487 if (test[u"type"] in (u"NDRPDR", ) and
488 u"-pdr" in plot.get(u"title", u"").lower()):
489 y_vals[test[u"parent"]].\
490 append(test[u"throughput"][u"PDR"][u"LOWER"])
491 elif (test[u"type"] in (u"NDRPDR", ) and
492 u"-ndr" in plot.get(u"title", u"").lower()):
493 y_vals[test[u"parent"]]. \
494 append(test[u"throughput"][u"NDR"][u"LOWER"])
495 elif test[u"type"] in (u"SOAK", ):
496 y_vals[test[u"parent"]].\
497 append(test[u"throughput"][u"LOWER"])
500 except (KeyError, TypeError):
501 y_vals[test[u"parent"]].append(None)
503 # Add None to the lists with missing data
505 nr_of_samples = list()
506 for val in y_vals.values():
507 if len(val) > max_len:
509 nr_of_samples.append(len(val))
510 for val in y_vals.values():
511 if len(val) < max_len:
512 val.extend([None for _ in range(max_len - len(val))])
516 df_y = pd.DataFrame(y_vals)
519 for i, col in enumerate(df_y.columns):
520 tst_name = re.sub(REGEX_NIC, u"",
521 col.lower().replace(u'-ndrpdr', u'').
522 replace(u'2n1l-', u'').replace(u'avf-', u''))
525 x=[str(i + 1) + u'.'] * len(df_y[col]),
526 y=[y / 1000000 if y else None for y in df_y[col]],
529 f"({nr_of_samples[i]:02d} "
530 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
537 val_max = max(df_y[col])
539 y_max.append(int(val_max / 1000000) + 2)
540 except (ValueError, TypeError) as err:
541 logging.error(repr(err))
546 layout = deepcopy(plot[u"layout"])
547 if layout.get(u"title", None):
548 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
550 layout[u"yaxis"][u"range"] = [0, max(y_max)]
551 plpl = plgo.Figure(data=traces, layout=layout)
554 logging.info(f" Writing file {plot[u'output-file']}.html.")
559 filename=f"{plot[u'output-file']}.html"
561 except PlotlyError as err:
563 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
568 def plot_lat_err_bars_name(plot, input_data):
569 """Generate the plot(s) with algorithm: plot_lat_err_bars_name
570 specified in the specification file.
572 :param plot: Plot to generate.
573 :param input_data: Data to process.
574 :type plot: pandas.Series
575 :type input_data: InputData
579 plot_title = plot.get(u"title", u"")
581 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
583 data = input_data.filter_tests_by_name(
584 plot, params=[u"latency", u"parent", u"tags", u"type"])
586 logging.error(u"No data.")
589 # Prepare the data for the plot
590 y_tmp_vals = OrderedDict()
595 logging.debug(f"test[u'latency']: {test[u'latency']}\n")
596 except ValueError as err:
597 logging.warning(repr(err))
598 if y_tmp_vals.get(test[u"parent"], None) is None:
599 y_tmp_vals[test[u"parent"]] = [
600 list(), # direction1, min
601 list(), # direction1, avg
602 list(), # direction1, max
603 list(), # direction2, min
604 list(), # direction2, avg
605 list() # direction2, max
608 if test[u"type"] not in (u"NDRPDR", ):
609 logging.warning(f"Invalid test type: {test[u'type']}")
611 if u"-pdr" in plot_title.lower():
613 elif u"-ndr" in plot_title.lower():
617 f"Invalid test type: {test[u'type']}"
620 y_tmp_vals[test[u"parent"]][0].append(
621 test[u"latency"][ttype][u"direction1"][u"min"])
622 y_tmp_vals[test[u"parent"]][1].append(
623 test[u"latency"][ttype][u"direction1"][u"avg"])
624 y_tmp_vals[test[u"parent"]][2].append(
625 test[u"latency"][ttype][u"direction1"][u"max"])
626 y_tmp_vals[test[u"parent"]][3].append(
627 test[u"latency"][ttype][u"direction2"][u"min"])
628 y_tmp_vals[test[u"parent"]][4].append(
629 test[u"latency"][ttype][u"direction2"][u"avg"])
630 y_tmp_vals[test[u"parent"]][5].append(
631 test[u"latency"][ttype][u"direction2"][u"max"])
632 except (KeyError, TypeError) as err:
633 logging.warning(repr(err))
639 nr_of_samples = list()
640 for key, val in y_tmp_vals.items():
641 name = re.sub(REGEX_NIC, u"", key.replace(u'-ndrpdr', u'').
642 replace(u'2n1l-', u'').replace(u'avf-', u''))
643 x_vals.append(name) # dir 1
644 y_vals.append(mean(val[1]) if val[1] else None)
645 y_mins.append(mean(val[0]) if val[0] else None)
646 y_maxs.append(mean(val[2]) if val[2] else None)
647 nr_of_samples.append(len(val[1]) if val[1] else 0)
648 x_vals.append(name) # dir 2
649 y_vals.append(mean(val[4]) if val[4] else None)
650 y_mins.append(mean(val[3]) if val[3] else None)
651 y_maxs.append(mean(val[5]) if val[5] else None)
652 nr_of_samples.append(len(val[3]) if val[3] else 0)
657 for idx, _ in enumerate(x_vals):
658 if not bool(int(idx % 2)):
659 direction = u"West-East"
661 direction = u"East-West"
663 f"No. of Runs: {nr_of_samples[idx]}<br>"
664 f"Test: {x_vals[idx]}<br>"
665 f"Direction: {direction}<br>"
667 if isinstance(y_maxs[idx], float):
668 hovertext += f"Max: {y_maxs[idx]:.2f}uSec<br>"
669 if isinstance(y_vals[idx], float):
670 hovertext += f"Mean: {y_vals[idx]:.2f}uSec<br>"
671 if isinstance(y_mins[idx], float):
672 hovertext += f"Min: {y_mins[idx]:.2f}uSec"
674 if isinstance(y_maxs[idx], float) and isinstance(y_vals[idx], float):
675 array = [y_maxs[idx] - y_vals[idx], ]
678 if isinstance(y_mins[idx], float) and isinstance(y_vals[idx], float):
679 arrayminus = [y_vals[idx] - y_mins[idx], ]
681 arrayminus = [None, ]
682 traces.append(plgo.Scatter(
686 legendgroup=x_vals[idx],
687 showlegend=bool(int(idx % 2)),
693 arrayminus=arrayminus,
694 color=COLORS[int(idx / 2)]
698 color=COLORS[int(idx / 2)],
703 annotations.append(dict(
710 text=u"E-W" if bool(int(idx % 2)) else u"W-E",
720 file_type = plot.get(u"output-file-type", u".html")
721 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
722 layout = deepcopy(plot[u"layout"])
723 if layout.get(u"title", None):
724 layout[u"title"] = f"<b>Latency:</b> {layout[u'title']}"
725 layout[u"annotations"] = annotations
726 plpl = plgo.Figure(data=traces, layout=layout)
731 show_link=False, auto_open=False,
732 filename=f"{plot[u'output-file']}{file_type}"
734 except PlotlyError as err:
736 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
741 def plot_tsa_name(plot, input_data):
742 """Generate the plot(s) with algorithm:
744 specified in the specification file.
746 :param plot: Plot to generate.
747 :param input_data: Data to process.
748 :type plot: pandas.Series
749 :type input_data: InputData
753 plot_title = plot.get(u"title", u"")
755 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
757 data = input_data.filter_tests_by_name(
758 plot, params=[u"throughput", u"parent", u"tags", u"type"])
760 logging.error(u"No data.")
763 y_vals = OrderedDict()
767 if y_vals.get(test[u"parent"], None) is None:
768 y_vals[test[u"parent"]] = {
774 if test[u"type"] not in (u"NDRPDR",):
777 if u"-pdr" in plot_title.lower():
779 elif u"-ndr" in plot_title.lower():
784 if u"1C" in test[u"tags"]:
785 y_vals[test[u"parent"]][u"1"]. \
786 append(test[u"throughput"][ttype][u"LOWER"])
787 elif u"2C" in test[u"tags"]:
788 y_vals[test[u"parent"]][u"2"]. \
789 append(test[u"throughput"][ttype][u"LOWER"])
790 elif u"4C" in test[u"tags"]:
791 y_vals[test[u"parent"]][u"4"]. \
792 append(test[u"throughput"][ttype][u"LOWER"])
793 except (KeyError, TypeError):
797 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
801 for test_name, test_vals in y_vals.items():
802 for key, test_val in test_vals.items():
804 avg_val = sum(test_val) / len(test_val)
805 y_vals[test_name][key] = [avg_val, len(test_val)]
806 ideal = avg_val / (int(key) * 1000000.0)
807 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
808 y_1c_max[test_name] = ideal
814 pci_limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
815 for test_name, test_vals in y_vals.items():
817 if test_vals[u"1"][1]:
821 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'').
822 replace(u'avf-', u'')
824 vals[name] = OrderedDict()
825 y_val_1 = test_vals[u"1"][0] / 1000000.0
826 y_val_2 = test_vals[u"2"][0] / 1000000.0 if test_vals[u"2"][0] \
828 y_val_4 = test_vals[u"4"][0] / 1000000.0 if test_vals[u"4"][0] \
831 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
832 vals[name][u"rel"] = [1.0, None, None]
833 vals[name][u"ideal"] = [
835 y_1c_max[test_name] * 2,
836 y_1c_max[test_name] * 4
838 vals[name][u"diff"] = [
839 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
841 vals[name][u"count"] = [
848 val_max = max(vals[name][u"val"])
849 except ValueError as err:
850 logging.error(repr(err))
853 y_max.append(val_max)
856 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
857 vals[name][u"diff"][1] = \
858 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
860 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
861 vals[name][u"diff"][2] = \
862 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
863 except IndexError as err:
864 logging.warning(f"No data for {test_name}")
865 logging.warning(repr(err))
868 if u"x520" in test_name:
869 limit = plot[u"limits"][u"nic"][u"x520"]
870 elif u"x710" in test_name:
871 limit = plot[u"limits"][u"nic"][u"x710"]
872 elif u"xxv710" in test_name:
873 limit = plot[u"limits"][u"nic"][u"xxv710"]
874 elif u"xl710" in test_name:
875 limit = plot[u"limits"][u"nic"][u"xl710"]
876 elif u"x553" in test_name:
877 limit = plot[u"limits"][u"nic"][u"x553"]
880 if limit > nic_limit:
883 mul = 2 if u"ge2p" in test_name else 1
884 if u"10ge" in test_name:
885 limit = plot[u"limits"][u"link"][u"10ge"] * mul
886 elif u"25ge" in test_name:
887 limit = plot[u"limits"][u"link"][u"25ge"] * mul
888 elif u"40ge" in test_name:
889 limit = plot[u"limits"][u"link"][u"40ge"] * mul
890 elif u"100ge" in test_name:
891 limit = plot[u"limits"][u"link"][u"100ge"] * mul
894 if limit > lnk_limit:
903 threshold = 1.1 * max(y_max) # 10%
904 except ValueError as err:
907 nic_limit /= 1000000.0
908 traces.append(plgo.Scatter(
910 y=[nic_limit, ] * len(x_vals),
911 name=f"NIC: {nic_limit:.2f}Mpps",
920 annotations.append(dict(
927 text=f"NIC: {nic_limit:.2f}Mpps",
935 y_max.append(nic_limit)
937 lnk_limit /= 1000000.0
938 if lnk_limit < threshold:
939 traces.append(plgo.Scatter(
941 y=[lnk_limit, ] * len(x_vals),
942 name=f"Link: {lnk_limit:.2f}Mpps",
951 annotations.append(dict(
958 text=f"Link: {lnk_limit:.2f}Mpps",
966 y_max.append(lnk_limit)
968 pci_limit /= 1000000.0
969 if (pci_limit < threshold and
970 (pci_limit < lnk_limit * 0.95 or lnk_limit > lnk_limit * 1.05)):
971 traces.append(plgo.Scatter(
973 y=[pci_limit, ] * len(x_vals),
974 name=f"PCIe: {pci_limit:.2f}Mpps",
983 annotations.append(dict(
990 text=f"PCIe: {pci_limit:.2f}Mpps",
998 y_max.append(pci_limit)
1000 # Perfect and measured:
1002 for name, val in vals.items():
1005 for idx in range(len(val[u"val"])):
1007 if isinstance(val[u"val"][idx], float):
1009 f"No. of Runs: {val[u'count'][idx]}<br>"
1010 f"Mean: {val[u'val'][idx]:.2f}Mpps<br>"
1012 if isinstance(val[u"diff"][idx], float):
1013 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
1014 if isinstance(val[u"rel"][idx], float):
1015 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
1016 hovertext.append(htext)
1023 mode=u"lines+markers",
1032 hoverinfo=u"text+name"
1039 name=f"{name} perfect",
1047 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1052 except (IndexError, ValueError, KeyError) as err:
1053 logging.warning(f"No data for {name}\n{repr(err)}")
1057 file_type = plot.get(u"output-file-type", u".html")
1058 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1059 layout = deepcopy(plot[u"layout"])
1060 if layout.get(u"title", None):
1061 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1062 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1063 layout[u"annotations"].extend(annotations)
1064 plpl = plgo.Figure(data=traces, layout=layout)
1071 filename=f"{plot[u'output-file']}{file_type}"
1073 except PlotlyError as err:
1075 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1080 def plot_http_server_perf_box(plot, input_data):
1081 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1082 specified in the specification file.
1084 :param plot: Plot to generate.
1085 :param input_data: Data to process.
1086 :type plot: pandas.Series
1087 :type input_data: InputData
1090 # Transform the data
1092 f" Creating the data set for the {plot.get(u'type', u'')} "
1093 f"{plot.get(u'title', u'')}."
1095 data = input_data.filter_data(plot)
1097 logging.error(u"No data.")
1100 # Prepare the data for the plot
1105 if y_vals.get(test[u"name"], None) is None:
1106 y_vals[test[u"name"]] = list()
1108 y_vals[test[u"name"]].append(test[u"result"])
1109 except (KeyError, TypeError):
1110 y_vals[test[u"name"]].append(None)
1112 # Add None to the lists with missing data
1114 nr_of_samples = list()
1115 for val in y_vals.values():
1116 if len(val) > max_len:
1118 nr_of_samples.append(len(val))
1119 for val in y_vals.values():
1120 if len(val) < max_len:
1121 val.extend([None for _ in range(max_len - len(val))])
1125 df_y = pd.DataFrame(y_vals)
1127 for i, col in enumerate(df_y.columns):
1130 f"({nr_of_samples[i]:02d} " \
1131 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1132 f"{col.lower().replace(u'-ndrpdr', u'')}"
1134 name_lst = name.split(u'-')
1137 for segment in name_lst:
1138 if (len(name) + len(segment) + 1) > 50 and split_name:
1141 name += segment + u'-'
1144 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1150 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1154 f" Writing file {plot[u'output-file']}"
1155 f"{plot[u'output-file-type']}."
1161 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1163 except PlotlyError as err:
1165 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1170 def plot_nf_heatmap(plot, input_data):
1171 """Generate the plot(s) with algorithm: plot_nf_heatmap
1172 specified in the specification file.
1174 :param plot: Plot to generate.
1175 :param input_data: Data to process.
1176 :type plot: pandas.Series
1177 :type input_data: InputData
1180 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1181 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1183 r'(\d+vm\d+t|\d+dcr\d+t).*$')
1186 # Transform the data
1188 f" Creating the data set for the {plot.get(u'type', u'')} "
1189 f"{plot.get(u'title', u'')}."
1191 data = input_data.filter_data(plot, continue_on_error=True)
1192 if data is None or data.empty:
1193 logging.error(u"No data.")
1199 for tag in test[u"tags"]:
1200 groups = re.search(regex_cn, tag)
1202 chain = str(groups.group(1))
1203 node = str(groups.group(2))
1207 groups = re.search(regex_test_name, test[u"name"])
1208 if groups and len(groups.groups()) == 3:
1210 f"{str(groups.group(1))}-"
1211 f"{str(groups.group(2))}-"
1212 f"{str(groups.group(3))}"
1216 if vals.get(chain, None) is None:
1217 vals[chain] = dict()
1218 if vals[chain].get(node, None) is None:
1219 vals[chain][node] = dict(
1227 if plot[u"include-tests"] == u"MRR":
1228 result = test[u"result"][u"receive-rate"]
1229 elif plot[u"include-tests"] == u"PDR":
1230 result = test[u"throughput"][u"PDR"][u"LOWER"]
1231 elif plot[u"include-tests"] == u"NDR":
1232 result = test[u"throughput"][u"NDR"][u"LOWER"]
1239 vals[chain][node][u"vals"].append(result)
1242 logging.error(u"No data.")
1248 txt_chains.append(key_c)
1249 for key_n in vals[key_c].keys():
1250 txt_nodes.append(key_n)
1251 if vals[key_c][key_n][u"vals"]:
1252 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1253 vals[key_c][key_n][u"mean"] = \
1254 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1255 vals[key_c][key_n][u"stdev"] = \
1256 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1257 txt_nodes = list(set(txt_nodes))
1259 def sort_by_int(value):
1260 """Makes possible to sort a list of strings which represent integers.
1262 :param value: Integer as a string.
1264 :returns: Integer representation of input parameter 'value'.
1269 txt_chains = sorted(txt_chains, key=sort_by_int)
1270 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1272 chains = [i + 1 for i in range(len(txt_chains))]
1273 nodes = [i + 1 for i in range(len(txt_nodes))]
1275 data = [list() for _ in range(len(chains))]
1276 for chain in chains:
1279 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1280 except (KeyError, IndexError):
1282 data[chain - 1].append(val)
1285 my_green = [[0.0, u"rgb(235, 249, 242)"],
1286 [1.0, u"rgb(45, 134, 89)"]]
1288 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1289 [1.0, u"rgb(57, 115, 172)"]]
1291 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1292 [1.0, u"rgb(102, 102, 102)"]]
1295 annotations = list()
1297 text = (u"Test: {name}<br>"
1302 for chain, _ in enumerate(txt_chains):
1304 for node, _ in enumerate(txt_nodes):
1305 if data[chain][node] is not None:
1314 text=str(data[chain][node]),
1322 hover_line.append(text.format(
1323 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1324 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1325 val=data[chain][node],
1326 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1327 hovertext.append(hover_line)
1335 title=plot.get(u"z-axis", u""),
1349 colorscale=my_green,
1355 for idx, item in enumerate(txt_nodes):
1373 for idx, item in enumerate(txt_chains):
1400 text=plot.get(u"x-axis", u""),
1417 text=plot.get(u"y-axis", u""),
1426 updatemenus = list([
1437 u"colorscale": [my_green, ],
1438 u"reversescale": False
1447 u"colorscale": [my_blue, ],
1448 u"reversescale": False
1457 u"colorscale": [my_grey, ],
1458 u"reversescale": False
1469 layout = deepcopy(plot[u"layout"])
1470 except KeyError as err:
1471 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1474 layout[u"annotations"] = annotations
1475 layout[u'updatemenus'] = updatemenus
1479 plpl = plgo.Figure(data=traces, layout=layout)
1483 f" Writing file {plot[u'output-file']}"
1484 f"{plot[u'output-file-type']}."
1490 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1492 except PlotlyError as err:
1494 f" Finished with error: {repr(err)}".replace(u"\n", u" ")