1 # Copyright (c) 2021 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.
24 import plotly.offline as ploff
25 import plotly.graph_objs as plgo
27 from collections import OrderedDict
28 from copy import deepcopy
31 from plotly.exceptions import PlotlyError
33 from pal_utils import mean, stdev
62 REGEX_NIC = re.compile(r'(\d*ge\dp\d\D*\d*[a-z]*)-')
64 # This value depends on latency stream rate (9001 pps) and duration (5s).
65 PERCENTILE_MAX = 99.9995
68 def generate_plots(spec, data):
69 """Generate all plots specified in the specification file.
71 :param spec: Specification read from the specification file.
72 :param data: Data to process.
73 :type spec: Specification
78 u"plot_nf_reconf_box_name": plot_nf_reconf_box_name,
79 u"plot_perf_box_name": plot_perf_box_name,
80 u"plot_tsa_name": plot_tsa_name,
81 u"plot_http_server_perf_box": plot_http_server_perf_box,
82 u"plot_nf_heatmap": plot_nf_heatmap,
83 u"plot_hdrh_lat_by_percentile": plot_hdrh_lat_by_percentile,
84 u"plot_hdrh_lat_by_percentile_x_log": plot_hdrh_lat_by_percentile_x_log
87 logging.info(u"Generating the plots ...")
88 for index, plot in enumerate(spec.plots):
90 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
91 plot[u"limits"] = spec.configuration[u"limits"]
92 generator[plot[u"algorithm"]](plot, data)
93 logging.info(u" Done.")
94 except NameError as err:
96 f"Probably algorithm {plot[u'algorithm']} is not defined: "
99 logging.info(u"Done.")
102 def plot_hdrh_lat_by_percentile(plot, input_data):
103 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile
104 specified in the specification file.
106 :param plot: Plot to generate.
107 :param input_data: Data to process.
108 :type plot: pandas.Series
109 :type input_data: InputData
114 f" Creating the data set for the {plot.get(u'type', u'')} "
115 f"{plot.get(u'title', u'')}."
117 if plot.get(u"include", None):
118 data = input_data.filter_tests_by_name(
120 params=[u"name", u"latency", u"parent", u"tags", u"type"]
122 elif plot.get(u"filter", None):
123 data = input_data.filter_data(
125 params=[u"name", u"latency", u"parent", u"tags", u"type"],
126 continue_on_error=True
129 job = list(plot[u"data"].keys())[0]
130 build = str(plot[u"data"][job][0])
131 data = input_data.tests(job, build)
133 if data is None or len(data) == 0:
134 logging.error(u"No data.")
138 u"LAT0": u"No-load.",
139 u"PDR10": u"Low-load, 10% PDR.",
140 u"PDR50": u"Mid-load, 50% PDR.",
141 u"PDR90": u"High-load, 90% PDR.",
142 u"PDR": u"Full-load, 100% PDR.",
143 u"NDR10": u"Low-load, 10% NDR.",
144 u"NDR50": u"Mid-load, 50% NDR.",
145 u"NDR90": u"High-load, 90% NDR.",
146 u"NDR": u"Full-load, 100% NDR."
156 file_links = plot.get(u"output-file-links", None)
157 target_links = plot.get(u"target-links", None)
161 if test[u"type"] not in (u"NDRPDR",):
162 logging.warning(f"Invalid test type: {test[u'type']}")
164 name = re.sub(REGEX_NIC, u"", test[u"parent"].
165 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
167 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
168 except (IndexError, AttributeError, KeyError, ValueError):
170 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
172 logging.info(f" Generating the graph: {name_link}")
175 layout = deepcopy(plot[u"layout"])
177 for color, graph in enumerate(graphs):
178 for idx, direction in enumerate((u"direction1", u"direction2")):
184 decoded = hdrh.histogram.HdrHistogram.decode(
185 test[u"latency"][graph][direction][u"hdrh"]
187 except hdrh.codec.HdrLengthException:
189 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
193 for item in decoded.get_recorded_iterator():
194 percentile = item.percentile_level_iterated_to
195 xaxis.append(previous_x)
196 yaxis.append(item.value_iterated_to)
198 f"<b>{desc[graph]}</b><br>"
199 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
200 f"Percentile: {previous_x:.5f}-{percentile:.5f}%<br>"
201 f"Latency: {item.value_iterated_to}uSec"
203 xaxis.append(percentile)
204 yaxis.append(item.value_iterated_to)
206 f"<b>{desc[graph]}</b><br>"
207 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
208 f"Percentile: {previous_x:.5f}-{percentile:.5f}%<br>"
209 f"Latency: {item.value_iterated_to}uSec"
211 previous_x = percentile
218 legendgroup=desc[graph],
219 showlegend=bool(idx),
223 width=1 if idx % 2 else 2
230 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
231 fig.update_layout(layout)
234 file_name = f"{plot[u'output-file']}-{name_link}.html"
235 logging.info(f" Writing file {file_name}")
239 ploff.plot(fig, show_link=False, auto_open=False,
241 # Add link to the file:
242 if file_links and target_links:
243 with open(file_links, u"a") as file_handler:
246 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
248 except FileNotFoundError as err:
250 f"Not possible to write the link to the file "
251 f"{file_links}\n{err}"
253 except PlotlyError as err:
254 logging.error(f" Finished with error: {repr(err)}")
256 except hdrh.codec.HdrLengthException as err:
257 logging.warning(repr(err))
260 except (ValueError, KeyError) as err:
261 logging.warning(repr(err))
265 def plot_hdrh_lat_by_percentile_x_log(plot, input_data):
266 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile_x_log
267 specified in the specification file.
269 :param plot: Plot to generate.
270 :param input_data: Data to process.
271 :type plot: pandas.Series
272 :type input_data: InputData
277 f" Creating the data set for the {plot.get(u'type', u'')} "
278 f"{plot.get(u'title', u'')}."
280 if plot.get(u"include", None):
281 data = input_data.filter_tests_by_name(
283 params=[u"name", u"latency", u"parent", u"tags", u"type"]
285 elif plot.get(u"filter", None):
286 data = input_data.filter_data(
288 params=[u"name", u"latency", u"parent", u"tags", u"type"],
289 continue_on_error=True
292 job = list(plot[u"data"].keys())[0]
293 build = str(plot[u"data"][job][0])
294 data = input_data.tests(job, build)
296 if data is None or len(data) == 0:
297 logging.error(u"No data.")
301 u"LAT0": u"No-load.",
302 u"PDR10": u"Low-load, 10% PDR.",
303 u"PDR50": u"Mid-load, 50% PDR.",
304 u"PDR90": u"High-load, 90% PDR.",
305 u"PDR": u"Full-load, 100% PDR.",
306 u"NDR10": u"Low-load, 10% NDR.",
307 u"NDR50": u"Mid-load, 50% NDR.",
308 u"NDR90": u"High-load, 90% NDR.",
309 u"NDR": u"Full-load, 100% NDR."
319 file_links = plot.get(u"output-file-links", None)
320 target_links = plot.get(u"target-links", None)
324 if test[u"type"] not in (u"NDRPDR",):
325 logging.warning(f"Invalid test type: {test[u'type']}")
327 name = re.sub(REGEX_NIC, u"", test[u"parent"].
328 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
330 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
331 except (IndexError, AttributeError, KeyError, ValueError):
333 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
335 logging.info(f" Generating the graph: {name_link}")
338 layout = deepcopy(plot[u"layout"])
340 for color, graph in enumerate(graphs):
341 for idx, direction in enumerate((u"direction1", u"direction2")):
348 decoded = hdrh.histogram.HdrHistogram.decode(
349 test[u"latency"][graph][direction][u"hdrh"]
351 except hdrh.codec.HdrLengthException:
353 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
357 for item in decoded.get_recorded_iterator():
358 # The real value is "percentile".
359 # For 100%, we cut that down to "x_perc" to avoid
361 percentile = item.percentile_level_iterated_to
362 x_perc = min(percentile, PERCENTILE_MAX)
363 xaxis.append(previous_x)
364 yaxis.append(item.value_iterated_to)
366 f"<b>{desc[graph]}</b><br>"
367 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
368 f"Percentile: {prev_perc:.5f}-{percentile:.5f}%<br>"
369 f"Latency: {item.value_iterated_to}uSec"
371 next_x = 100.0 / (100.0 - x_perc)
373 yaxis.append(item.value_iterated_to)
375 f"<b>{desc[graph]}</b><br>"
376 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
377 f"Percentile: {prev_perc:.5f}-{percentile:.5f}%<br>"
378 f"Latency: {item.value_iterated_to}uSec"
381 prev_perc = percentile
388 legendgroup=desc[graph],
389 showlegend=not(bool(idx)),
393 width=1 if idx % 2 else 2
400 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
401 layout[u"xaxis"][u"range"] = [0, 5]
402 # layout[u"xaxis"][u"range"] = [
403 # 0, round(log(100.0 / (100.0 - PERCENTILE_MAX), 10))
405 fig.update_layout(layout)
408 file_name = f"{plot[u'output-file']}-{name_link}.html"
409 logging.info(f" Writing file {file_name}")
413 ploff.plot(fig, show_link=False, auto_open=False,
415 # Add link to the file:
416 if file_links and target_links:
417 with open(file_links, u"a") as file_handler:
420 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
422 except FileNotFoundError as err:
424 f"Not possible to write the link to the file "
425 f"{file_links}\n{err}"
427 except PlotlyError as err:
428 logging.error(f" Finished with error: {repr(err)}")
430 except hdrh.codec.HdrLengthException as err:
431 logging.warning(repr(err))
434 except (ValueError, KeyError) as err:
435 logging.warning(repr(err))
439 def plot_nf_reconf_box_name(plot, input_data):
440 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
441 specified in the specification file.
443 :param plot: Plot to generate.
444 :param input_data: Data to process.
445 :type plot: pandas.Series
446 :type input_data: InputData
451 f" Creating the data set for the {plot.get(u'type', u'')} "
452 f"{plot.get(u'title', u'')}."
454 data = input_data.filter_tests_by_name(
455 plot, params=[u"result", u"parent", u"tags", u"type"]
458 logging.error(u"No data.")
461 # Prepare the data for the plot
462 y_vals = OrderedDict()
467 if y_vals.get(test[u"parent"], None) is None:
468 y_vals[test[u"parent"]] = list()
469 loss[test[u"parent"]] = list()
471 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
472 loss[test[u"parent"]].append(test[u"result"][u"loss"])
473 except (KeyError, TypeError):
474 y_vals[test[u"parent"]].append(None)
476 # Add None to the lists with missing data
478 nr_of_samples = list()
479 for val in y_vals.values():
480 if len(val) > max_len:
482 nr_of_samples.append(len(val))
483 for val in y_vals.values():
484 if len(val) < max_len:
485 val.extend([None for _ in range(max_len - len(val))])
489 df_y = pd.DataFrame(y_vals)
491 for i, col in enumerate(df_y.columns):
493 tst_name = re.sub(REGEX_NIC, u"",
494 col.lower().replace(u'-reconf', u'').
495 replace(u'2n1l-', u'').replace(u'2n-', u'').
496 replace(u'-testpmd', u''))
498 traces.append(plgo.Box(
499 x=[str(i + 1) + u'.'] * len(df_y[col]),
503 f"({nr_of_samples[i]:02d} "
504 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
505 f"packets lost average: {mean(loss[col]):.1f}) "
506 f"{u'-'.join(tst_name.split(u'-')[2:])}"
512 layout = deepcopy(plot[u"layout"])
513 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
514 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
515 layout[u"legend"][u"font"][u"size"] = 14
516 layout[u"yaxis"].pop(u"range")
517 plpl = plgo.Figure(data=traces, layout=layout)
520 file_type = plot.get(u"output-file-type", u".html")
521 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
526 filename=f"{plot[u'output-file']}{file_type}"
528 except PlotlyError as err:
530 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
535 def plot_perf_box_name(plot, input_data):
536 """Generate the plot(s) with algorithm: plot_perf_box_name
537 specified in the specification file.
539 :param plot: Plot to generate.
540 :param input_data: Data to process.
541 :type plot: pandas.Series
542 :type input_data: InputData
547 f" Creating data set for the {plot.get(u'type', u'')} "
548 f"{plot.get(u'title', u'')}."
550 data = input_data.filter_tests_by_name(
552 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
554 logging.error(u"No data.")
557 # Prepare the data for the plot
558 plot_title = plot.get(u"title", u"").lower()
560 if u"-gbps" in plot_title:
564 value = u"throughput"
566 y_vals = OrderedDict()
569 for item in plot.get(u"include", tuple()):
570 reg_ex = re.compile(str(item).lower())
573 for test_id, test in build.iteritems():
574 if not re.match(reg_ex, str(test_id).lower()):
576 if y_vals.get(test[u"parent"], None) is None:
577 y_vals[test[u"parent"]] = list()
579 if test[u"type"] in (u"NDRPDR", u"CPS"):
580 test_type = test[u"type"]
582 if u"-pdr" in plot_title:
584 elif u"-ndr" in plot_title:
588 u"Wrong title. No information about test "
589 u"type. Add '-ndr' or '-pdr' to the test "
593 y_vals[test[u"parent"]].append(
594 test[value][ttype][u"LOWER"] * multiplier
597 elif test[u"type"] in (u"SOAK",):
598 y_vals[test[u"parent"]]. \
599 append(test[u"throughput"][u"LOWER"])
602 elif test[u"type"] in (u"HOSTSTACK",):
603 if u"LDPRELOAD" in test[u"tags"]:
604 y_vals[test[u"parent"]].append(
606 test[u"result"][u"bits_per_second"]
609 elif u"VPPECHO" in test[u"tags"]:
610 y_vals[test[u"parent"]].append(
612 test[u"result"][u"client"][u"tx_data"]
615 test[u"result"][u"client"][u"time"]
618 test[u"result"][u"server"][u"time"])
621 test_type = u"HOSTSTACK"
626 except (KeyError, TypeError):
627 y_vals[test[u"parent"]].append(None)
629 # Add None to the lists with missing data
631 nr_of_samples = list()
632 for val in y_vals.values():
633 if len(val) > max_len:
635 nr_of_samples.append(len(val))
636 for val in y_vals.values():
637 if len(val) < max_len:
638 val.extend([None for _ in range(max_len - len(val))])
642 df_y = pd.DataFrame(y_vals)
645 for i, col in enumerate(df_y.columns):
646 tst_name = re.sub(REGEX_NIC, u"",
647 col.lower().replace(u'-ndrpdr', u'').
648 replace(u'2n1l-', u''))
650 x=[str(i + 1) + u'.'] * len(df_y[col]),
651 y=[y / 1e6 if y else None for y in df_y[col]],
654 f"({nr_of_samples[i]:02d} "
655 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
660 if test_type in (u"SOAK", ):
661 kwargs[u"boxpoints"] = u"all"
663 traces.append(plgo.Box(**kwargs))
666 val_max = max(df_y[col])
668 y_max.append(int(val_max / 1e6) + 2)
669 except (ValueError, TypeError) as err:
670 logging.error(repr(err))
675 layout = deepcopy(plot[u"layout"])
676 if layout.get(u"title", None):
677 if test_type in (u"HOSTSTACK", ):
678 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
679 elif test_type in (u"CPS", ):
680 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
682 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
684 layout[u"yaxis"][u"range"] = [0, max(y_max)]
685 plpl = plgo.Figure(data=traces, layout=layout)
688 logging.info(f" Writing file {plot[u'output-file']}.html.")
693 filename=f"{plot[u'output-file']}.html"
695 except PlotlyError as err:
697 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
702 def plot_tsa_name(plot, input_data):
703 """Generate the plot(s) with algorithm:
705 specified in the specification file.
707 :param plot: Plot to generate.
708 :param input_data: Data to process.
709 :type plot: pandas.Series
710 :type input_data: InputData
714 plot_title = plot.get(u"title", u"")
716 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
718 data = input_data.filter_tests_by_name(
720 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
723 logging.error(u"No data.")
726 plot_title = plot_title.lower()
728 if u"-gbps" in plot_title:
733 value = u"throughput"
737 y_vals = OrderedDict()
738 for item in plot.get(u"include", tuple()):
739 reg_ex = re.compile(str(item).lower())
742 for test_id, test in build.iteritems():
743 if re.match(reg_ex, str(test_id).lower()):
744 if y_vals.get(test[u"parent"], None) is None:
745 y_vals[test[u"parent"]] = {
751 if test[u"type"] not in (u"NDRPDR", u"CPS"):
754 if u"-pdr" in plot_title:
756 elif u"-ndr" in plot_title:
761 if u"1C" in test[u"tags"]:
762 y_vals[test[u"parent"]][u"1"].append(
763 test[value][ttype][u"LOWER"] * multiplier
765 elif u"2C" in test[u"tags"]:
766 y_vals[test[u"parent"]][u"2"].append(
767 test[value][ttype][u"LOWER"] * multiplier
769 elif u"4C" in test[u"tags"]:
770 y_vals[test[u"parent"]][u"4"].append(
771 test[value][ttype][u"LOWER"] * multiplier
773 except (KeyError, TypeError):
777 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
781 for test_name, test_vals in y_vals.items():
782 for key, test_val in test_vals.items():
784 avg_val = sum(test_val) / len(test_val)
785 y_vals[test_name][key] = [avg_val, len(test_val)]
786 ideal = avg_val / (int(key) * 1e6)
787 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
788 y_1c_max[test_name] = ideal
795 for test_name, test_vals in y_vals.items():
797 if test_vals[u"1"][1]:
801 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
803 vals[name] = OrderedDict()
804 y_val_1 = test_vals[u"1"][0] / 1e6
805 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
807 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
810 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
811 vals[name][u"rel"] = [1.0, None, None]
812 vals[name][u"ideal"] = [
814 y_1c_max[test_name] * 2,
815 y_1c_max[test_name] * 4
817 vals[name][u"diff"] = [
818 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
820 vals[name][u"count"] = [
827 val_max = max(vals[name][u"val"])
828 except ValueError as err:
829 logging.error(repr(err))
832 y_max.append(val_max)
835 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
836 vals[name][u"diff"][1] = \
837 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
839 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
840 vals[name][u"diff"][2] = \
841 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
842 except IndexError as err:
843 logging.warning(f"No data for {test_name}")
844 logging.warning(repr(err))
847 if u"x520" in test_name:
848 limit = plot[u"limits"][u"nic"][u"x520"]
849 elif u"x710" in test_name:
850 limit = plot[u"limits"][u"nic"][u"x710"]
851 elif u"xxv710" in test_name:
852 limit = plot[u"limits"][u"nic"][u"xxv710"]
853 elif u"xl710" in test_name:
854 limit = plot[u"limits"][u"nic"][u"xl710"]
855 elif u"x553" in test_name:
856 limit = plot[u"limits"][u"nic"][u"x553"]
857 elif u"cx556a" in test_name:
858 limit = plot[u"limits"][u"nic"][u"cx556a"]
861 if limit > nic_limit:
864 mul = 2 if u"ge2p" in test_name else 1
865 if u"10ge" in test_name:
866 limit = plot[u"limits"][u"link"][u"10ge"] * mul
867 elif u"25ge" in test_name:
868 limit = plot[u"limits"][u"link"][u"25ge"] * mul
869 elif u"40ge" in test_name:
870 limit = plot[u"limits"][u"link"][u"40ge"] * mul
871 elif u"100ge" in test_name:
872 limit = plot[u"limits"][u"link"][u"100ge"] * mul
875 if limit > lnk_limit:
878 if u"cx556a" in test_name:
879 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
881 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
882 if limit > pci_limit:
890 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
894 min_limit = min((nic_limit, lnk_limit, pci_limit))
895 if nic_limit == min_limit:
896 traces.append(plgo.Scatter(
898 y=[nic_limit, ] * len(x_vals),
899 name=f"NIC: {nic_limit:.2f}Mpps",
908 annotations.append(dict(
915 text=f"NIC: {nic_limit:.2f}Mpps",
923 y_max.append(nic_limit)
924 elif lnk_limit == min_limit:
925 traces.append(plgo.Scatter(
927 y=[lnk_limit, ] * len(x_vals),
928 name=f"Link: {lnk_limit:.2f}Mpps",
937 annotations.append(dict(
944 text=f"Link: {lnk_limit:.2f}Mpps",
952 y_max.append(lnk_limit)
953 elif pci_limit == min_limit:
954 traces.append(plgo.Scatter(
956 y=[pci_limit, ] * len(x_vals),
957 name=f"PCIe: {pci_limit:.2f}Mpps",
966 annotations.append(dict(
973 text=f"PCIe: {pci_limit:.2f}Mpps",
981 y_max.append(pci_limit)
983 # Perfect and measured:
985 for name, val in vals.items():
988 for idx in range(len(val[u"val"])):
990 if isinstance(val[u"val"][idx], float):
992 f"No. of Runs: {val[u'count'][idx]}<br>"
993 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
995 if isinstance(val[u"diff"][idx], float):
996 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
997 if isinstance(val[u"rel"][idx], float):
998 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
999 hovertext.append(htext)
1006 mode=u"lines+markers",
1015 hoverinfo=u"text+name"
1022 name=f"{name} perfect",
1030 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1035 except (IndexError, ValueError, KeyError) as err:
1036 logging.warning(f"No data for {name}\n{repr(err)}")
1040 file_type = plot.get(u"output-file-type", u".html")
1041 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1042 layout = deepcopy(plot[u"layout"])
1043 if layout.get(u"title", None):
1044 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1045 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1046 layout[u"annotations"].extend(annotations)
1047 plpl = plgo.Figure(data=traces, layout=layout)
1054 filename=f"{plot[u'output-file']}{file_type}"
1056 except PlotlyError as err:
1058 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1063 def plot_http_server_perf_box(plot, input_data):
1064 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1065 specified in the specification file.
1067 :param plot: Plot to generate.
1068 :param input_data: Data to process.
1069 :type plot: pandas.Series
1070 :type input_data: InputData
1073 # Transform the data
1075 f" Creating the data set for the {plot.get(u'type', u'')} "
1076 f"{plot.get(u'title', u'')}."
1078 data = input_data.filter_data(plot)
1080 logging.error(u"No data.")
1083 # Prepare the data for the plot
1088 if y_vals.get(test[u"name"], None) is None:
1089 y_vals[test[u"name"]] = list()
1091 y_vals[test[u"name"]].append(test[u"result"])
1092 except (KeyError, TypeError):
1093 y_vals[test[u"name"]].append(None)
1095 # Add None to the lists with missing data
1097 nr_of_samples = list()
1098 for val in y_vals.values():
1099 if len(val) > max_len:
1101 nr_of_samples.append(len(val))
1102 for val in y_vals.values():
1103 if len(val) < max_len:
1104 val.extend([None for _ in range(max_len - len(val))])
1108 df_y = pd.DataFrame(y_vals)
1110 for i, col in enumerate(df_y.columns):
1113 f"({nr_of_samples[i]:02d} " \
1114 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1115 f"{col.lower().replace(u'-ndrpdr', u'')}"
1117 name_lst = name.split(u'-')
1120 for segment in name_lst:
1121 if (len(name) + len(segment) + 1) > 50 and split_name:
1124 name += segment + u'-'
1127 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1133 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1137 f" Writing file {plot[u'output-file']}"
1138 f"{plot[u'output-file-type']}."
1144 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1146 except PlotlyError as err:
1148 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1153 def plot_nf_heatmap(plot, input_data):
1154 """Generate the plot(s) with algorithm: plot_nf_heatmap
1155 specified in the specification file.
1157 :param plot: Plot to generate.
1158 :param input_data: Data to process.
1159 :type plot: pandas.Series
1160 :type input_data: InputData
1163 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1164 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1166 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
1169 # Transform the data
1171 f" Creating the data set for the {plot.get(u'type', u'')} "
1172 f"{plot.get(u'title', u'')}."
1174 data = input_data.filter_data(plot, continue_on_error=True)
1175 if data is None or data.empty:
1176 logging.error(u"No data.")
1182 for tag in test[u"tags"]:
1183 groups = re.search(regex_cn, tag)
1185 chain = str(groups.group(1))
1186 node = str(groups.group(2))
1190 groups = re.search(regex_test_name, test[u"name"])
1191 if groups and len(groups.groups()) == 3:
1193 f"{str(groups.group(1))}-"
1194 f"{str(groups.group(2))}-"
1195 f"{str(groups.group(3))}"
1199 if vals.get(chain, None) is None:
1200 vals[chain] = dict()
1201 if vals[chain].get(node, None) is None:
1202 vals[chain][node] = dict(
1210 if plot[u"include-tests"] == u"MRR":
1211 result = test[u"result"][u"receive-rate"]
1212 elif plot[u"include-tests"] == u"PDR":
1213 result = test[u"throughput"][u"PDR"][u"LOWER"]
1214 elif plot[u"include-tests"] == u"NDR":
1215 result = test[u"throughput"][u"NDR"][u"LOWER"]
1222 vals[chain][node][u"vals"].append(result)
1225 logging.error(u"No data.")
1231 txt_chains.append(key_c)
1232 for key_n in vals[key_c].keys():
1233 txt_nodes.append(key_n)
1234 if vals[key_c][key_n][u"vals"]:
1235 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1236 vals[key_c][key_n][u"mean"] = \
1237 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1238 vals[key_c][key_n][u"stdev"] = \
1239 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1240 txt_nodes = list(set(txt_nodes))
1242 def sort_by_int(value):
1243 """Makes possible to sort a list of strings which represent integers.
1245 :param value: Integer as a string.
1247 :returns: Integer representation of input parameter 'value'.
1252 txt_chains = sorted(txt_chains, key=sort_by_int)
1253 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1255 chains = [i + 1 for i in range(len(txt_chains))]
1256 nodes = [i + 1 for i in range(len(txt_nodes))]
1258 data = [list() for _ in range(len(chains))]
1259 for chain in chains:
1262 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1263 except (KeyError, IndexError):
1265 data[chain - 1].append(val)
1268 my_green = [[0.0, u"rgb(235, 249, 242)"],
1269 [1.0, u"rgb(45, 134, 89)"]]
1271 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1272 [1.0, u"rgb(57, 115, 172)"]]
1274 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1275 [1.0, u"rgb(102, 102, 102)"]]
1278 annotations = list()
1280 text = (u"Test: {name}<br>"
1285 for chain, _ in enumerate(txt_chains):
1287 for node, _ in enumerate(txt_nodes):
1288 if data[chain][node] is not None:
1297 text=str(data[chain][node]),
1305 hover_line.append(text.format(
1306 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1307 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1308 val=data[chain][node],
1309 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1310 hovertext.append(hover_line)
1318 title=plot.get(u"z-axis", u""),
1332 colorscale=my_green,
1338 for idx, item in enumerate(txt_nodes):
1356 for idx, item in enumerate(txt_chains):
1383 text=plot.get(u"x-axis", u""),
1400 text=plot.get(u"y-axis", u""),
1409 updatemenus = list([
1420 u"colorscale": [my_green, ],
1421 u"reversescale": False
1430 u"colorscale": [my_blue, ],
1431 u"reversescale": False
1440 u"colorscale": [my_grey, ],
1441 u"reversescale": False
1452 layout = deepcopy(plot[u"layout"])
1453 except KeyError as err:
1454 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1457 layout[u"annotations"] = annotations
1458 layout[u'updatemenus'] = updatemenus
1462 plpl = plgo.Figure(data=traces, layout=layout)
1465 logging.info(f" Writing file {plot[u'output-file']}.html")
1470 filename=f"{plot[u'output-file']}.html"
1472 except PlotlyError as err:
1474 f" Finished with error: {repr(err)}".replace(u"\n", u" ")