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 for idx, direction in enumerate(
121 (u"direction1", u"direction2", )):
123 hdr_lat = test[u"latency"][ttype][direction][u"hdrh"]
124 # TODO: Workaround, HDRH data must be aligned to 4
125 # bytes, remove when not needed.
126 hdr_lat += u"=" * (len(hdr_lat) % 4)
130 decoded = hdrh.histogram.HdrHistogram.decode(hdr_lat)
131 for item in decoded.get_recorded_iterator():
132 percentile = item.percentile_level_iterated_to
133 if percentile != 100.0:
134 xaxis.append(100.0 / (100.0 - percentile))
135 yaxis.append(item.value_iterated_to)
138 f"Direction: {directions[idx]}<br>"
139 f"Percentile: {percentile:.5f}%<br>"
140 f"Latency: {item.value_iterated_to}uSec"
149 showlegend=bool(idx),
157 except hdrh.codec.HdrLengthException as err:
159 f"No or invalid data for HDRHistogram for the test "
164 logging.warning(f"Invalid test type: {test[u'type']}")
166 except (ValueError, KeyError) as err:
167 logging.warning(repr(err))
169 layout = deepcopy(plot[u"layout"])
171 layout[u"title"][u"text"] = \
172 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
173 fig[u"layout"].update(layout)
176 file_type = plot.get(u"output-file-type", u".html")
177 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
180 ploff.plot(fig, show_link=False, auto_open=False,
181 filename=f"{plot[u'output-file']}{file_type}")
182 except PlotlyError as err:
183 logging.error(f" Finished with error: {repr(err)}")
186 def plot_lat_hdrh_bar_name(plot, input_data):
187 """Generate the plot(s) with algorithm: plot_lat_hdrh_bar_name
188 specified in the specification file.
190 :param plot: Plot to generate.
191 :param input_data: Data to process.
192 :type plot: pandas.Series
193 :type input_data: InputData
197 plot_title = plot.get(u"title", u"")
199 f" Creating the data set for the {plot.get(u'type', u'')} "
202 data = input_data.filter_tests_by_name(
203 plot, params=[u"latency", u"parent", u"tags", u"type"])
204 if data is None or len(data[0][0]) == 0:
205 logging.error(u"No data.")
208 # Prepare the data for the plot
209 directions = [u"W-E", u"E-W"]
212 for idx_row, test in enumerate(data[0][0]):
214 if test[u"type"] in (u"NDRPDR",):
215 if u"-pdr" in plot_title.lower():
217 elif u"-ndr" in plot_title.lower():
220 logging.warning(f"Invalid test type: {test[u'type']}")
222 name = re.sub(REGEX_NIC, u"", test[u"parent"].
223 replace(u'-ndrpdr', u'').
224 replace(u'2n1l-', u''))
226 for idx_col, direction in enumerate(
227 (u"direction1", u"direction2", )):
229 hdr_lat = test[u"latency"][ttype][direction][u"hdrh"]
230 # TODO: Workaround, HDRH data must be aligned to 4
231 # bytes, remove when not needed.
232 hdr_lat += u"=" * (len(hdr_lat) % 4)
236 decoded = hdrh.histogram.HdrHistogram.decode(hdr_lat)
237 total_count = decoded.get_total_count()
238 for item in decoded.get_recorded_iterator():
239 xaxis.append(item.value_iterated_to)
240 prob = float(item.count_added_in_this_iter_step) / \
245 f"Direction: {directions[idx_col]}<br>"
246 f"Latency: {item.value_iterated_to}uSec<br>"
247 f"Probability: {prob:.2f}%<br>"
249 f"{item.percentile_level_iterated_to:.2f}"
251 marker_color = [COLORS[idx_row], ] * len(yaxis)
252 marker_color[xaxis.index(
253 decoded.get_value_at_percentile(50.0))] = u"red"
254 marker_color[xaxis.index(
255 decoded.get_value_at_percentile(90.0))] = u"red"
256 marker_color[xaxis.index(
257 decoded.get_value_at_percentile(95.0))] = u"red"
264 marker={u"color": marker_color},
269 except hdrh.codec.HdrLengthException as err:
271 f"No or invalid data for HDRHistogram for the test "
275 if len(histograms) == 2:
276 traces.append(histograms)
279 logging.warning(f"Invalid test type: {test[u'type']}")
281 except (ValueError, KeyError) as err:
282 logging.warning(repr(err))
285 logging.warning(f"No data for {plot_title}.")
292 [{u"type": u"bar"}, {u"type": u"bar"}] for _ in range(len(tests))
297 gridcolor=u"rgb(220, 220, 220)",
298 linecolor=u"rgb(220, 220, 220)",
303 tickcolor=u"rgb(220, 220, 220)",
306 for idx_row, test in enumerate(tests):
307 for idx_col in range(2):
309 traces[idx_row][idx_col],
324 layout = deepcopy(plot[u"layout"])
326 layout[u"title"][u"text"] = \
327 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
328 layout[u"height"] = 250 * len(tests) + 130
330 layout[u"annotations"][2][u"y"] = 1.06 - 0.008 * len(tests)
331 layout[u"annotations"][3][u"y"] = 1.06 - 0.008 * len(tests)
333 for idx, test in enumerate(tests):
334 layout[u"annotations"].append({
339 u"text": f"<b>{test}</b>",
342 u"xanchor": u"center",
344 u"y": 1.0 - float(idx) * 1.06 / len(tests),
345 u"yanchor": u"bottom",
349 fig[u"layout"].update(layout)
352 file_type = plot.get(u"output-file-type", u".html")
353 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
356 ploff.plot(fig, show_link=False, auto_open=False,
357 filename=f"{plot[u'output-file']}{file_type}")
358 except PlotlyError as err:
359 logging.error(f" Finished with error: {repr(err)}")
362 def plot_nf_reconf_box_name(plot, input_data):
363 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
364 specified in the specification file.
366 :param plot: Plot to generate.
367 :param input_data: Data to process.
368 :type plot: pandas.Series
369 :type input_data: InputData
374 f" Creating the data set for the {plot.get(u'type', u'')} "
375 f"{plot.get(u'title', u'')}."
377 data = input_data.filter_tests_by_name(
378 plot, params=[u"result", u"parent", u"tags", u"type"]
381 logging.error(u"No data.")
384 # Prepare the data for the plot
385 y_vals = OrderedDict()
390 if y_vals.get(test[u"parent"], None) is None:
391 y_vals[test[u"parent"]] = list()
392 loss[test[u"parent"]] = list()
394 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
395 loss[test[u"parent"]].append(test[u"result"][u"loss"])
396 except (KeyError, TypeError):
397 y_vals[test[u"parent"]].append(None)
399 # Add None to the lists with missing data
401 nr_of_samples = list()
402 for val in y_vals.values():
403 if len(val) > max_len:
405 nr_of_samples.append(len(val))
406 for val in y_vals.values():
407 if len(val) < max_len:
408 val.extend([None for _ in range(max_len - len(val))])
412 df_y = pd.DataFrame(y_vals)
414 for i, col in enumerate(df_y.columns):
415 tst_name = re.sub(REGEX_NIC, u"",
416 col.lower().replace(u'-ndrpdr', u'').
417 replace(u'2n1l-', u''))
419 traces.append(plgo.Box(
420 x=[str(i + 1) + u'.'] * len(df_y[col]),
421 y=[y if y else None for y in df_y[col]],
424 f"({nr_of_samples[i]:02d} "
425 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
426 f"packets lost average: {mean(loss[col]):.1f}) "
427 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
433 layout = deepcopy(plot[u"layout"])
434 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
435 layout[u"yaxis"][u"title"] = u"<b>Implied Time Lost [s]</b>"
436 layout[u"legend"][u"font"][u"size"] = 14
437 layout[u"yaxis"].pop(u"range")
438 plpl = plgo.Figure(data=traces, layout=layout)
441 file_type = plot.get(u"output-file-type", u".html")
442 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
447 filename=f"{plot[u'output-file']}{file_type}"
449 except PlotlyError as err:
451 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
456 def plot_perf_box_name(plot, input_data):
457 """Generate the plot(s) with algorithm: plot_perf_box_name
458 specified in the specification file.
460 :param plot: Plot to generate.
461 :param input_data: Data to process.
462 :type plot: pandas.Series
463 :type input_data: InputData
468 f" Creating data set for the {plot.get(u'type', u'')} "
469 f"{plot.get(u'title', u'')}."
471 data = input_data.filter_tests_by_name(
472 plot, params=[u"throughput", u"parent", u"tags", u"type"])
474 logging.error(u"No data.")
477 # Prepare the data for the plot
478 y_vals = OrderedDict()
482 if y_vals.get(test[u"parent"], None) is None:
483 y_vals[test[u"parent"]] = list()
485 if (test[u"type"] in (u"NDRPDR", ) and
486 u"-pdr" in plot.get(u"title", u"").lower()):
487 y_vals[test[u"parent"]].\
488 append(test[u"throughput"][u"PDR"][u"LOWER"])
489 elif (test[u"type"] in (u"NDRPDR", ) and
490 u"-ndr" in plot.get(u"title", u"").lower()):
491 y_vals[test[u"parent"]]. \
492 append(test[u"throughput"][u"NDR"][u"LOWER"])
493 elif test[u"type"] in (u"SOAK", ):
494 y_vals[test[u"parent"]].\
495 append(test[u"throughput"][u"LOWER"])
498 except (KeyError, TypeError):
499 y_vals[test[u"parent"]].append(None)
501 # Add None to the lists with missing data
503 nr_of_samples = list()
504 for val in y_vals.values():
505 if len(val) > max_len:
507 nr_of_samples.append(len(val))
508 for val in y_vals.values():
509 if len(val) < max_len:
510 val.extend([None for _ in range(max_len - len(val))])
514 df_y = pd.DataFrame(y_vals)
517 for i, col in enumerate(df_y.columns):
518 tst_name = re.sub(REGEX_NIC, u"",
519 col.lower().replace(u'-ndrpdr', u'').
520 replace(u'2n1l-', u''))
523 x=[str(i + 1) + u'.'] * len(df_y[col]),
524 y=[y / 1000000 if y else None for y in df_y[col]],
527 f"({nr_of_samples[i]:02d} "
528 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
535 val_max = max(df_y[col])
537 y_max.append(int(val_max / 1000000) + 2)
538 except (ValueError, TypeError) as err:
539 logging.error(repr(err))
544 layout = deepcopy(plot[u"layout"])
545 if layout.get(u"title", None):
546 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
548 layout[u"yaxis"][u"range"] = [0, max(y_max)]
549 plpl = plgo.Figure(data=traces, layout=layout)
552 logging.info(f" Writing file {plot[u'output-file']}.html.")
557 filename=f"{plot[u'output-file']}.html"
559 except PlotlyError as err:
561 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
566 def plot_lat_err_bars_name(plot, input_data):
567 """Generate the plot(s) with algorithm: plot_lat_err_bars_name
568 specified in the specification file.
570 :param plot: Plot to generate.
571 :param input_data: Data to process.
572 :type plot: pandas.Series
573 :type input_data: InputData
577 plot_title = plot.get(u"title", u"")
579 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
581 data = input_data.filter_tests_by_name(
582 plot, params=[u"latency", u"parent", u"tags", u"type"])
584 logging.error(u"No data.")
587 # Prepare the data for the plot
588 y_tmp_vals = OrderedDict()
593 logging.debug(f"test[u'latency']: {test[u'latency']}\n")
594 except ValueError as err:
595 logging.warning(repr(err))
596 if y_tmp_vals.get(test[u"parent"], None) is None:
597 y_tmp_vals[test[u"parent"]] = [
598 list(), # direction1, min
599 list(), # direction1, avg
600 list(), # direction1, max
601 list(), # direction2, min
602 list(), # direction2, avg
603 list() # direction2, max
606 if test[u"type"] not in (u"NDRPDR", ):
607 logging.warning(f"Invalid test type: {test[u'type']}")
609 if u"-pdr" in plot_title.lower():
611 elif u"-ndr" in plot_title.lower():
615 f"Invalid test type: {test[u'type']}"
618 y_tmp_vals[test[u"parent"]][0].append(
619 test[u"latency"][ttype][u"direction1"][u"min"])
620 y_tmp_vals[test[u"parent"]][1].append(
621 test[u"latency"][ttype][u"direction1"][u"avg"])
622 y_tmp_vals[test[u"parent"]][2].append(
623 test[u"latency"][ttype][u"direction1"][u"max"])
624 y_tmp_vals[test[u"parent"]][3].append(
625 test[u"latency"][ttype][u"direction2"][u"min"])
626 y_tmp_vals[test[u"parent"]][4].append(
627 test[u"latency"][ttype][u"direction2"][u"avg"])
628 y_tmp_vals[test[u"parent"]][5].append(
629 test[u"latency"][ttype][u"direction2"][u"max"])
630 except (KeyError, TypeError) as err:
631 logging.warning(repr(err))
637 nr_of_samples = list()
638 for key, val in y_tmp_vals.items():
639 name = re.sub(REGEX_NIC, u"", key.replace(u'-ndrpdr', u'').
640 replace(u'2n1l-', u''))
641 x_vals.append(name) # dir 1
642 y_vals.append(mean(val[1]) if val[1] else None)
643 y_mins.append(mean(val[0]) if val[0] else None)
644 y_maxs.append(mean(val[2]) if val[2] else None)
645 nr_of_samples.append(len(val[1]) if val[1] else 0)
646 x_vals.append(name) # dir 2
647 y_vals.append(mean(val[4]) if val[4] else None)
648 y_mins.append(mean(val[3]) if val[3] else None)
649 y_maxs.append(mean(val[5]) if val[5] else None)
650 nr_of_samples.append(len(val[3]) if val[3] else 0)
655 for idx, _ in enumerate(x_vals):
656 if not bool(int(idx % 2)):
657 direction = u"West-East"
659 direction = u"East-West"
661 f"No. of Runs: {nr_of_samples[idx]}<br>"
662 f"Test: {x_vals[idx]}<br>"
663 f"Direction: {direction}<br>"
665 if isinstance(y_maxs[idx], float):
666 hovertext += f"Max: {y_maxs[idx]:.2f}uSec<br>"
667 if isinstance(y_vals[idx], float):
668 hovertext += f"Mean: {y_vals[idx]:.2f}uSec<br>"
669 if isinstance(y_mins[idx], float):
670 hovertext += f"Min: {y_mins[idx]:.2f}uSec"
672 if isinstance(y_maxs[idx], float) and isinstance(y_vals[idx], float):
673 array = [y_maxs[idx] - y_vals[idx], ]
676 if isinstance(y_mins[idx], float) and isinstance(y_vals[idx], float):
677 arrayminus = [y_vals[idx] - y_mins[idx], ]
679 arrayminus = [None, ]
680 traces.append(plgo.Scatter(
684 legendgroup=x_vals[idx],
685 showlegend=bool(int(idx % 2)),
691 arrayminus=arrayminus,
692 color=COLORS[int(idx / 2)]
696 color=COLORS[int(idx / 2)],
701 annotations.append(dict(
708 text=u"E-W" if bool(int(idx % 2)) else u"W-E",
718 file_type = plot.get(u"output-file-type", u".html")
719 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
720 layout = deepcopy(plot[u"layout"])
721 if layout.get(u"title", None):
722 layout[u"title"] = f"<b>Latency:</b> {layout[u'title']}"
723 layout[u"annotations"] = annotations
724 plpl = plgo.Figure(data=traces, layout=layout)
729 show_link=False, auto_open=False,
730 filename=f"{plot[u'output-file']}{file_type}"
732 except PlotlyError as err:
734 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
739 def plot_tsa_name(plot, input_data):
740 """Generate the plot(s) with algorithm:
742 specified in the specification file.
744 :param plot: Plot to generate.
745 :param input_data: Data to process.
746 :type plot: pandas.Series
747 :type input_data: InputData
751 plot_title = plot.get(u"title", u"")
753 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
755 data = input_data.filter_tests_by_name(
756 plot, params=[u"throughput", u"parent", u"tags", u"type"])
758 logging.error(u"No data.")
761 y_vals = OrderedDict()
765 if y_vals.get(test[u"parent"], None) is None:
766 y_vals[test[u"parent"]] = {
772 if test[u"type"] not in (u"NDRPDR",):
775 if u"-pdr" in plot_title.lower():
777 elif u"-ndr" in plot_title.lower():
782 if u"1C" in test[u"tags"]:
783 y_vals[test[u"parent"]][u"1"]. \
784 append(test[u"throughput"][ttype][u"LOWER"])
785 elif u"2C" in test[u"tags"]:
786 y_vals[test[u"parent"]][u"2"]. \
787 append(test[u"throughput"][ttype][u"LOWER"])
788 elif u"4C" in test[u"tags"]:
789 y_vals[test[u"parent"]][u"4"]. \
790 append(test[u"throughput"][ttype][u"LOWER"])
791 except (KeyError, TypeError):
795 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
799 for test_name, test_vals in y_vals.items():
800 for key, test_val in test_vals.items():
802 avg_val = sum(test_val) / len(test_val)
803 y_vals[test_name][key] = [avg_val, len(test_val)]
804 ideal = avg_val / (int(key) * 1000000.0)
805 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
806 y_1c_max[test_name] = ideal
812 pci_limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
813 for test_name, test_vals in y_vals.items():
815 if test_vals[u"1"][1]:
819 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
821 vals[name] = OrderedDict()
822 y_val_1 = test_vals[u"1"][0] / 1000000.0
823 y_val_2 = test_vals[u"2"][0] / 1000000.0 if test_vals[u"2"][0] \
825 y_val_4 = test_vals[u"4"][0] / 1000000.0 if test_vals[u"4"][0] \
828 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
829 vals[name][u"rel"] = [1.0, None, None]
830 vals[name][u"ideal"] = [
832 y_1c_max[test_name] * 2,
833 y_1c_max[test_name] * 4
835 vals[name][u"diff"] = [
836 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
838 vals[name][u"count"] = [
845 val_max = max(vals[name][u"val"])
846 except ValueError as err:
847 logging.error(repr(err))
850 y_max.append(val_max)
853 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
854 vals[name][u"diff"][1] = \
855 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
857 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
858 vals[name][u"diff"][2] = \
859 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
860 except IndexError as err:
861 logging.warning(f"No data for {test_name}")
862 logging.warning(repr(err))
865 if u"x520" in test_name:
866 limit = plot[u"limits"][u"nic"][u"x520"]
867 elif u"x710" in test_name:
868 limit = plot[u"limits"][u"nic"][u"x710"]
869 elif u"xxv710" in test_name:
870 limit = plot[u"limits"][u"nic"][u"xxv710"]
871 elif u"xl710" in test_name:
872 limit = plot[u"limits"][u"nic"][u"xl710"]
873 elif u"x553" in test_name:
874 limit = plot[u"limits"][u"nic"][u"x553"]
877 if limit > nic_limit:
880 mul = 2 if u"ge2p" in test_name else 1
881 if u"10ge" in test_name:
882 limit = plot[u"limits"][u"link"][u"10ge"] * mul
883 elif u"25ge" in test_name:
884 limit = plot[u"limits"][u"link"][u"25ge"] * mul
885 elif u"40ge" in test_name:
886 limit = plot[u"limits"][u"link"][u"40ge"] * mul
887 elif u"100ge" in test_name:
888 limit = plot[u"limits"][u"link"][u"100ge"] * mul
891 if limit > lnk_limit:
900 threshold = 1.1 * max(y_max) # 10%
901 except ValueError as err:
904 nic_limit /= 1000000.0
905 traces.append(plgo.Scatter(
907 y=[nic_limit, ] * len(x_vals),
908 name=f"NIC: {nic_limit:.2f}Mpps",
917 annotations.append(dict(
924 text=f"NIC: {nic_limit:.2f}Mpps",
932 y_max.append(nic_limit)
934 lnk_limit /= 1000000.0
935 if lnk_limit < threshold:
936 traces.append(plgo.Scatter(
938 y=[lnk_limit, ] * len(x_vals),
939 name=f"Link: {lnk_limit:.2f}Mpps",
948 annotations.append(dict(
955 text=f"Link: {lnk_limit:.2f}Mpps",
963 y_max.append(lnk_limit)
965 pci_limit /= 1000000.0
966 if (pci_limit < threshold and
967 (pci_limit < lnk_limit * 0.95 or lnk_limit > lnk_limit * 1.05)):
968 traces.append(plgo.Scatter(
970 y=[pci_limit, ] * len(x_vals),
971 name=f"PCIe: {pci_limit:.2f}Mpps",
980 annotations.append(dict(
987 text=f"PCIe: {pci_limit:.2f}Mpps",
995 y_max.append(pci_limit)
997 # Perfect and measured:
999 for name, val in vals.items():
1002 for idx in range(len(val[u"val"])):
1004 if isinstance(val[u"val"][idx], float):
1006 f"No. of Runs: {val[u'count'][idx]}<br>"
1007 f"Mean: {val[u'val'][idx]:.2f}Mpps<br>"
1009 if isinstance(val[u"diff"][idx], float):
1010 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
1011 if isinstance(val[u"rel"][idx], float):
1012 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
1013 hovertext.append(htext)
1020 mode=u"lines+markers",
1029 hoverinfo=u"text+name"
1036 name=f"{name} perfect",
1044 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1049 except (IndexError, ValueError, KeyError) as err:
1050 logging.warning(f"No data for {name}\n{repr(err)}")
1054 file_type = plot.get(u"output-file-type", u".html")
1055 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1056 layout = deepcopy(plot[u"layout"])
1057 if layout.get(u"title", None):
1058 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1059 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1060 layout[u"annotations"].extend(annotations)
1061 plpl = plgo.Figure(data=traces, layout=layout)
1068 filename=f"{plot[u'output-file']}{file_type}"
1070 except PlotlyError as err:
1072 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1077 def plot_http_server_perf_box(plot, input_data):
1078 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1079 specified in the specification file.
1081 :param plot: Plot to generate.
1082 :param input_data: Data to process.
1083 :type plot: pandas.Series
1084 :type input_data: InputData
1087 # Transform the data
1089 f" Creating the data set for the {plot.get(u'type', u'')} "
1090 f"{plot.get(u'title', u'')}."
1092 data = input_data.filter_data(plot)
1094 logging.error(u"No data.")
1097 # Prepare the data for the plot
1102 if y_vals.get(test[u"name"], None) is None:
1103 y_vals[test[u"name"]] = list()
1105 y_vals[test[u"name"]].append(test[u"result"])
1106 except (KeyError, TypeError):
1107 y_vals[test[u"name"]].append(None)
1109 # Add None to the lists with missing data
1111 nr_of_samples = list()
1112 for val in y_vals.values():
1113 if len(val) > max_len:
1115 nr_of_samples.append(len(val))
1116 for val in y_vals.values():
1117 if len(val) < max_len:
1118 val.extend([None for _ in range(max_len - len(val))])
1122 df_y = pd.DataFrame(y_vals)
1124 for i, col in enumerate(df_y.columns):
1127 f"({nr_of_samples[i]:02d} " \
1128 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1129 f"{col.lower().replace(u'-ndrpdr', u'')}"
1131 name_lst = name.split(u'-')
1134 for segment in name_lst:
1135 if (len(name) + len(segment) + 1) > 50 and split_name:
1138 name += segment + u'-'
1141 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1147 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1151 f" Writing file {plot[u'output-file']}"
1152 f"{plot[u'output-file-type']}."
1158 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1160 except PlotlyError as err:
1162 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1167 def plot_nf_heatmap(plot, input_data):
1168 """Generate the plot(s) with algorithm: plot_nf_heatmap
1169 specified in the specification file.
1171 :param plot: Plot to generate.
1172 :param input_data: Data to process.
1173 :type plot: pandas.Series
1174 :type input_data: InputData
1177 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1178 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1180 r'(\d+vm\d+t|\d+dcr\d+t).*$')
1183 # Transform the data
1185 f" Creating the data set for the {plot.get(u'type', u'')} "
1186 f"{plot.get(u'title', u'')}."
1188 data = input_data.filter_data(plot, continue_on_error=True)
1189 if data is None or data.empty:
1190 logging.error(u"No data.")
1196 for tag in test[u"tags"]:
1197 groups = re.search(regex_cn, tag)
1199 chain = str(groups.group(1))
1200 node = str(groups.group(2))
1204 groups = re.search(regex_test_name, test[u"name"])
1205 if groups and len(groups.groups()) == 3:
1207 f"{str(groups.group(1))}-"
1208 f"{str(groups.group(2))}-"
1209 f"{str(groups.group(3))}"
1213 if vals.get(chain, None) is None:
1214 vals[chain] = dict()
1215 if vals[chain].get(node, None) is None:
1216 vals[chain][node] = dict(
1224 if plot[u"include-tests"] == u"MRR":
1225 result = test[u"result"][u"receive-rate"]
1226 elif plot[u"include-tests"] == u"PDR":
1227 result = test[u"throughput"][u"PDR"][u"LOWER"]
1228 elif plot[u"include-tests"] == u"NDR":
1229 result = test[u"throughput"][u"NDR"][u"LOWER"]
1236 vals[chain][node][u"vals"].append(result)
1239 logging.error(u"No data.")
1245 txt_chains.append(key_c)
1246 for key_n in vals[key_c].keys():
1247 txt_nodes.append(key_n)
1248 if vals[key_c][key_n][u"vals"]:
1249 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1250 vals[key_c][key_n][u"mean"] = \
1251 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1252 vals[key_c][key_n][u"stdev"] = \
1253 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1254 txt_nodes = list(set(txt_nodes))
1256 def sort_by_int(value):
1257 """Makes possible to sort a list of strings which represent integers.
1259 :param value: Integer as a string.
1261 :returns: Integer representation of input parameter 'value'.
1266 txt_chains = sorted(txt_chains, key=sort_by_int)
1267 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1269 chains = [i + 1 for i in range(len(txt_chains))]
1270 nodes = [i + 1 for i in range(len(txt_nodes))]
1272 data = [list() for _ in range(len(chains))]
1273 for chain in chains:
1276 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1277 except (KeyError, IndexError):
1279 data[chain - 1].append(val)
1282 my_green = [[0.0, u"rgb(235, 249, 242)"],
1283 [1.0, u"rgb(45, 134, 89)"]]
1285 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1286 [1.0, u"rgb(57, 115, 172)"]]
1288 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1289 [1.0, u"rgb(102, 102, 102)"]]
1292 annotations = list()
1294 text = (u"Test: {name}<br>"
1299 for chain, _ in enumerate(txt_chains):
1301 for node, _ in enumerate(txt_nodes):
1302 if data[chain][node] is not None:
1311 text=str(data[chain][node]),
1319 hover_line.append(text.format(
1320 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1321 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1322 val=data[chain][node],
1323 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1324 hovertext.append(hover_line)
1332 title=plot.get(u"z-axis", u""),
1346 colorscale=my_green,
1352 for idx, item in enumerate(txt_nodes):
1370 for idx, item in enumerate(txt_chains):
1397 text=plot.get(u"x-axis", u""),
1414 text=plot.get(u"y-axis", u""),
1423 updatemenus = list([
1434 u"colorscale": [my_green, ],
1435 u"reversescale": False
1444 u"colorscale": [my_blue, ],
1445 u"reversescale": False
1454 u"colorscale": [my_grey, ],
1455 u"reversescale": False
1466 layout = deepcopy(plot[u"layout"])
1467 except KeyError as err:
1468 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1471 layout[u"annotations"] = annotations
1472 layout[u'updatemenus'] = updatemenus
1476 plpl = plgo.Figure(data=traces, layout=layout)
1480 f" Writing file {plot[u'output-file']}"
1481 f"{plot[u'output-file-type']}."
1487 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1489 except PlotlyError as err:
1491 f" Finished with error: {repr(err)}".replace(u"\n", u" ")