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 # Keep it slightly higher to ensure rounding errors to not remove tick mark.
66 PERCENTILE_MAX = 99.999501
69 def generate_plots(spec, data):
70 """Generate all plots specified in the specification file.
72 :param spec: Specification read from the specification file.
73 :param data: Data to process.
74 :type spec: Specification
79 u"plot_nf_reconf_box_name": plot_nf_reconf_box_name,
80 u"plot_perf_box_name": plot_perf_box_name,
81 u"plot_tsa_name": plot_tsa_name,
82 u"plot_http_server_perf_box": plot_http_server_perf_box,
83 u"plot_nf_heatmap": plot_nf_heatmap,
84 u"plot_hdrh_lat_by_percentile": plot_hdrh_lat_by_percentile,
85 u"plot_hdrh_lat_by_percentile_x_log": plot_hdrh_lat_by_percentile_x_log,
86 u"plot_mrr_box_name": plot_mrr_box_name,
87 u"plot_ndrpdr_box_name": plot_ndrpdr_box_name
90 logging.info(u"Generating the plots ...")
91 for index, plot in enumerate(spec.plots):
93 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
94 plot[u"limits"] = spec.environment[u"limits"]
95 generator[plot[u"algorithm"]](plot, data)
96 logging.info(u" Done.")
97 except NameError as err:
99 f"Probably algorithm {plot[u'algorithm']} is not defined: "
102 logging.info(u"Done.")
105 def plot_hdrh_lat_by_percentile(plot, input_data):
106 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile
107 specified in the specification file.
109 :param plot: Plot to generate.
110 :param input_data: Data to process.
111 :type plot: pandas.Series
112 :type input_data: InputData
117 f" Creating the data set for the {plot.get(u'type', u'')} "
118 f"{plot.get(u'title', u'')}."
120 if plot.get(u"include", None):
121 data = input_data.filter_tests_by_name(
123 params=[u"name", u"latency", u"parent", u"tags", u"type"]
125 elif plot.get(u"filter", None):
126 data = input_data.filter_data(
128 params=[u"name", u"latency", u"parent", u"tags", u"type"],
129 continue_on_error=True
132 job = list(plot[u"data"].keys())[0]
133 build = str(plot[u"data"][job][0])
134 data = input_data.tests(job, build)
136 if data is None or len(data) == 0:
137 logging.error(u"No data.")
141 u"LAT0": u"No-load.",
142 u"PDR10": u"Low-load, 10% PDR.",
143 u"PDR50": u"Mid-load, 50% PDR.",
144 u"PDR90": u"High-load, 90% PDR.",
145 u"PDR": u"Full-load, 100% PDR.",
146 u"NDR10": u"Low-load, 10% NDR.",
147 u"NDR50": u"Mid-load, 50% NDR.",
148 u"NDR90": u"High-load, 90% NDR.",
149 u"NDR": u"Full-load, 100% NDR."
159 file_links = plot.get(u"output-file-links", None)
160 target_links = plot.get(u"target-links", None)
164 if test[u"type"] not in (u"NDRPDR",):
165 logging.warning(f"Invalid test type: {test[u'type']}")
167 name = re.sub(REGEX_NIC, u"", test[u"parent"].
168 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
170 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
171 except (IndexError, AttributeError, KeyError, ValueError):
173 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
175 logging.info(f" Generating the graph: {name_link}")
178 layout = deepcopy(plot[u"layout"])
180 for color, graph in enumerate(graphs):
181 for idx, direction in enumerate((u"direction1", u"direction2")):
187 decoded = hdrh.histogram.HdrHistogram.decode(
188 test[u"latency"][graph][direction][u"hdrh"]
190 except hdrh.codec.HdrLengthException:
192 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
196 for item in decoded.get_recorded_iterator():
197 percentile = item.percentile_level_iterated_to
198 xaxis.append(previous_x)
199 yaxis.append(item.value_iterated_to)
201 f"<b>{desc[graph]}</b><br>"
202 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
203 f"Percentile: {previous_x:.5f}-{percentile:.5f}%<br>"
204 f"Latency: {item.value_iterated_to}uSec"
206 xaxis.append(percentile)
207 yaxis.append(item.value_iterated_to)
209 f"<b>{desc[graph]}</b><br>"
210 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
211 f"Percentile: {previous_x:.5f}-{percentile:.5f}%<br>"
212 f"Latency: {item.value_iterated_to}uSec"
214 previous_x = percentile
221 legendgroup=desc[graph],
222 showlegend=bool(idx),
226 width=1 if idx % 2 else 2
233 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
234 fig.update_layout(layout)
237 file_name = f"{plot[u'output-file']}-{name_link}.html"
238 logging.info(f" Writing file {file_name}")
242 ploff.plot(fig, show_link=False, auto_open=False,
244 # Add link to the file:
245 if file_links and target_links:
246 with open(file_links, u"a") as file_handler:
249 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
251 except FileNotFoundError as err:
253 f"Not possible to write the link to the file "
254 f"{file_links}\n{err}"
256 except PlotlyError as err:
257 logging.error(f" Finished with error: {repr(err)}")
259 except hdrh.codec.HdrLengthException as err:
260 logging.warning(repr(err))
263 except (ValueError, KeyError) as err:
264 logging.warning(repr(err))
268 def plot_hdrh_lat_by_percentile_x_log(plot, input_data):
269 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile_x_log
270 specified in the specification file.
272 :param plot: Plot to generate.
273 :param input_data: Data to process.
274 :type plot: pandas.Series
275 :type input_data: InputData
280 f" Creating the data set for the {plot.get(u'type', u'')} "
281 f"{plot.get(u'title', u'')}."
283 if plot.get(u"include", None):
284 data = input_data.filter_tests_by_name(
286 params=[u"name", u"latency", u"parent", u"tags", u"type"]
288 elif plot.get(u"filter", None):
289 data = input_data.filter_data(
291 params=[u"name", u"latency", u"parent", u"tags", u"type"],
292 continue_on_error=True
295 job = list(plot[u"data"].keys())[0]
296 build = str(plot[u"data"][job][0])
297 data = input_data.tests(job, build)
299 if data is None or len(data) == 0:
300 logging.error(u"No data.")
304 u"LAT0": u"No-load.",
305 u"PDR10": u"Low-load, 10% PDR.",
306 u"PDR50": u"Mid-load, 50% PDR.",
307 u"PDR90": u"High-load, 90% PDR.",
308 u"PDR": u"Full-load, 100% PDR.",
309 u"NDR10": u"Low-load, 10% NDR.",
310 u"NDR50": u"Mid-load, 50% NDR.",
311 u"NDR90": u"High-load, 90% NDR.",
312 u"NDR": u"Full-load, 100% NDR."
322 file_links = plot.get(u"output-file-links", None)
323 target_links = plot.get(u"target-links", None)
327 if test[u"type"] not in (u"NDRPDR",):
328 logging.warning(f"Invalid test type: {test[u'type']}")
330 name = re.sub(REGEX_NIC, u"", test[u"parent"].
331 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
333 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
334 except (IndexError, AttributeError, KeyError, ValueError):
336 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
338 logging.info(f" Generating the graph: {name_link}")
341 layout = deepcopy(plot[u"layout"])
343 for color, graph in enumerate(graphs):
344 for idx, direction in enumerate((u"direction1", u"direction2")):
351 decoded = hdrh.histogram.HdrHistogram.decode(
352 test[u"latency"][graph][direction][u"hdrh"]
354 except hdrh.codec.HdrLengthException:
356 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
360 for item in decoded.get_recorded_iterator():
361 # The real value is "percentile".
362 # For 100%, we cut that down to "x_perc" to avoid
364 percentile = item.percentile_level_iterated_to
365 x_perc = min(percentile, PERCENTILE_MAX)
366 xaxis.append(previous_x)
367 yaxis.append(item.value_iterated_to)
369 f"<b>{desc[graph]}</b><br>"
370 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
371 f"Percentile: {prev_perc:.5f}-{percentile:.5f}%<br>"
372 f"Latency: {item.value_iterated_to}uSec"
374 next_x = 100.0 / (100.0 - x_perc)
376 yaxis.append(item.value_iterated_to)
378 f"<b>{desc[graph]}</b><br>"
379 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
380 f"Percentile: {prev_perc:.5f}-{percentile:.5f}%<br>"
381 f"Latency: {item.value_iterated_to}uSec"
384 prev_perc = percentile
391 legendgroup=desc[graph],
392 showlegend=not(bool(idx)),
396 width=1 if idx % 2 else 2
403 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
404 x_max = log(100.0 / (100.0 - PERCENTILE_MAX), 10)
405 layout[u"xaxis"][u"range"] = [0, x_max]
406 fig.update_layout(layout)
409 file_name = f"{plot[u'output-file']}-{name_link}.html"
410 logging.info(f" Writing file {file_name}")
414 ploff.plot(fig, show_link=False, auto_open=False,
416 # Add link to the file:
417 if file_links and target_links:
418 with open(file_links, u"a") as file_handler:
421 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
423 except FileNotFoundError as err:
425 f"Not possible to write the link to the file "
426 f"{file_links}\n{err}"
428 except PlotlyError as err:
429 logging.error(f" Finished with error: {repr(err)}")
431 except hdrh.codec.HdrLengthException as err:
432 logging.warning(repr(err))
435 except (ValueError, KeyError) as err:
436 logging.warning(repr(err))
440 def plot_nf_reconf_box_name(plot, input_data):
441 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
442 specified in the specification file.
444 :param plot: Plot to generate.
445 :param input_data: Data to process.
446 :type plot: pandas.Series
447 :type input_data: InputData
452 f" Creating the data set for the {plot.get(u'type', u'')} "
453 f"{plot.get(u'title', u'')}."
455 data = input_data.filter_tests_by_name(
456 plot, params=[u"result", u"parent", u"tags", u"type"]
459 logging.error(u"No data.")
462 for core in plot.get(u"core", tuple()):
463 # Prepare the data for the plot
464 y_vals = OrderedDict()
466 for item in plot.get(u"include", tuple()):
467 reg_ex = re.compile(str(item.format(core=core)).lower())
470 for test_id, test in build.iteritems():
471 if not re.match(reg_ex, str(test_id).lower()):
473 if y_vals.get(test[u"parent"], None) is None:
474 y_vals[test[u"parent"]] = list()
475 loss[test[u"parent"]] = list()
477 y_vals[test[u"parent"]].append(
478 test[u"result"][u"time"]
480 loss[test[u"parent"]].append(
481 test[u"result"][u"loss"]
483 except (KeyError, TypeError):
484 y_vals[test[u"parent"]].append(None)
486 # Add None to the lists with missing data
488 nr_of_samples = list()
489 for val in y_vals.values():
490 if len(val) > max_len:
492 nr_of_samples.append(len(val))
493 for val in y_vals.values():
494 if len(val) < max_len:
495 val.extend([None for _ in range(max_len - len(val))])
499 df_y = pd.DataFrame(y_vals)
501 for i, col in enumerate(df_y.columns):
504 col.lower().replace(u'-reconf', u'').replace(u'2n1l-', u'').
505 replace(u'2n-', u'').replace(u'-testpmd', u'')
507 traces.append(plgo.Box(
508 x=[str(i + 1) + u'.'] * len(df_y[col]),
512 f"({nr_of_samples[i]:02d} "
513 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
514 f"packets lost average: {mean(loss[col]):.1f}) "
515 f"{u'-'.join(tst_name.split(u'-')[2:])}"
521 layout = deepcopy(plot[u"layout"])
522 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
523 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
524 layout[u"legend"][u"font"][u"size"] = 14
525 layout[u"yaxis"].pop(u"range")
526 plpl = plgo.Figure(data=traces, layout=layout)
529 file_name = f"{plot[u'output-file'].format(core=core)}.html"
530 logging.info(f" Writing file {file_name}")
537 except PlotlyError as err:
539 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
543 def plot_perf_box_name(plot, input_data):
544 """Generate the plot(s) with algorithm: plot_perf_box_name
545 specified in the specification file.
547 Use only for soak and hoststack tests.
549 :param plot: Plot to generate.
550 :param input_data: Data to process.
551 :type plot: pandas.Series
552 :type input_data: InputData
557 f" Creating data set for the {plot.get(u'type', u'')} "
558 f"{plot.get(u'title', u'')}."
560 data = input_data.filter_tests_by_name(
562 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
564 logging.error(u"No data.")
567 # Prepare the data for the plot
568 y_vals = OrderedDict()
571 for item in plot.get(u"include", tuple()):
572 reg_ex = re.compile(str(item).lower())
575 for test_id, test in build.iteritems():
576 if not re.match(reg_ex, str(test_id).lower()):
578 if y_vals.get(test[u"parent"], None) is None:
579 y_vals[test[u"parent"]] = list()
581 if test[u"type"] in (u"SOAK",):
582 y_vals[test[u"parent"]]. \
583 append(test[u"throughput"][u"LOWER"])
586 elif test[u"type"] in (u"HOSTSTACK",):
587 if u"LDPRELOAD" in test[u"tags"]:
588 y_vals[test[u"parent"]].append(
590 test[u"result"][u"bits_per_second"]
593 elif u"VPPECHO" in test[u"tags"]:
594 y_vals[test[u"parent"]].append(
596 test[u"result"][u"client"][u"tx_data"]
599 test[u"result"][u"client"][u"time"]
602 test[u"result"][u"server"][u"time"])
605 test_type = u"HOSTSTACK"
610 except (KeyError, TypeError):
611 y_vals[test[u"parent"]].append(None)
613 # Add None to the lists with missing data
615 nr_of_samples = list()
616 for val in y_vals.values():
617 if len(val) > max_len:
619 nr_of_samples.append(len(val))
620 for val in y_vals.values():
621 if len(val) < max_len:
622 val.extend([None for _ in range(max_len - len(val))])
626 df_y = pd.DataFrame(y_vals)
629 for i, col in enumerate(df_y.columns):
630 tst_name = re.sub(REGEX_NIC, u"",
631 col.lower().replace(u'-ndrpdr', u'').
632 replace(u'2n1l-', u''))
634 x=[str(i + 1) + u'.'] * len(df_y[col]),
635 y=[y / 1e6 if y else None for y in df_y[col]],
638 f"({nr_of_samples[i]:02d} "
639 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
644 if test_type in (u"SOAK", ):
645 kwargs[u"boxpoints"] = u"all"
647 traces.append(plgo.Box(**kwargs))
650 val_max = max(df_y[col])
652 y_max.append(int(val_max / 1e6) + 2)
653 except (ValueError, TypeError) as err:
654 logging.error(repr(err))
659 layout = deepcopy(plot[u"layout"])
660 if layout.get(u"title", None):
661 if test_type in (u"HOSTSTACK", ):
662 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
664 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
666 layout[u"yaxis"][u"range"] = [0, max(y_max)]
667 plpl = plgo.Figure(data=traces, layout=layout)
670 logging.info(f" Writing file {plot[u'output-file']}.html.")
675 filename=f"{plot[u'output-file']}.html"
677 except PlotlyError as err:
679 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
684 def plot_ndrpdr_box_name(plot, input_data):
685 """Generate the plot(s) with algorithm: plot_ndrpdr_box_name
686 specified in the specification file.
688 :param plot: Plot to generate.
689 :param input_data: Data to process.
690 :type plot: pandas.Series
691 :type input_data: InputData
696 f" Creating data set for the {plot.get(u'type', u'')} "
697 f"{plot.get(u'title', u'')}."
699 data = input_data.filter_tests_by_name(
701 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
704 logging.error(u"No data.")
707 if u"-gbps" in plot.get(u"title", u"").lower():
711 value = u"throughput"
716 for ttype in plot.get(u"test-type", (u"ndr", u"pdr")):
717 for core in plot.get(u"core", tuple()):
718 # Prepare the data for the plot
720 data_y = OrderedDict()
723 for item in plot.get(u"include", tuple()):
724 reg_ex = re.compile(str(item.format(core=core)).lower())
727 for test_id, test in build.iteritems():
728 if not re.match(reg_ex, str(test_id).lower()):
730 if data_y.get(test[u"parent"], None) is None:
731 data_y[test[u"parent"]] = list()
732 test_type = test[u"type"]
736 data_y[test[u"parent"]].append(
737 test[value][ttype.upper()][u"LOWER"] *
740 except (KeyError, TypeError):
745 for idx, (key, vals) in enumerate(data_y.items()):
747 REGEX_NIC, u'', key.lower().replace(u'-ndrpdr', u'').
748 replace(u'2n1l-', u'')
752 x=[data_x[idx], ] * len(data_x),
753 y=[y / 1e6 if y else None for y in vals],
758 f"{u's' if len(vals) > 1 else u''}) "
765 data_y_max.append(max(vals))
766 except ValueError as err:
767 logging.warning(f"No values to use.\n{err!r}")
770 layout = deepcopy(plot[u"layout"])
771 if layout.get(u"title", None):
773 layout[u'title'].format(core=core, test_type=ttype)
774 if test_type in (u"CPS", ):
775 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
778 f"<b>Throughput:</b> {layout[u'title']}"
780 layout[u"yaxis"][u"range"] = [0, max(data_y_max) / 1e6 + 1]
781 plpl = plgo.Figure(data=traces, layout=layout)
785 f"{plot[u'output-file'].format(core=core, test_type=ttype)}"
788 logging.info(f" Writing file {file_name}")
795 except PlotlyError as err:
797 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
801 def plot_mrr_box_name(plot, input_data):
802 """Generate the plot(s) with algorithm: plot_mrr_box_name
803 specified in the specification file.
805 :param plot: Plot to generate.
806 :param input_data: Data to process.
807 :type plot: pandas.Series
808 :type input_data: InputData
813 f" Creating data set for the {plot.get(u'type', u'')} "
814 f"{plot.get(u'title', u'')}."
816 data = input_data.filter_tests_by_name(
818 params=[u"result", u"parent", u"tags", u"type"]
821 logging.error(u"No data.")
824 for core in plot.get(u"core", tuple()):
825 # Prepare the data for the plot
831 for item in plot.get(u"include", tuple()):
832 reg_ex = re.compile(str(item.format(core=core)).lower())
835 for test_id, test in build.iteritems():
836 if not re.match(reg_ex, str(test_id).lower()):
841 REGEX_NIC, u'', test[u'parent'].lower().
842 replace(u'-mrr', u'').replace(u'2n1l-', u'')
844 data_y.append(test[u"result"][u"samples"])
847 f"({len(data_y[-1]):02d} "
848 f"run{u's' if len(data_y[-1]) > 1 else u''}) "
851 data_y_max.append(max(data_y[-1]))
853 except (KeyError, TypeError):
858 for idx in range(len(data_x)):
861 x=[data_x[idx], ] * len(data_y[idx]),
863 name=data_names[idx],
870 layout = deepcopy(plot[u"layout"])
871 if layout.get(u"title", None):
873 f"<b>Throughput:</b> {layout[u'title'].format(core=core)}"
876 layout[u"yaxis"][u"range"] = [0, max(data_y_max) + 1]
877 plpl = plgo.Figure(data=traces, layout=layout)
880 file_name = f"{plot[u'output-file'].format(core=core)}.html"
881 logging.info(f" Writing file {file_name}")
888 except PlotlyError as err:
890 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
894 def plot_tsa_name(plot, input_data):
895 """Generate the plot(s) with algorithm:
897 specified in the specification file.
899 :param plot: Plot to generate.
900 :param input_data: Data to process.
901 :type plot: pandas.Series
902 :type input_data: InputData
906 plot_title = plot.get(u"title", u"")
908 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
910 data = input_data.filter_tests_by_name(
912 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
915 logging.error(u"No data.")
918 plot_title = plot_title.lower()
920 if u"-gbps" in plot_title:
925 value = u"throughput"
929 for ttype in plot.get(u"test-type", (u"ndr", u"pdr")):
930 y_vals = OrderedDict()
931 for item in plot.get(u"include", tuple()):
932 reg_ex = re.compile(str(item).lower())
935 for test_id, test in build.iteritems():
936 if re.match(reg_ex, str(test_id).lower()):
937 if y_vals.get(test[u"parent"], None) is None:
938 y_vals[test[u"parent"]] = {
944 if test[u"type"] not in (u"NDRPDR", u"CPS"):
947 if u"1C" in test[u"tags"]:
948 y_vals[test[u"parent"]][u"1"].append(
949 test[value][ttype.upper()][u"LOWER"] *
952 elif u"2C" in test[u"tags"]:
953 y_vals[test[u"parent"]][u"2"].append(
954 test[value][ttype.upper()][u"LOWER"] *
957 elif u"4C" in test[u"tags"]:
958 y_vals[test[u"parent"]][u"4"].append(
959 test[value][ttype.upper()][u"LOWER"] *
962 except (KeyError, TypeError):
966 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
970 for test_name, test_vals in y_vals.items():
971 for key, test_val in test_vals.items():
973 avg_val = sum(test_val) / len(test_val)
974 y_vals[test_name][key] = [avg_val, len(test_val)]
975 ideal = avg_val / (int(key) * 1e6)
976 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
977 y_1c_max[test_name] = ideal
984 for test_name, test_vals in y_vals.items():
986 if test_vals[u"1"][1]:
990 test_name.replace(u'-ndrpdr', u'').
991 replace(u'2n1l-', u'')
993 vals[name] = OrderedDict()
994 y_val_1 = test_vals[u"1"][0] / 1e6
995 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
997 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
1000 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
1001 vals[name][u"rel"] = [1.0, None, None]
1002 vals[name][u"ideal"] = [
1003 y_1c_max[test_name],
1004 y_1c_max[test_name] * 2,
1005 y_1c_max[test_name] * 4
1007 vals[name][u"diff"] = [
1008 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1,
1012 vals[name][u"count"] = [
1019 val_max = max(vals[name][u"val"])
1020 except ValueError as err:
1021 logging.error(repr(err))
1024 y_max.append(val_max)
1027 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
1028 vals[name][u"diff"][1] = \
1029 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
1031 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
1032 vals[name][u"diff"][2] = \
1033 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
1034 except IndexError as err:
1035 logging.warning(f"No data for {test_name}")
1036 logging.warning(repr(err))
1039 if u"x520" in test_name:
1040 limit = plot[u"limits"][u"nic"][u"x520"]
1041 elif u"x710" in test_name:
1042 limit = plot[u"limits"][u"nic"][u"x710"]
1043 elif u"xxv710" in test_name:
1044 limit = plot[u"limits"][u"nic"][u"xxv710"]
1045 elif u"xl710" in test_name:
1046 limit = plot[u"limits"][u"nic"][u"xl710"]
1047 elif u"x553" in test_name:
1048 limit = plot[u"limits"][u"nic"][u"x553"]
1049 elif u"cx556a" in test_name:
1050 limit = plot[u"limits"][u"nic"][u"cx556a"]
1051 elif u"e810cq" in test_name:
1052 limit = plot[u"limits"][u"nic"][u"e810cq"]
1055 if limit > nic_limit:
1058 mul = 2 if u"ge2p" in test_name else 1
1059 if u"10ge" in test_name:
1060 limit = plot[u"limits"][u"link"][u"10ge"] * mul
1061 elif u"25ge" in test_name:
1062 limit = plot[u"limits"][u"link"][u"25ge"] * mul
1063 elif u"40ge" in test_name:
1064 limit = plot[u"limits"][u"link"][u"40ge"] * mul
1065 elif u"100ge" in test_name:
1066 limit = plot[u"limits"][u"link"][u"100ge"] * mul
1069 if limit > lnk_limit:
1072 if u"cx556a" in test_name:
1073 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
1075 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
1076 if limit > pci_limit:
1080 annotations = list()
1084 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
1088 min_limit = min((nic_limit, lnk_limit, pci_limit))
1089 if nic_limit == min_limit:
1090 traces.append(plgo.Scatter(
1092 y=[nic_limit, ] * len(x_vals),
1093 name=f"NIC: {nic_limit:.2f}Mpps",
1102 annotations.append(dict(
1109 text=f"NIC: {nic_limit:.2f}Mpps",
1117 y_max.append(nic_limit)
1118 elif lnk_limit == min_limit:
1119 traces.append(plgo.Scatter(
1121 y=[lnk_limit, ] * len(x_vals),
1122 name=f"Link: {lnk_limit:.2f}Mpps",
1131 annotations.append(dict(
1138 text=f"Link: {lnk_limit:.2f}Mpps",
1146 y_max.append(lnk_limit)
1147 elif pci_limit == min_limit:
1148 traces.append(plgo.Scatter(
1150 y=[pci_limit, ] * len(x_vals),
1151 name=f"PCIe: {pci_limit:.2f}Mpps",
1160 annotations.append(dict(
1167 text=f"PCIe: {pci_limit:.2f}Mpps",
1175 y_max.append(pci_limit)
1177 # Perfect and measured:
1179 for name, val in vals.items():
1182 for idx in range(len(val[u"val"])):
1184 if isinstance(val[u"val"][idx], float):
1186 f"No. of Runs: {val[u'count'][idx]}<br>"
1187 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
1189 if isinstance(val[u"diff"][idx], float):
1190 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
1191 if isinstance(val[u"rel"][idx], float):
1192 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
1193 hovertext.append(htext)
1200 mode=u"lines+markers",
1209 hoverinfo=u"text+name"
1216 name=f"{name} perfect",
1224 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1229 except (IndexError, ValueError, KeyError) as err:
1230 logging.warning(f"No data for {name}\n{repr(err)}")
1234 file_name = f"{plot[u'output-file'].format(test_type=ttype)}.html"
1235 logging.info(f" Writing file {file_name}")
1236 layout = deepcopy(plot[u"layout"])
1237 if layout.get(u"title", None):
1238 layout[u"title"] = (
1239 f"<b>Speedup Multi-core:</b> "
1240 f"{layout[u'title'].format(test_type=ttype)}"
1242 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1243 layout[u"annotations"].extend(annotations)
1244 plpl = plgo.Figure(data=traces, layout=layout)
1253 except PlotlyError as err:
1255 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1259 def plot_http_server_perf_box(plot, input_data):
1260 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1261 specified in the specification file.
1263 :param plot: Plot to generate.
1264 :param input_data: Data to process.
1265 :type plot: pandas.Series
1266 :type input_data: InputData
1269 # Transform the data
1271 f" Creating the data set for the {plot.get(u'type', u'')} "
1272 f"{plot.get(u'title', u'')}."
1274 data = input_data.filter_data(plot)
1276 logging.error(u"No data.")
1279 # Prepare the data for the plot
1284 if y_vals.get(test[u"name"], None) is None:
1285 y_vals[test[u"name"]] = list()
1287 y_vals[test[u"name"]].append(test[u"result"])
1288 except (KeyError, TypeError):
1289 y_vals[test[u"name"]].append(None)
1291 # Add None to the lists with missing data
1293 nr_of_samples = list()
1294 for val in y_vals.values():
1295 if len(val) > max_len:
1297 nr_of_samples.append(len(val))
1298 for val in y_vals.values():
1299 if len(val) < max_len:
1300 val.extend([None for _ in range(max_len - len(val))])
1304 df_y = pd.DataFrame(y_vals)
1306 for i, col in enumerate(df_y.columns):
1309 f"({nr_of_samples[i]:02d} " \
1310 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1311 f"{col.lower().replace(u'-ndrpdr', u'')}"
1313 name_lst = name.split(u'-')
1316 for segment in name_lst:
1317 if (len(name) + len(segment) + 1) > 50 and split_name:
1320 name += segment + u'-'
1323 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1329 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1333 f" Writing file {plot[u'output-file']}"
1334 f"{plot[u'output-file-type']}."
1340 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1342 except PlotlyError as err:
1344 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1349 def plot_nf_heatmap(plot, input_data):
1350 """Generate the plot(s) with algorithm: plot_nf_heatmap
1351 specified in the specification file.
1353 :param plot: Plot to generate.
1354 :param input_data: Data to process.
1355 :type plot: pandas.Series
1356 :type input_data: InputData
1359 def sort_by_int(value):
1360 """Makes possible to sort a list of strings which represent integers.
1362 :param value: Integer as a string.
1364 :returns: Integer representation of input parameter 'value'.
1369 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1370 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1372 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
1375 # Transform the data
1377 f" Creating the data set for the {plot.get(u'type', u'')} "
1378 f"{plot.get(u'title', u'')}."
1380 in_data = input_data.filter_tests_by_name(
1382 continue_on_error=True,
1383 params=[u"throughput", u"result", u"name", u"tags", u"type"]
1385 if in_data is None or in_data.empty:
1386 logging.error(u"No data.")
1389 for ttype in plot.get(u"test-type", (u"ndr", u"pdr")):
1390 for core in plot.get(u"core", tuple()):
1391 for item in plot.get(u"include", tuple()):
1392 reg_ex = re.compile(str(item.format(core=core)).lower())
1395 for test_id, test in build.iteritems():
1396 if not re.match(reg_ex, str(test_id).lower()):
1398 for tag in test[u"tags"]:
1399 groups = re.search(regex_cn, tag)
1401 chain = str(groups.group(1))
1402 node = str(groups.group(2))
1406 groups = re.search(regex_test_name, test[u"name"])
1407 if groups and len(groups.groups()) == 3:
1409 f"{str(groups.group(1))}-"
1410 f"{str(groups.group(2))}-"
1411 f"{str(groups.group(3))}"
1415 if vals.get(chain, None) is None:
1416 vals[chain] = dict()
1417 if vals[chain].get(node, None) is None:
1418 vals[chain][node] = dict(
1427 result = test[u"result"][u"receive-rate"]
1428 elif ttype == u"pdr":
1430 test[u"throughput"][u"PDR"][u"LOWER"]
1431 elif ttype == u"ndr":
1433 test[u"throughput"][u"NDR"][u"LOWER"]
1440 vals[chain][node][u"vals"].append(result)
1443 logging.error(u"No data.")
1449 txt_chains.append(key_c)
1450 for key_n in vals[key_c].keys():
1451 txt_nodes.append(key_n)
1452 if vals[key_c][key_n][u"vals"]:
1453 vals[key_c][key_n][u"nr"] = \
1454 len(vals[key_c][key_n][u"vals"])
1455 vals[key_c][key_n][u"mean"] = \
1456 round(mean(vals[key_c][key_n][u"vals"]) / 1e6, 1)
1457 vals[key_c][key_n][u"stdev"] = \
1458 round(stdev(vals[key_c][key_n][u"vals"]) / 1e6, 1)
1459 txt_nodes = list(set(txt_nodes))
1461 txt_chains = sorted(txt_chains, key=sort_by_int)
1462 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1464 chains = [i + 1 for i in range(len(txt_chains))]
1465 nodes = [i + 1 for i in range(len(txt_nodes))]
1467 data = [list() for _ in range(len(chains))]
1468 for chain in chains:
1471 val = vals[txt_chains[chain - 1]] \
1472 [txt_nodes[node - 1]][u"mean"]
1473 except (KeyError, IndexError):
1475 data[chain - 1].append(val)
1478 my_green = [[0.0, u"rgb(235, 249, 242)"],
1479 [1.0, u"rgb(45, 134, 89)"]]
1481 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1482 [1.0, u"rgb(57, 115, 172)"]]
1484 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1485 [1.0, u"rgb(102, 102, 102)"]]
1488 annotations = list()
1490 text = (u"Test: {name}<br>"
1495 for chain, _ in enumerate(txt_chains):
1497 for node, _ in enumerate(txt_nodes):
1498 if data[chain][node] is not None:
1507 text=str(data[chain][node]),
1515 hover_line.append(text.format(
1516 name=vals[txt_chains[chain]][txt_nodes[node]]
1518 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1519 val=data[chain][node],
1520 stdev=vals[txt_chains[chain]][txt_nodes[node]]
1523 hovertext.append(hover_line)
1531 title=plot.get(u"z-axis", u"{test_type}").
1532 format(test_type=ttype.upper()),
1546 colorscale=my_green,
1552 for idx, item in enumerate(txt_nodes):
1570 for idx, item in enumerate(txt_chains):
1597 text=plot.get(u"x-axis", u""),
1614 text=plot.get(u"y-axis", u""),
1623 updatemenus = list([
1634 u"colorscale": [my_green, ],
1635 u"reversescale": False
1644 u"colorscale": [my_blue, ],
1645 u"reversescale": False
1654 u"colorscale": [my_grey, ],
1655 u"reversescale": False
1666 layout = deepcopy(plot[u"layout"])
1667 except KeyError as err:
1669 f"Finished with error: No layout defined\n{repr(err)}"
1673 layout[u"annotations"] = annotations
1674 layout[u'updatemenus'] = updatemenus
1675 if layout.get(u"title", None):
1676 layout[u"title"] = layout[u'title'].replace(u"test_type", ttype)
1680 plpl = plgo.Figure(data=traces, layout=layout)
1684 f"{plot[u'output-file'].format(core=core, test_type=ttype)}"
1687 logging.info(f" Writing file {file_name}")
1694 except PlotlyError as err:
1696 f" Finished with error: {repr(err)}".replace(u"\n", u" ")