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.302]
402 fig.update_layout(layout)
405 file_name = f"{plot[u'output-file']}-{name_link}.html"
406 logging.info(f" Writing file {file_name}")
410 ploff.plot(fig, show_link=False, auto_open=False,
412 # Add link to the file:
413 if file_links and target_links:
414 with open(file_links, u"a") as file_handler:
417 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
419 except FileNotFoundError as err:
421 f"Not possible to write the link to the file "
422 f"{file_links}\n{err}"
424 except PlotlyError as err:
425 logging.error(f" Finished with error: {repr(err)}")
427 except hdrh.codec.HdrLengthException as err:
428 logging.warning(repr(err))
431 except (ValueError, KeyError) as err:
432 logging.warning(repr(err))
436 def plot_nf_reconf_box_name(plot, input_data):
437 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
438 specified in the specification file.
440 :param plot: Plot to generate.
441 :param input_data: Data to process.
442 :type plot: pandas.Series
443 :type input_data: InputData
448 f" Creating the data set for the {plot.get(u'type', u'')} "
449 f"{plot.get(u'title', u'')}."
451 data = input_data.filter_tests_by_name(
452 plot, params=[u"result", u"parent", u"tags", u"type"]
455 logging.error(u"No data.")
458 # Prepare the data for the plot
459 y_vals = OrderedDict()
464 if y_vals.get(test[u"parent"], None) is None:
465 y_vals[test[u"parent"]] = list()
466 loss[test[u"parent"]] = list()
468 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
469 loss[test[u"parent"]].append(test[u"result"][u"loss"])
470 except (KeyError, TypeError):
471 y_vals[test[u"parent"]].append(None)
473 # Add None to the lists with missing data
475 nr_of_samples = list()
476 for val in y_vals.values():
477 if len(val) > max_len:
479 nr_of_samples.append(len(val))
480 for val in y_vals.values():
481 if len(val) < max_len:
482 val.extend([None for _ in range(max_len - len(val))])
486 df_y = pd.DataFrame(y_vals)
488 for i, col in enumerate(df_y.columns):
490 tst_name = re.sub(REGEX_NIC, u"",
491 col.lower().replace(u'-reconf', u'').
492 replace(u'2n1l-', u'').replace(u'2n-', u'').
493 replace(u'-testpmd', u''))
495 traces.append(plgo.Box(
496 x=[str(i + 1) + u'.'] * len(df_y[col]),
500 f"({nr_of_samples[i]:02d} "
501 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
502 f"packets lost average: {mean(loss[col]):.1f}) "
503 f"{u'-'.join(tst_name.split(u'-')[2:])}"
509 layout = deepcopy(plot[u"layout"])
510 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
511 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
512 layout[u"legend"][u"font"][u"size"] = 14
513 layout[u"yaxis"].pop(u"range")
514 plpl = plgo.Figure(data=traces, layout=layout)
517 file_type = plot.get(u"output-file-type", u".html")
518 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
523 filename=f"{plot[u'output-file']}{file_type}"
525 except PlotlyError as err:
527 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
532 def plot_perf_box_name(plot, input_data):
533 """Generate the plot(s) with algorithm: plot_perf_box_name
534 specified in the specification file.
536 :param plot: Plot to generate.
537 :param input_data: Data to process.
538 :type plot: pandas.Series
539 :type input_data: InputData
544 f" Creating data set for the {plot.get(u'type', u'')} "
545 f"{plot.get(u'title', u'')}."
547 data = input_data.filter_tests_by_name(
549 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
551 logging.error(u"No data.")
554 # Prepare the data for the plot
555 plot_title = plot.get(u"title", u"").lower()
557 if u"-gbps" in plot_title:
561 value = u"throughput"
563 y_vals = OrderedDict()
566 for item in plot.get(u"include", tuple()):
567 reg_ex = re.compile(str(item).lower())
570 for test_id, test in build.iteritems():
571 if not re.match(reg_ex, str(test_id).lower()):
573 if y_vals.get(test[u"parent"], None) is None:
574 y_vals[test[u"parent"]] = list()
576 if test[u"type"] in (u"NDRPDR", u"CPS"):
577 test_type = test[u"type"]
579 if u"-pdr" in plot_title:
581 elif u"-ndr" in plot_title:
585 u"Wrong title. No information about test "
586 u"type. Add '-ndr' or '-pdr' to the test "
590 y_vals[test[u"parent"]].append(
591 test[value][ttype][u"LOWER"] * multiplier
594 elif test[u"type"] in (u"SOAK",):
595 y_vals[test[u"parent"]]. \
596 append(test[u"throughput"][u"LOWER"])
599 elif test[u"type"] in (u"HOSTSTACK",):
600 if u"LDPRELOAD" in test[u"tags"]:
601 y_vals[test[u"parent"]].append(
603 test[u"result"][u"bits_per_second"]
606 elif u"VPPECHO" in test[u"tags"]:
607 y_vals[test[u"parent"]].append(
609 test[u"result"][u"client"][u"tx_data"]
612 test[u"result"][u"client"][u"time"]
615 test[u"result"][u"server"][u"time"])
618 test_type = u"HOSTSTACK"
623 except (KeyError, TypeError):
624 y_vals[test[u"parent"]].append(None)
626 # Add None to the lists with missing data
628 nr_of_samples = list()
629 for val in y_vals.values():
630 if len(val) > max_len:
632 nr_of_samples.append(len(val))
633 for val in y_vals.values():
634 if len(val) < max_len:
635 val.extend([None for _ in range(max_len - len(val))])
639 df_y = pd.DataFrame(y_vals)
642 for i, col in enumerate(df_y.columns):
643 tst_name = re.sub(REGEX_NIC, u"",
644 col.lower().replace(u'-ndrpdr', u'').
645 replace(u'2n1l-', u''))
647 x=[str(i + 1) + u'.'] * len(df_y[col]),
648 y=[y / 1e6 if y else None for y in df_y[col]],
651 f"({nr_of_samples[i]:02d} "
652 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
657 if test_type in (u"SOAK", ):
658 kwargs[u"boxpoints"] = u"all"
660 traces.append(plgo.Box(**kwargs))
663 val_max = max(df_y[col])
665 y_max.append(int(val_max / 1e6) + 2)
666 except (ValueError, TypeError) as err:
667 logging.error(repr(err))
672 layout = deepcopy(plot[u"layout"])
673 if layout.get(u"title", None):
674 if test_type in (u"HOSTSTACK", ):
675 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
676 elif test_type in (u"CPS", ):
677 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
679 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
681 layout[u"yaxis"][u"range"] = [0, max(y_max)]
682 plpl = plgo.Figure(data=traces, layout=layout)
685 logging.info(f" Writing file {plot[u'output-file']}.html.")
690 filename=f"{plot[u'output-file']}.html"
692 except PlotlyError as err:
694 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
699 def plot_tsa_name(plot, input_data):
700 """Generate the plot(s) with algorithm:
702 specified in the specification file.
704 :param plot: Plot to generate.
705 :param input_data: Data to process.
706 :type plot: pandas.Series
707 :type input_data: InputData
711 plot_title = plot.get(u"title", u"")
713 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
715 data = input_data.filter_tests_by_name(
717 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
720 logging.error(u"No data.")
723 plot_title = plot_title.lower()
725 if u"-gbps" in plot_title:
730 value = u"throughput"
734 y_vals = OrderedDict()
735 for item in plot.get(u"include", tuple()):
736 reg_ex = re.compile(str(item).lower())
739 for test_id, test in build.iteritems():
740 if re.match(reg_ex, str(test_id).lower()):
741 if y_vals.get(test[u"parent"], None) is None:
742 y_vals[test[u"parent"]] = {
748 if test[u"type"] not in (u"NDRPDR", u"CPS"):
751 if u"-pdr" in plot_title:
753 elif u"-ndr" in plot_title:
758 if u"1C" in test[u"tags"]:
759 y_vals[test[u"parent"]][u"1"].append(
760 test[value][ttype][u"LOWER"] * multiplier
762 elif u"2C" in test[u"tags"]:
763 y_vals[test[u"parent"]][u"2"].append(
764 test[value][ttype][u"LOWER"] * multiplier
766 elif u"4C" in test[u"tags"]:
767 y_vals[test[u"parent"]][u"4"].append(
768 test[value][ttype][u"LOWER"] * multiplier
770 except (KeyError, TypeError):
774 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
778 for test_name, test_vals in y_vals.items():
779 for key, test_val in test_vals.items():
781 avg_val = sum(test_val) / len(test_val)
782 y_vals[test_name][key] = [avg_val, len(test_val)]
783 ideal = avg_val / (int(key) * 1e6)
784 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
785 y_1c_max[test_name] = ideal
792 for test_name, test_vals in y_vals.items():
794 if test_vals[u"1"][1]:
798 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
800 vals[name] = OrderedDict()
801 y_val_1 = test_vals[u"1"][0] / 1e6
802 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
804 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
807 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
808 vals[name][u"rel"] = [1.0, None, None]
809 vals[name][u"ideal"] = [
811 y_1c_max[test_name] * 2,
812 y_1c_max[test_name] * 4
814 vals[name][u"diff"] = [
815 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
817 vals[name][u"count"] = [
824 val_max = max(vals[name][u"val"])
825 except ValueError as err:
826 logging.error(repr(err))
829 y_max.append(val_max)
832 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
833 vals[name][u"diff"][1] = \
834 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
836 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
837 vals[name][u"diff"][2] = \
838 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
839 except IndexError as err:
840 logging.warning(f"No data for {test_name}")
841 logging.warning(repr(err))
844 if u"x520" in test_name:
845 limit = plot[u"limits"][u"nic"][u"x520"]
846 elif u"x710" in test_name:
847 limit = plot[u"limits"][u"nic"][u"x710"]
848 elif u"xxv710" in test_name:
849 limit = plot[u"limits"][u"nic"][u"xxv710"]
850 elif u"xl710" in test_name:
851 limit = plot[u"limits"][u"nic"][u"xl710"]
852 elif u"x553" in test_name:
853 limit = plot[u"limits"][u"nic"][u"x553"]
854 elif u"cx556a" in test_name:
855 limit = plot[u"limits"][u"nic"][u"cx556a"]
858 if limit > nic_limit:
861 mul = 2 if u"ge2p" in test_name else 1
862 if u"10ge" in test_name:
863 limit = plot[u"limits"][u"link"][u"10ge"] * mul
864 elif u"25ge" in test_name:
865 limit = plot[u"limits"][u"link"][u"25ge"] * mul
866 elif u"40ge" in test_name:
867 limit = plot[u"limits"][u"link"][u"40ge"] * mul
868 elif u"100ge" in test_name:
869 limit = plot[u"limits"][u"link"][u"100ge"] * mul
872 if limit > lnk_limit:
875 if u"cx556a" in test_name:
876 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
878 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
879 if limit > pci_limit:
887 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
891 min_limit = min((nic_limit, lnk_limit, pci_limit))
892 if nic_limit == min_limit:
893 traces.append(plgo.Scatter(
895 y=[nic_limit, ] * len(x_vals),
896 name=f"NIC: {nic_limit:.2f}Mpps",
905 annotations.append(dict(
912 text=f"NIC: {nic_limit:.2f}Mpps",
920 y_max.append(nic_limit)
921 elif lnk_limit == min_limit:
922 traces.append(plgo.Scatter(
924 y=[lnk_limit, ] * len(x_vals),
925 name=f"Link: {lnk_limit:.2f}Mpps",
934 annotations.append(dict(
941 text=f"Link: {lnk_limit:.2f}Mpps",
949 y_max.append(lnk_limit)
950 elif pci_limit == min_limit:
951 traces.append(plgo.Scatter(
953 y=[pci_limit, ] * len(x_vals),
954 name=f"PCIe: {pci_limit:.2f}Mpps",
963 annotations.append(dict(
970 text=f"PCIe: {pci_limit:.2f}Mpps",
978 y_max.append(pci_limit)
980 # Perfect and measured:
982 for name, val in vals.items():
985 for idx in range(len(val[u"val"])):
987 if isinstance(val[u"val"][idx], float):
989 f"No. of Runs: {val[u'count'][idx]}<br>"
990 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
992 if isinstance(val[u"diff"][idx], float):
993 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
994 if isinstance(val[u"rel"][idx], float):
995 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
996 hovertext.append(htext)
1003 mode=u"lines+markers",
1012 hoverinfo=u"text+name"
1019 name=f"{name} perfect",
1027 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1032 except (IndexError, ValueError, KeyError) as err:
1033 logging.warning(f"No data for {name}\n{repr(err)}")
1037 file_type = plot.get(u"output-file-type", u".html")
1038 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1039 layout = deepcopy(plot[u"layout"])
1040 if layout.get(u"title", None):
1041 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1042 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1043 layout[u"annotations"].extend(annotations)
1044 plpl = plgo.Figure(data=traces, layout=layout)
1051 filename=f"{plot[u'output-file']}{file_type}"
1053 except PlotlyError as err:
1055 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1060 def plot_http_server_perf_box(plot, input_data):
1061 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1062 specified in the specification file.
1064 :param plot: Plot to generate.
1065 :param input_data: Data to process.
1066 :type plot: pandas.Series
1067 :type input_data: InputData
1070 # Transform the data
1072 f" Creating the data set for the {plot.get(u'type', u'')} "
1073 f"{plot.get(u'title', u'')}."
1075 data = input_data.filter_data(plot)
1077 logging.error(u"No data.")
1080 # Prepare the data for the plot
1085 if y_vals.get(test[u"name"], None) is None:
1086 y_vals[test[u"name"]] = list()
1088 y_vals[test[u"name"]].append(test[u"result"])
1089 except (KeyError, TypeError):
1090 y_vals[test[u"name"]].append(None)
1092 # Add None to the lists with missing data
1094 nr_of_samples = list()
1095 for val in y_vals.values():
1096 if len(val) > max_len:
1098 nr_of_samples.append(len(val))
1099 for val in y_vals.values():
1100 if len(val) < max_len:
1101 val.extend([None for _ in range(max_len - len(val))])
1105 df_y = pd.DataFrame(y_vals)
1107 for i, col in enumerate(df_y.columns):
1110 f"({nr_of_samples[i]:02d} " \
1111 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1112 f"{col.lower().replace(u'-ndrpdr', u'')}"
1114 name_lst = name.split(u'-')
1117 for segment in name_lst:
1118 if (len(name) + len(segment) + 1) > 50 and split_name:
1121 name += segment + u'-'
1124 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1130 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1134 f" Writing file {plot[u'output-file']}"
1135 f"{plot[u'output-file-type']}."
1141 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1143 except PlotlyError as err:
1145 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1150 def plot_nf_heatmap(plot, input_data):
1151 """Generate the plot(s) with algorithm: plot_nf_heatmap
1152 specified in the specification file.
1154 :param plot: Plot to generate.
1155 :param input_data: Data to process.
1156 :type plot: pandas.Series
1157 :type input_data: InputData
1160 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1161 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1163 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
1166 # Transform the data
1168 f" Creating the data set for the {plot.get(u'type', u'')} "
1169 f"{plot.get(u'title', u'')}."
1171 data = input_data.filter_data(plot, continue_on_error=True)
1172 if data is None or data.empty:
1173 logging.error(u"No data.")
1179 for tag in test[u"tags"]:
1180 groups = re.search(regex_cn, tag)
1182 chain = str(groups.group(1))
1183 node = str(groups.group(2))
1187 groups = re.search(regex_test_name, test[u"name"])
1188 if groups and len(groups.groups()) == 3:
1190 f"{str(groups.group(1))}-"
1191 f"{str(groups.group(2))}-"
1192 f"{str(groups.group(3))}"
1196 if vals.get(chain, None) is None:
1197 vals[chain] = dict()
1198 if vals[chain].get(node, None) is None:
1199 vals[chain][node] = dict(
1207 if plot[u"include-tests"] == u"MRR":
1208 result = test[u"result"][u"receive-rate"]
1209 elif plot[u"include-tests"] == u"PDR":
1210 result = test[u"throughput"][u"PDR"][u"LOWER"]
1211 elif plot[u"include-tests"] == u"NDR":
1212 result = test[u"throughput"][u"NDR"][u"LOWER"]
1219 vals[chain][node][u"vals"].append(result)
1222 logging.error(u"No data.")
1228 txt_chains.append(key_c)
1229 for key_n in vals[key_c].keys():
1230 txt_nodes.append(key_n)
1231 if vals[key_c][key_n][u"vals"]:
1232 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1233 vals[key_c][key_n][u"mean"] = \
1234 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1235 vals[key_c][key_n][u"stdev"] = \
1236 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1237 txt_nodes = list(set(txt_nodes))
1239 def sort_by_int(value):
1240 """Makes possible to sort a list of strings which represent integers.
1242 :param value: Integer as a string.
1244 :returns: Integer representation of input parameter 'value'.
1249 txt_chains = sorted(txt_chains, key=sort_by_int)
1250 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1252 chains = [i + 1 for i in range(len(txt_chains))]
1253 nodes = [i + 1 for i in range(len(txt_nodes))]
1255 data = [list() for _ in range(len(chains))]
1256 for chain in chains:
1259 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1260 except (KeyError, IndexError):
1262 data[chain - 1].append(val)
1265 my_green = [[0.0, u"rgb(235, 249, 242)"],
1266 [1.0, u"rgb(45, 134, 89)"]]
1268 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1269 [1.0, u"rgb(57, 115, 172)"]]
1271 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1272 [1.0, u"rgb(102, 102, 102)"]]
1275 annotations = list()
1277 text = (u"Test: {name}<br>"
1282 for chain, _ in enumerate(txt_chains):
1284 for node, _ in enumerate(txt_nodes):
1285 if data[chain][node] is not None:
1294 text=str(data[chain][node]),
1302 hover_line.append(text.format(
1303 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1304 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1305 val=data[chain][node],
1306 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1307 hovertext.append(hover_line)
1315 title=plot.get(u"z-axis", u""),
1329 colorscale=my_green,
1335 for idx, item in enumerate(txt_nodes):
1353 for idx, item in enumerate(txt_chains):
1380 text=plot.get(u"x-axis", u""),
1397 text=plot.get(u"y-axis", u""),
1406 updatemenus = list([
1417 u"colorscale": [my_green, ],
1418 u"reversescale": False
1427 u"colorscale": [my_blue, ],
1428 u"reversescale": False
1437 u"colorscale": [my_grey, ],
1438 u"reversescale": False
1449 layout = deepcopy(plot[u"layout"])
1450 except KeyError as err:
1451 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1454 layout[u"annotations"] = annotations
1455 layout[u'updatemenus'] = updatemenus
1459 plpl = plgo.Figure(data=traces, layout=layout)
1462 logging.info(f" Writing file {plot[u'output-file']}.html")
1467 filename=f"{plot[u'output-file']}.html"
1469 except PlotlyError as err:
1471 f" Finished with error: {repr(err)}".replace(u"\n", u" ")