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]*)-')
65 def generate_plots(spec, data):
66 """Generate all plots specified in the specification file.
68 :param spec: Specification read from the specification file.
69 :param data: Data to process.
70 :type spec: Specification
75 u"plot_nf_reconf_box_name": plot_nf_reconf_box_name,
76 u"plot_perf_box_name": plot_perf_box_name,
77 u"plot_tsa_name": plot_tsa_name,
78 u"plot_http_server_perf_box": plot_http_server_perf_box,
79 u"plot_nf_heatmap": plot_nf_heatmap,
80 u"plot_hdrh_lat_by_percentile": plot_hdrh_lat_by_percentile,
81 u"plot_hdrh_lat_by_percentile_x_log": plot_hdrh_lat_by_percentile_x_log
84 logging.info(u"Generating the plots ...")
85 for index, plot in enumerate(spec.plots):
87 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
88 plot[u"limits"] = spec.configuration[u"limits"]
89 generator[plot[u"algorithm"]](plot, data)
90 logging.info(u" Done.")
91 except NameError as err:
93 f"Probably algorithm {plot[u'algorithm']} is not defined: "
96 logging.info(u"Done.")
99 def plot_hdrh_lat_by_percentile(plot, input_data):
100 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile
101 specified in the specification file.
103 :param plot: Plot to generate.
104 :param input_data: Data to process.
105 :type plot: pandas.Series
106 :type input_data: InputData
111 f" Creating the data set for the {plot.get(u'type', u'')} "
112 f"{plot.get(u'title', u'')}."
114 if plot.get(u"include", None):
115 data = input_data.filter_tests_by_name(
117 params=[u"name", u"latency", u"parent", u"tags", u"type"]
119 elif plot.get(u"filter", None):
120 data = input_data.filter_data(
122 params=[u"name", u"latency", u"parent", u"tags", u"type"],
123 continue_on_error=True
126 job = list(plot[u"data"].keys())[0]
127 build = str(plot[u"data"][job][0])
128 data = input_data.tests(job, build)
130 if data is None or len(data) == 0:
131 logging.error(u"No data.")
135 u"LAT0": u"No-load.",
136 u"PDR10": u"Low-load, 10% PDR.",
137 u"PDR50": u"Mid-load, 50% PDR.",
138 u"PDR90": u"High-load, 90% PDR.",
139 u"PDR": u"Full-load, 100% PDR.",
140 u"NDR10": u"Low-load, 10% NDR.",
141 u"NDR50": u"Mid-load, 50% NDR.",
142 u"NDR90": u"High-load, 90% NDR.",
143 u"NDR": u"Full-load, 100% NDR."
153 file_links = plot.get(u"output-file-links", None)
154 target_links = plot.get(u"target-links", None)
158 if test[u"type"] not in (u"NDRPDR",):
159 logging.warning(f"Invalid test type: {test[u'type']}")
161 name = re.sub(REGEX_NIC, u"", test[u"parent"].
162 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
164 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
165 except (IndexError, AttributeError, KeyError, ValueError):
167 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
169 logging.info(f" Generating the graph: {name_link}")
172 layout = deepcopy(plot[u"layout"])
174 for color, graph in enumerate(graphs):
175 for idx, direction in enumerate((u"direction1", u"direction2")):
181 decoded = hdrh.histogram.HdrHistogram.decode(
182 test[u"latency"][graph][direction][u"hdrh"]
184 except hdrh.codec.HdrLengthException:
186 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
190 for item in decoded.get_recorded_iterator():
191 percentile = item.percentile_level_iterated_to
192 if percentile > 99.9999999:
194 xaxis.append(previous_x)
195 yaxis.append(item.value_iterated_to)
197 f"<b>{desc[graph]}</b><br>"
198 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
199 f"Percentile: {previous_x:.5f}-{percentile:.5f}%<br>"
200 f"Latency: {item.value_iterated_to}uSec"
202 xaxis.append(percentile)
203 yaxis.append(item.value_iterated_to)
205 f"<b>{desc[graph]}</b><br>"
206 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
207 f"Percentile: {previous_x:.5f}-{percentile:.5f}%<br>"
208 f"Latency: {item.value_iterated_to}uSec"
210 previous_x = percentile
217 legendgroup=desc[graph],
218 showlegend=bool(idx),
222 width=1 if idx % 2 else 2
229 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
230 fig.update_layout(layout)
233 file_name = f"{plot[u'output-file']}-{name_link}.html"
234 logging.info(f" Writing file {file_name}")
238 ploff.plot(fig, show_link=False, auto_open=False,
240 # Add link to the file:
241 if file_links and target_links:
242 with open(file_links, u"a") as file_handler:
245 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
247 except FileNotFoundError as err:
249 f"Not possible to write the link to the file "
250 f"{file_links}\n{err}"
252 except PlotlyError as err:
253 logging.error(f" Finished with error: {repr(err)}")
255 except hdrh.codec.HdrLengthException as err:
256 logging.warning(repr(err))
259 except (ValueError, KeyError) as err:
260 logging.warning(repr(err))
264 def plot_hdrh_lat_by_percentile_x_log(plot, input_data):
265 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile_x_log
266 specified in the specification file.
268 :param plot: Plot to generate.
269 :param input_data: Data to process.
270 :type plot: pandas.Series
271 :type input_data: InputData
276 f" Creating the data set for the {plot.get(u'type', u'')} "
277 f"{plot.get(u'title', u'')}."
279 if plot.get(u"include", None):
280 data = input_data.filter_tests_by_name(
282 params=[u"name", u"latency", u"parent", u"tags", u"type"]
284 elif plot.get(u"filter", None):
285 data = input_data.filter_data(
287 params=[u"name", u"latency", u"parent", u"tags", u"type"],
288 continue_on_error=True
291 job = list(plot[u"data"].keys())[0]
292 build = str(plot[u"data"][job][0])
293 data = input_data.tests(job, build)
295 if data is None or len(data) == 0:
296 logging.error(u"No data.")
300 u"LAT0": u"No-load.",
301 u"PDR10": u"Low-load, 10% PDR.",
302 u"PDR50": u"Mid-load, 50% PDR.",
303 u"PDR90": u"High-load, 90% PDR.",
304 u"PDR": u"Full-load, 100% PDR.",
305 u"NDR10": u"Low-load, 10% NDR.",
306 u"NDR50": u"Mid-load, 50% NDR.",
307 u"NDR90": u"High-load, 90% NDR.",
308 u"NDR": u"Full-load, 100% NDR."
318 file_links = plot.get(u"output-file-links", None)
319 target_links = plot.get(u"target-links", None)
323 if test[u"type"] not in (u"NDRPDR",):
324 logging.warning(f"Invalid test type: {test[u'type']}")
326 name = re.sub(REGEX_NIC, u"", test[u"parent"].
327 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
329 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
330 except (IndexError, AttributeError, KeyError, ValueError):
332 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
334 logging.info(f" Generating the graph: {name_link}")
337 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 percentile = item.percentile_level_iterated_to
359 if percentile > 99.9999999:
361 xaxis.append(previous_x)
362 yaxis.append(item.value_iterated_to)
364 f"<b>{desc[graph]}</b><br>"
365 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
366 f"Percentile: {prev_perc:.5f}-{percentile:.5f}%<br>"
367 f"Latency: {item.value_iterated_to}uSec"
369 next_x = 100.0 / (100.0 - percentile)
371 yaxis.append(item.value_iterated_to)
373 f"<b>{desc[graph]}</b><br>"
374 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
375 f"Percentile: {prev_perc:.5f}-{percentile:.5f}%<br>"
376 f"Latency: {item.value_iterated_to}uSec"
379 prev_perc = percentile
386 legendgroup=desc[graph],
387 showlegend=not(bool(idx)),
391 width=1 if idx % 2 else 2
397 xaxis_max = max(xaxis) if xaxis_max < max(
398 xaxis) else xaxis_max
400 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
401 layout[u"xaxis"][u"range"] = [0, int(log(xaxis_max, 10)) + 1]
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):
489 tst_name = re.sub(REGEX_NIC, u"",
490 col.lower().replace(u'-ndrpdr', u'').
491 replace(u'2n1l-', u''))
493 traces.append(plgo.Box(
494 x=[str(i + 1) + u'.'] * len(df_y[col]),
495 y=[y if y else None for y in df_y[col]],
498 f"({nr_of_samples[i]:02d} "
499 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
500 f"packets lost average: {mean(loss[col]):.1f}) "
501 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
507 layout = deepcopy(plot[u"layout"])
508 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
509 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
510 layout[u"legend"][u"font"][u"size"] = 14
511 layout[u"yaxis"].pop(u"range")
512 plpl = plgo.Figure(data=traces, layout=layout)
515 file_type = plot.get(u"output-file-type", u".html")
516 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
521 filename=f"{plot[u'output-file']}{file_type}"
523 except PlotlyError as err:
525 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
530 def plot_perf_box_name(plot, input_data):
531 """Generate the plot(s) with algorithm: plot_perf_box_name
532 specified in the specification file.
534 :param plot: Plot to generate.
535 :param input_data: Data to process.
536 :type plot: pandas.Series
537 :type input_data: InputData
542 f" Creating data set for the {plot.get(u'type', u'')} "
543 f"{plot.get(u'title', u'')}."
545 data = input_data.filter_tests_by_name(
547 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
549 logging.error(u"No data.")
552 # Prepare the data for the plot
553 plot_title = plot.get(u"title", u"").lower()
555 if u"-gbps" in plot_title:
559 value = u"throughput"
561 y_vals = OrderedDict()
564 for item in plot.get(u"include", tuple()):
565 reg_ex = re.compile(str(item).lower())
568 for test_id, test in build.iteritems():
569 if not re.match(reg_ex, str(test_id).lower()):
571 if y_vals.get(test[u"parent"], None) is None:
572 y_vals[test[u"parent"]] = list()
574 if test[u"type"] in (u"NDRPDR", u"CPS"):
575 test_type = test[u"type"]
577 if u"-pdr" in plot_title:
579 elif u"-ndr" in plot_title:
583 u"Wrong title. No information about test "
584 u"type. Add '-ndr' or '-pdr' to the test "
588 y_vals[test[u"parent"]].append(
589 test[value][ttype][u"LOWER"] * multiplier
592 elif test[u"type"] in (u"SOAK",):
593 y_vals[test[u"parent"]]. \
594 append(test[u"throughput"][u"LOWER"])
597 elif test[u"type"] in (u"HOSTSTACK",):
598 if u"LDPRELOAD" in test[u"tags"]:
599 y_vals[test[u"parent"]].append(
601 test[u"result"][u"bits_per_second"]
604 elif u"VPPECHO" in test[u"tags"]:
605 y_vals[test[u"parent"]].append(
607 test[u"result"][u"client"][u"tx_data"]
610 test[u"result"][u"client"][u"time"]
613 test[u"result"][u"server"][u"time"])
616 test_type = u"HOSTSTACK"
621 except (KeyError, TypeError):
622 y_vals[test[u"parent"]].append(None)
624 # Add None to the lists with missing data
626 nr_of_samples = list()
627 for val in y_vals.values():
628 if len(val) > max_len:
630 nr_of_samples.append(len(val))
631 for val in y_vals.values():
632 if len(val) < max_len:
633 val.extend([None for _ in range(max_len - len(val))])
637 df_y = pd.DataFrame(y_vals)
640 for i, col in enumerate(df_y.columns):
641 tst_name = re.sub(REGEX_NIC, u"",
642 col.lower().replace(u'-ndrpdr', u'').
643 replace(u'2n1l-', u''))
645 x=[str(i + 1) + u'.'] * len(df_y[col]),
646 y=[y / 1e6 if y else None for y in df_y[col]],
649 f"({nr_of_samples[i]:02d} "
650 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
655 if test_type in (u"SOAK", ):
656 kwargs[u"boxpoints"] = u"all"
658 traces.append(plgo.Box(**kwargs))
661 val_max = max(df_y[col])
663 y_max.append(int(val_max / 1e6) + 2)
664 except (ValueError, TypeError) as err:
665 logging.error(repr(err))
670 layout = deepcopy(plot[u"layout"])
671 if layout.get(u"title", None):
672 if test_type in (u"HOSTSTACK", ):
673 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
674 elif test_type in (u"CPS", ):
675 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
677 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
679 layout[u"yaxis"][u"range"] = [0, max(y_max)]
680 plpl = plgo.Figure(data=traces, layout=layout)
683 logging.info(f" Writing file {plot[u'output-file']}.html.")
688 filename=f"{plot[u'output-file']}.html"
690 except PlotlyError as err:
692 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
697 def plot_tsa_name(plot, input_data):
698 """Generate the plot(s) with algorithm:
700 specified in the specification file.
702 :param plot: Plot to generate.
703 :param input_data: Data to process.
704 :type plot: pandas.Series
705 :type input_data: InputData
709 plot_title = plot.get(u"title", u"")
711 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
713 data = input_data.filter_tests_by_name(
715 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
718 logging.error(u"No data.")
721 plot_title = plot_title.lower()
723 if u"-gbps" in plot_title:
728 value = u"throughput"
732 y_vals = OrderedDict()
733 for item in plot.get(u"include", tuple()):
734 reg_ex = re.compile(str(item).lower())
737 for test_id, test in build.iteritems():
738 if re.match(reg_ex, str(test_id).lower()):
739 if y_vals.get(test[u"parent"], None) is None:
740 y_vals[test[u"parent"]] = {
746 if test[u"type"] not in (u"NDRPDR", u"CPS"):
749 if u"-pdr" in plot_title:
751 elif u"-ndr" in plot_title:
756 if u"1C" in test[u"tags"]:
757 y_vals[test[u"parent"]][u"1"].append(
758 test[value][ttype][u"LOWER"] * multiplier
760 elif u"2C" in test[u"tags"]:
761 y_vals[test[u"parent"]][u"2"].append(
762 test[value][ttype][u"LOWER"] * multiplier
764 elif u"4C" in test[u"tags"]:
765 y_vals[test[u"parent"]][u"4"].append(
766 test[value][ttype][u"LOWER"] * multiplier
768 except (KeyError, TypeError):
772 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
776 for test_name, test_vals in y_vals.items():
777 for key, test_val in test_vals.items():
779 avg_val = sum(test_val) / len(test_val)
780 y_vals[test_name][key] = [avg_val, len(test_val)]
781 ideal = avg_val / (int(key) * 1e6)
782 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
783 y_1c_max[test_name] = ideal
790 for test_name, test_vals in y_vals.items():
792 if test_vals[u"1"][1]:
796 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
798 vals[name] = OrderedDict()
799 y_val_1 = test_vals[u"1"][0] / 1e6
800 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
802 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
805 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
806 vals[name][u"rel"] = [1.0, None, None]
807 vals[name][u"ideal"] = [
809 y_1c_max[test_name] * 2,
810 y_1c_max[test_name] * 4
812 vals[name][u"diff"] = [
813 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
815 vals[name][u"count"] = [
822 val_max = max(vals[name][u"val"])
823 except ValueError as err:
824 logging.error(repr(err))
827 y_max.append(val_max)
830 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
831 vals[name][u"diff"][1] = \
832 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
834 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
835 vals[name][u"diff"][2] = \
836 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
837 except IndexError as err:
838 logging.warning(f"No data for {test_name}")
839 logging.warning(repr(err))
842 if u"x520" in test_name:
843 limit = plot[u"limits"][u"nic"][u"x520"]
844 elif u"x710" in test_name:
845 limit = plot[u"limits"][u"nic"][u"x710"]
846 elif u"xxv710" in test_name:
847 limit = plot[u"limits"][u"nic"][u"xxv710"]
848 elif u"xl710" in test_name:
849 limit = plot[u"limits"][u"nic"][u"xl710"]
850 elif u"x553" in test_name:
851 limit = plot[u"limits"][u"nic"][u"x553"]
852 elif u"cx556a" in test_name:
853 limit = plot[u"limits"][u"nic"][u"cx556a"]
856 if limit > nic_limit:
859 mul = 2 if u"ge2p" in test_name else 1
860 if u"10ge" in test_name:
861 limit = plot[u"limits"][u"link"][u"10ge"] * mul
862 elif u"25ge" in test_name:
863 limit = plot[u"limits"][u"link"][u"25ge"] * mul
864 elif u"40ge" in test_name:
865 limit = plot[u"limits"][u"link"][u"40ge"] * mul
866 elif u"100ge" in test_name:
867 limit = plot[u"limits"][u"link"][u"100ge"] * mul
870 if limit > lnk_limit:
873 if u"cx556a" in test_name:
874 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
876 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
877 if limit > pci_limit:
885 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
889 min_limit = min((nic_limit, lnk_limit, pci_limit))
890 if nic_limit == min_limit:
891 traces.append(plgo.Scatter(
893 y=[nic_limit, ] * len(x_vals),
894 name=f"NIC: {nic_limit:.2f}Mpps",
903 annotations.append(dict(
910 text=f"NIC: {nic_limit:.2f}Mpps",
918 y_max.append(nic_limit)
919 elif lnk_limit == min_limit:
920 traces.append(plgo.Scatter(
922 y=[lnk_limit, ] * len(x_vals),
923 name=f"Link: {lnk_limit:.2f}Mpps",
932 annotations.append(dict(
939 text=f"Link: {lnk_limit:.2f}Mpps",
947 y_max.append(lnk_limit)
948 elif pci_limit == min_limit:
949 traces.append(plgo.Scatter(
951 y=[pci_limit, ] * len(x_vals),
952 name=f"PCIe: {pci_limit:.2f}Mpps",
961 annotations.append(dict(
968 text=f"PCIe: {pci_limit:.2f}Mpps",
976 y_max.append(pci_limit)
978 # Perfect and measured:
980 for name, val in vals.items():
983 for idx in range(len(val[u"val"])):
985 if isinstance(val[u"val"][idx], float):
987 f"No. of Runs: {val[u'count'][idx]}<br>"
988 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
990 if isinstance(val[u"diff"][idx], float):
991 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
992 if isinstance(val[u"rel"][idx], float):
993 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
994 hovertext.append(htext)
1001 mode=u"lines+markers",
1010 hoverinfo=u"text+name"
1017 name=f"{name} perfect",
1025 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1030 except (IndexError, ValueError, KeyError) as err:
1031 logging.warning(f"No data for {name}\n{repr(err)}")
1035 file_type = plot.get(u"output-file-type", u".html")
1036 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1037 layout = deepcopy(plot[u"layout"])
1038 if layout.get(u"title", None):
1039 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1040 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1041 layout[u"annotations"].extend(annotations)
1042 plpl = plgo.Figure(data=traces, layout=layout)
1049 filename=f"{plot[u'output-file']}{file_type}"
1051 except PlotlyError as err:
1053 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1058 def plot_http_server_perf_box(plot, input_data):
1059 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1060 specified in the specification file.
1062 :param plot: Plot to generate.
1063 :param input_data: Data to process.
1064 :type plot: pandas.Series
1065 :type input_data: InputData
1068 # Transform the data
1070 f" Creating the data set for the {plot.get(u'type', u'')} "
1071 f"{plot.get(u'title', u'')}."
1073 data = input_data.filter_data(plot)
1075 logging.error(u"No data.")
1078 # Prepare the data for the plot
1083 if y_vals.get(test[u"name"], None) is None:
1084 y_vals[test[u"name"]] = list()
1086 y_vals[test[u"name"]].append(test[u"result"])
1087 except (KeyError, TypeError):
1088 y_vals[test[u"name"]].append(None)
1090 # Add None to the lists with missing data
1092 nr_of_samples = list()
1093 for val in y_vals.values():
1094 if len(val) > max_len:
1096 nr_of_samples.append(len(val))
1097 for val in y_vals.values():
1098 if len(val) < max_len:
1099 val.extend([None for _ in range(max_len - len(val))])
1103 df_y = pd.DataFrame(y_vals)
1105 for i, col in enumerate(df_y.columns):
1108 f"({nr_of_samples[i]:02d} " \
1109 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1110 f"{col.lower().replace(u'-ndrpdr', u'')}"
1112 name_lst = name.split(u'-')
1115 for segment in name_lst:
1116 if (len(name) + len(segment) + 1) > 50 and split_name:
1119 name += segment + u'-'
1122 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1128 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1132 f" Writing file {plot[u'output-file']}"
1133 f"{plot[u'output-file-type']}."
1139 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1141 except PlotlyError as err:
1143 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1148 def plot_nf_heatmap(plot, input_data):
1149 """Generate the plot(s) with algorithm: plot_nf_heatmap
1150 specified in the specification file.
1152 :param plot: Plot to generate.
1153 :param input_data: Data to process.
1154 :type plot: pandas.Series
1155 :type input_data: InputData
1158 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1159 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1161 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
1164 # Transform the data
1166 f" Creating the data set for the {plot.get(u'type', u'')} "
1167 f"{plot.get(u'title', u'')}."
1169 data = input_data.filter_data(plot, continue_on_error=True)
1170 if data is None or data.empty:
1171 logging.error(u"No data.")
1177 for tag in test[u"tags"]:
1178 groups = re.search(regex_cn, tag)
1180 chain = str(groups.group(1))
1181 node = str(groups.group(2))
1185 groups = re.search(regex_test_name, test[u"name"])
1186 if groups and len(groups.groups()) == 3:
1188 f"{str(groups.group(1))}-"
1189 f"{str(groups.group(2))}-"
1190 f"{str(groups.group(3))}"
1194 if vals.get(chain, None) is None:
1195 vals[chain] = dict()
1196 if vals[chain].get(node, None) is None:
1197 vals[chain][node] = dict(
1205 if plot[u"include-tests"] == u"MRR":
1206 result = test[u"result"][u"receive-rate"]
1207 elif plot[u"include-tests"] == u"PDR":
1208 result = test[u"throughput"][u"PDR"][u"LOWER"]
1209 elif plot[u"include-tests"] == u"NDR":
1210 result = test[u"throughput"][u"NDR"][u"LOWER"]
1217 vals[chain][node][u"vals"].append(result)
1220 logging.error(u"No data.")
1226 txt_chains.append(key_c)
1227 for key_n in vals[key_c].keys():
1228 txt_nodes.append(key_n)
1229 if vals[key_c][key_n][u"vals"]:
1230 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1231 vals[key_c][key_n][u"mean"] = \
1232 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1233 vals[key_c][key_n][u"stdev"] = \
1234 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1235 txt_nodes = list(set(txt_nodes))
1237 def sort_by_int(value):
1238 """Makes possible to sort a list of strings which represent integers.
1240 :param value: Integer as a string.
1242 :returns: Integer representation of input parameter 'value'.
1247 txt_chains = sorted(txt_chains, key=sort_by_int)
1248 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1250 chains = [i + 1 for i in range(len(txt_chains))]
1251 nodes = [i + 1 for i in range(len(txt_nodes))]
1253 data = [list() for _ in range(len(chains))]
1254 for chain in chains:
1257 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1258 except (KeyError, IndexError):
1260 data[chain - 1].append(val)
1263 my_green = [[0.0, u"rgb(235, 249, 242)"],
1264 [1.0, u"rgb(45, 134, 89)"]]
1266 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1267 [1.0, u"rgb(57, 115, 172)"]]
1269 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1270 [1.0, u"rgb(102, 102, 102)"]]
1273 annotations = list()
1275 text = (u"Test: {name}<br>"
1280 for chain, _ in enumerate(txt_chains):
1282 for node, _ in enumerate(txt_nodes):
1283 if data[chain][node] is not None:
1292 text=str(data[chain][node]),
1300 hover_line.append(text.format(
1301 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1302 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1303 val=data[chain][node],
1304 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1305 hovertext.append(hover_line)
1313 title=plot.get(u"z-axis", u""),
1327 colorscale=my_green,
1333 for idx, item in enumerate(txt_nodes):
1351 for idx, item in enumerate(txt_chains):
1378 text=plot.get(u"x-axis", u""),
1395 text=plot.get(u"y-axis", u""),
1404 updatemenus = list([
1415 u"colorscale": [my_green, ],
1416 u"reversescale": False
1425 u"colorscale": [my_blue, ],
1426 u"reversescale": False
1435 u"colorscale": [my_grey, ],
1436 u"reversescale": False
1447 layout = deepcopy(plot[u"layout"])
1448 except KeyError as err:
1449 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1452 layout[u"annotations"] = annotations
1453 layout[u'updatemenus'] = updatemenus
1457 plpl = plgo.Figure(data=traces, layout=layout)
1460 logging.info(f" Writing file {plot[u'output-file']}.html")
1465 filename=f"{plot[u'output-file']}.html"
1467 except PlotlyError as err:
1469 f" Finished with error: {repr(err)}".replace(u"\n", u" ")