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"])
341 for color, graph in enumerate(graphs):
342 for idx, direction in enumerate((u"direction1", u"direction2")):
349 decoded = hdrh.histogram.HdrHistogram.decode(
350 test[u"latency"][graph][direction][u"hdrh"]
352 except hdrh.codec.HdrLengthException:
354 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
358 for item in decoded.get_recorded_iterator():
359 # The real value is "percentile".
360 # For 100%, we cut that down to "x_perc" to avoid infinity.
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
399 xaxis_max = max(xaxis) if xaxis_max < max(
400 xaxis) else xaxis_max
402 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
403 layout[u"xaxis"][u"range"] = [0, int(log(xaxis_max, 10)) + 1]
404 fig.update_layout(layout)
407 file_name = f"{plot[u'output-file']}-{name_link}.html"
408 logging.info(f" Writing file {file_name}")
412 ploff.plot(fig, show_link=False, auto_open=False,
414 # Add link to the file:
415 if file_links and target_links:
416 with open(file_links, u"a") as file_handler:
419 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
421 except FileNotFoundError as err:
423 f"Not possible to write the link to the file "
424 f"{file_links}\n{err}"
426 except PlotlyError as err:
427 logging.error(f" Finished with error: {repr(err)}")
429 except hdrh.codec.HdrLengthException as err:
430 logging.warning(repr(err))
433 except (ValueError, KeyError) as err:
434 logging.warning(repr(err))
438 def plot_nf_reconf_box_name(plot, input_data):
439 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
440 specified in the specification file.
442 :param plot: Plot to generate.
443 :param input_data: Data to process.
444 :type plot: pandas.Series
445 :type input_data: InputData
450 f" Creating the data set for the {plot.get(u'type', u'')} "
451 f"{plot.get(u'title', u'')}."
453 data = input_data.filter_tests_by_name(
454 plot, params=[u"result", u"parent", u"tags", u"type"]
457 logging.error(u"No data.")
460 # Prepare the data for the plot
461 y_vals = OrderedDict()
466 if y_vals.get(test[u"parent"], None) is None:
467 y_vals[test[u"parent"]] = list()
468 loss[test[u"parent"]] = list()
470 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
471 loss[test[u"parent"]].append(test[u"result"][u"loss"])
472 except (KeyError, TypeError):
473 y_vals[test[u"parent"]].append(None)
475 # Add None to the lists with missing data
477 nr_of_samples = list()
478 for val in y_vals.values():
479 if len(val) > max_len:
481 nr_of_samples.append(len(val))
482 for val in y_vals.values():
483 if len(val) < max_len:
484 val.extend([None for _ in range(max_len - len(val))])
488 df_y = pd.DataFrame(y_vals)
490 for i, col in enumerate(df_y.columns):
491 tst_name = re.sub(REGEX_NIC, u"",
492 col.lower().replace(u'-ndrpdr', u'').
493 replace(u'2n1l-', u''))
495 if u"ipsec" in tst_name:
496 show_name = u'-'.join(tst_name.split(u'-')[2:-1])
498 show_name = u'-'.join(tst_name.split(u'-')[3:-2])
499 traces.append(plgo.Box(
500 x=[str(i + 1) + u'.'] * len(df_y[col]),
504 f"({nr_of_samples[i]:02d} "
505 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
506 f"packets lost average: {mean(loss[col]):.1f}) "
513 layout = deepcopy(plot[u"layout"])
514 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
515 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
516 layout[u"legend"][u"font"][u"size"] = 14
517 layout[u"yaxis"].pop(u"range")
518 plpl = plgo.Figure(data=traces, layout=layout)
521 file_type = plot.get(u"output-file-type", u".html")
522 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
527 filename=f"{plot[u'output-file']}{file_type}"
529 except PlotlyError as err:
531 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
536 def plot_perf_box_name(plot, input_data):
537 """Generate the plot(s) with algorithm: plot_perf_box_name
538 specified in the specification file.
540 :param plot: Plot to generate.
541 :param input_data: Data to process.
542 :type plot: pandas.Series
543 :type input_data: InputData
548 f" Creating data set for the {plot.get(u'type', u'')} "
549 f"{plot.get(u'title', u'')}."
551 data = input_data.filter_tests_by_name(
553 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
555 logging.error(u"No data.")
558 # Prepare the data for the plot
559 plot_title = plot.get(u"title", u"").lower()
561 if u"-gbps" in plot_title:
565 value = u"throughput"
567 y_vals = OrderedDict()
570 for item in plot.get(u"include", tuple()):
571 reg_ex = re.compile(str(item).lower())
574 for test_id, test in build.iteritems():
575 if not re.match(reg_ex, str(test_id).lower()):
577 if y_vals.get(test[u"parent"], None) is None:
578 y_vals[test[u"parent"]] = list()
580 if test[u"type"] in (u"NDRPDR", u"CPS"):
581 test_type = test[u"type"]
583 if u"-pdr" in plot_title:
585 elif u"-ndr" in plot_title:
589 u"Wrong title. No information about test "
590 u"type. Add '-ndr' or '-pdr' to the test "
594 y_vals[test[u"parent"]].append(
595 test[value][ttype][u"LOWER"] * multiplier
598 elif test[u"type"] in (u"SOAK",):
599 y_vals[test[u"parent"]]. \
600 append(test[u"throughput"][u"LOWER"])
603 elif test[u"type"] in (u"HOSTSTACK",):
604 if u"LDPRELOAD" in test[u"tags"]:
605 y_vals[test[u"parent"]].append(
607 test[u"result"][u"bits_per_second"]
610 elif u"VPPECHO" in test[u"tags"]:
611 y_vals[test[u"parent"]].append(
613 test[u"result"][u"client"][u"tx_data"]
616 test[u"result"][u"client"][u"time"]
619 test[u"result"][u"server"][u"time"])
622 test_type = u"HOSTSTACK"
627 except (KeyError, TypeError):
628 y_vals[test[u"parent"]].append(None)
630 # Add None to the lists with missing data
632 nr_of_samples = list()
633 for val in y_vals.values():
634 if len(val) > max_len:
636 nr_of_samples.append(len(val))
637 for val in y_vals.values():
638 if len(val) < max_len:
639 val.extend([None for _ in range(max_len - len(val))])
643 df_y = pd.DataFrame(y_vals)
646 for i, col in enumerate(df_y.columns):
647 tst_name = re.sub(REGEX_NIC, u"",
648 col.lower().replace(u'-ndrpdr', u'').
649 replace(u'2n1l-', u''))
651 x=[str(i + 1) + u'.'] * len(df_y[col]),
652 y=[y / 1e6 if y else None for y in df_y[col]],
655 f"({nr_of_samples[i]:02d} "
656 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
661 if test_type in (u"SOAK", ):
662 kwargs[u"boxpoints"] = u"all"
664 traces.append(plgo.Box(**kwargs))
667 val_max = max(df_y[col])
669 y_max.append(int(val_max / 1e6) + 2)
670 except (ValueError, TypeError) as err:
671 logging.error(repr(err))
676 layout = deepcopy(plot[u"layout"])
677 if layout.get(u"title", None):
678 if test_type in (u"HOSTSTACK", ):
679 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
680 elif test_type in (u"CPS", ):
681 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
683 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
685 layout[u"yaxis"][u"range"] = [0, max(y_max)]
686 plpl = plgo.Figure(data=traces, layout=layout)
689 logging.info(f" Writing file {plot[u'output-file']}.html.")
694 filename=f"{plot[u'output-file']}.html"
696 except PlotlyError as err:
698 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
703 def plot_tsa_name(plot, input_data):
704 """Generate the plot(s) with algorithm:
706 specified in the specification file.
708 :param plot: Plot to generate.
709 :param input_data: Data to process.
710 :type plot: pandas.Series
711 :type input_data: InputData
715 plot_title = plot.get(u"title", u"")
717 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
719 data = input_data.filter_tests_by_name(
721 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
724 logging.error(u"No data.")
727 plot_title = plot_title.lower()
729 if u"-gbps" in plot_title:
734 value = u"throughput"
738 y_vals = OrderedDict()
739 for item in plot.get(u"include", tuple()):
740 reg_ex = re.compile(str(item).lower())
743 for test_id, test in build.iteritems():
744 if re.match(reg_ex, str(test_id).lower()):
745 if y_vals.get(test[u"parent"], None) is None:
746 y_vals[test[u"parent"]] = {
752 if test[u"type"] not in (u"NDRPDR", u"CPS"):
755 if u"-pdr" in plot_title:
757 elif u"-ndr" in plot_title:
762 if u"1C" in test[u"tags"]:
763 y_vals[test[u"parent"]][u"1"].append(
764 test[value][ttype][u"LOWER"] * multiplier
766 elif u"2C" in test[u"tags"]:
767 y_vals[test[u"parent"]][u"2"].append(
768 test[value][ttype][u"LOWER"] * multiplier
770 elif u"4C" in test[u"tags"]:
771 y_vals[test[u"parent"]][u"4"].append(
772 test[value][ttype][u"LOWER"] * multiplier
774 except (KeyError, TypeError):
778 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
782 for test_name, test_vals in y_vals.items():
783 for key, test_val in test_vals.items():
785 avg_val = sum(test_val) / len(test_val)
786 y_vals[test_name][key] = [avg_val, len(test_val)]
787 ideal = avg_val / (int(key) * 1e6)
788 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
789 y_1c_max[test_name] = ideal
796 for test_name, test_vals in y_vals.items():
798 if test_vals[u"1"][1]:
802 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
804 vals[name] = OrderedDict()
805 y_val_1 = test_vals[u"1"][0] / 1e6
806 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
808 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
811 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
812 vals[name][u"rel"] = [1.0, None, None]
813 vals[name][u"ideal"] = [
815 y_1c_max[test_name] * 2,
816 y_1c_max[test_name] * 4
818 vals[name][u"diff"] = [
819 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
821 vals[name][u"count"] = [
828 val_max = max(vals[name][u"val"])
829 except ValueError as err:
830 logging.error(repr(err))
833 y_max.append(val_max)
836 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
837 vals[name][u"diff"][1] = \
838 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
840 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
841 vals[name][u"diff"][2] = \
842 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
843 except IndexError as err:
844 logging.warning(f"No data for {test_name}")
845 logging.warning(repr(err))
848 if u"x520" in test_name:
849 limit = plot[u"limits"][u"nic"][u"x520"]
850 elif u"x710" in test_name:
851 limit = plot[u"limits"][u"nic"][u"x710"]
852 elif u"xxv710" in test_name:
853 limit = plot[u"limits"][u"nic"][u"xxv710"]
854 elif u"xl710" in test_name:
855 limit = plot[u"limits"][u"nic"][u"xl710"]
856 elif u"x553" in test_name:
857 limit = plot[u"limits"][u"nic"][u"x553"]
858 elif u"cx556a" in test_name:
859 limit = plot[u"limits"][u"nic"][u"cx556a"]
862 if limit > nic_limit:
865 mul = 2 if u"ge2p" in test_name else 1
866 if u"10ge" in test_name:
867 limit = plot[u"limits"][u"link"][u"10ge"] * mul
868 elif u"25ge" in test_name:
869 limit = plot[u"limits"][u"link"][u"25ge"] * mul
870 elif u"40ge" in test_name:
871 limit = plot[u"limits"][u"link"][u"40ge"] * mul
872 elif u"100ge" in test_name:
873 limit = plot[u"limits"][u"link"][u"100ge"] * mul
876 if limit > lnk_limit:
879 if u"cx556a" in test_name:
880 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
882 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
883 if limit > pci_limit:
891 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
895 min_limit = min((nic_limit, lnk_limit, pci_limit))
896 if nic_limit == min_limit:
897 traces.append(plgo.Scatter(
899 y=[nic_limit, ] * len(x_vals),
900 name=f"NIC: {nic_limit:.2f}Mpps",
909 annotations.append(dict(
916 text=f"NIC: {nic_limit:.2f}Mpps",
924 y_max.append(nic_limit)
925 elif lnk_limit == min_limit:
926 traces.append(plgo.Scatter(
928 y=[lnk_limit, ] * len(x_vals),
929 name=f"Link: {lnk_limit:.2f}Mpps",
938 annotations.append(dict(
945 text=f"Link: {lnk_limit:.2f}Mpps",
953 y_max.append(lnk_limit)
954 elif pci_limit == min_limit:
955 traces.append(plgo.Scatter(
957 y=[pci_limit, ] * len(x_vals),
958 name=f"PCIe: {pci_limit:.2f}Mpps",
967 annotations.append(dict(
974 text=f"PCIe: {pci_limit:.2f}Mpps",
982 y_max.append(pci_limit)
984 # Perfect and measured:
986 for name, val in vals.items():
989 for idx in range(len(val[u"val"])):
991 if isinstance(val[u"val"][idx], float):
993 f"No. of Runs: {val[u'count'][idx]}<br>"
994 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
996 if isinstance(val[u"diff"][idx], float):
997 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
998 if isinstance(val[u"rel"][idx], float):
999 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
1000 hovertext.append(htext)
1007 mode=u"lines+markers",
1016 hoverinfo=u"text+name"
1023 name=f"{name} perfect",
1031 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1036 except (IndexError, ValueError, KeyError) as err:
1037 logging.warning(f"No data for {name}\n{repr(err)}")
1041 file_type = plot.get(u"output-file-type", u".html")
1042 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1043 layout = deepcopy(plot[u"layout"])
1044 if layout.get(u"title", None):
1045 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1046 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1047 layout[u"annotations"].extend(annotations)
1048 plpl = plgo.Figure(data=traces, layout=layout)
1055 filename=f"{plot[u'output-file']}{file_type}"
1057 except PlotlyError as err:
1059 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1064 def plot_http_server_perf_box(plot, input_data):
1065 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1066 specified in the specification file.
1068 :param plot: Plot to generate.
1069 :param input_data: Data to process.
1070 :type plot: pandas.Series
1071 :type input_data: InputData
1074 # Transform the data
1076 f" Creating the data set for the {plot.get(u'type', u'')} "
1077 f"{plot.get(u'title', u'')}."
1079 data = input_data.filter_data(plot)
1081 logging.error(u"No data.")
1084 # Prepare the data for the plot
1089 if y_vals.get(test[u"name"], None) is None:
1090 y_vals[test[u"name"]] = list()
1092 y_vals[test[u"name"]].append(test[u"result"])
1093 except (KeyError, TypeError):
1094 y_vals[test[u"name"]].append(None)
1096 # Add None to the lists with missing data
1098 nr_of_samples = list()
1099 for val in y_vals.values():
1100 if len(val) > max_len:
1102 nr_of_samples.append(len(val))
1103 for val in y_vals.values():
1104 if len(val) < max_len:
1105 val.extend([None for _ in range(max_len - len(val))])
1109 df_y = pd.DataFrame(y_vals)
1111 for i, col in enumerate(df_y.columns):
1114 f"({nr_of_samples[i]:02d} " \
1115 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1116 f"{col.lower().replace(u'-ndrpdr', u'')}"
1118 name_lst = name.split(u'-')
1121 for segment in name_lst:
1122 if (len(name) + len(segment) + 1) > 50 and split_name:
1125 name += segment + u'-'
1128 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1134 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1138 f" Writing file {plot[u'output-file']}"
1139 f"{plot[u'output-file-type']}."
1145 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1147 except PlotlyError as err:
1149 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1154 def plot_nf_heatmap(plot, input_data):
1155 """Generate the plot(s) with algorithm: plot_nf_heatmap
1156 specified in the specification file.
1158 :param plot: Plot to generate.
1159 :param input_data: Data to process.
1160 :type plot: pandas.Series
1161 :type input_data: InputData
1164 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1165 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1167 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
1170 # Transform the data
1172 f" Creating the data set for the {plot.get(u'type', u'')} "
1173 f"{plot.get(u'title', u'')}."
1175 data = input_data.filter_data(plot, continue_on_error=True)
1176 if data is None or data.empty:
1177 logging.error(u"No data.")
1183 for tag in test[u"tags"]:
1184 groups = re.search(regex_cn, tag)
1186 chain = str(groups.group(1))
1187 node = str(groups.group(2))
1191 groups = re.search(regex_test_name, test[u"name"])
1192 if groups and len(groups.groups()) == 3:
1194 f"{str(groups.group(1))}-"
1195 f"{str(groups.group(2))}-"
1196 f"{str(groups.group(3))}"
1200 if vals.get(chain, None) is None:
1201 vals[chain] = dict()
1202 if vals[chain].get(node, None) is None:
1203 vals[chain][node] = dict(
1211 if plot[u"include-tests"] == u"MRR":
1212 result = test[u"result"][u"receive-rate"]
1213 elif plot[u"include-tests"] == u"PDR":
1214 result = test[u"throughput"][u"PDR"][u"LOWER"]
1215 elif plot[u"include-tests"] == u"NDR":
1216 result = test[u"throughput"][u"NDR"][u"LOWER"]
1223 vals[chain][node][u"vals"].append(result)
1226 logging.error(u"No data.")
1232 txt_chains.append(key_c)
1233 for key_n in vals[key_c].keys():
1234 txt_nodes.append(key_n)
1235 if vals[key_c][key_n][u"vals"]:
1236 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1237 vals[key_c][key_n][u"mean"] = \
1238 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1239 vals[key_c][key_n][u"stdev"] = \
1240 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1241 txt_nodes = list(set(txt_nodes))
1243 def sort_by_int(value):
1244 """Makes possible to sort a list of strings which represent integers.
1246 :param value: Integer as a string.
1248 :returns: Integer representation of input parameter 'value'.
1253 txt_chains = sorted(txt_chains, key=sort_by_int)
1254 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1256 chains = [i + 1 for i in range(len(txt_chains))]
1257 nodes = [i + 1 for i in range(len(txt_nodes))]
1259 data = [list() for _ in range(len(chains))]
1260 for chain in chains:
1263 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1264 except (KeyError, IndexError):
1266 data[chain - 1].append(val)
1269 my_green = [[0.0, u"rgb(235, 249, 242)"],
1270 [1.0, u"rgb(45, 134, 89)"]]
1272 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1273 [1.0, u"rgb(57, 115, 172)"]]
1275 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1276 [1.0, u"rgb(102, 102, 102)"]]
1279 annotations = list()
1281 text = (u"Test: {name}<br>"
1286 for chain, _ in enumerate(txt_chains):
1288 for node, _ in enumerate(txt_nodes):
1289 if data[chain][node] is not None:
1298 text=str(data[chain][node]),
1306 hover_line.append(text.format(
1307 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1308 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1309 val=data[chain][node],
1310 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1311 hovertext.append(hover_line)
1319 title=plot.get(u"z-axis", u""),
1333 colorscale=my_green,
1339 for idx, item in enumerate(txt_nodes):
1357 for idx, item in enumerate(txt_chains):
1384 text=plot.get(u"x-axis", u""),
1401 text=plot.get(u"y-axis", u""),
1410 updatemenus = list([
1421 u"colorscale": [my_green, ],
1422 u"reversescale": False
1431 u"colorscale": [my_blue, ],
1432 u"reversescale": False
1441 u"colorscale": [my_grey, ],
1442 u"reversescale": False
1453 layout = deepcopy(plot[u"layout"])
1454 except KeyError as err:
1455 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1458 layout[u"annotations"] = annotations
1459 layout[u'updatemenus'] = updatemenus
1463 plpl = plgo.Figure(data=traces, layout=layout)
1466 logging.info(f" Writing file {plot[u'output-file']}.html")
1471 filename=f"{plot[u'output-file']}.html"
1473 except PlotlyError as err:
1475 f" Finished with error: {repr(err)}".replace(u"\n", u" ")