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.
21 from collections import OrderedDict
22 from copy import deepcopy
28 import plotly.offline as ploff
29 import plotly.graph_objs as plgo
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>"
204 f"{previous_x:.5f}-{percentile:.5f}%<br>"
205 f"Latency: {item.value_iterated_to}uSec"
207 xaxis.append(percentile)
208 yaxis.append(item.value_iterated_to)
210 f"<b>{desc[graph]}</b><br>"
211 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
213 f"{previous_x:.5f}-{percentile:.5f}%<br>"
214 f"Latency: {item.value_iterated_to}uSec"
216 previous_x = percentile
223 legendgroup=desc[graph],
224 showlegend=bool(idx),
228 width=1 if idx % 2 else 2
235 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
236 fig.update_layout(layout)
239 file_name = f"{plot[u'output-file']}-{name_link}.html"
240 logging.info(f" Writing file {file_name}")
244 ploff.plot(fig, show_link=False, auto_open=False,
246 # Add link to the file:
247 if file_links and target_links:
248 with open(file_links, u"a") as file_handler:
251 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
253 except FileNotFoundError as err:
255 f"Not possible to write the link to the file "
256 f"{file_links}\n{err}"
258 except PlotlyError as err:
259 logging.error(f" Finished with error: {repr(err)}")
261 except hdrh.codec.HdrLengthException as err:
262 logging.warning(repr(err))
265 except (ValueError, KeyError) as err:
266 logging.warning(repr(err))
270 def plot_hdrh_lat_by_percentile_x_log(plot, input_data):
271 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile_x_log
272 specified in the specification file.
274 :param plot: Plot to generate.
275 :param input_data: Data to process.
276 :type plot: pandas.Series
277 :type input_data: InputData
282 f" Creating the data set for the {plot.get(u'type', u'')} "
283 f"{plot.get(u'title', u'')}."
285 if plot.get(u"include", None):
286 data = input_data.filter_tests_by_name(
288 params=[u"name", u"latency", u"parent", u"tags", u"type"]
290 elif plot.get(u"filter", None):
291 data = input_data.filter_data(
293 params=[u"name", u"latency", u"parent", u"tags", u"type"],
294 continue_on_error=True
297 job = list(plot[u"data"].keys())[0]
298 build = str(plot[u"data"][job][0])
299 data = input_data.tests(job, build)
301 if data is None or len(data) == 0:
302 logging.error(u"No data.")
306 u"LAT0": u"No-load.",
307 u"PDR10": u"Low-load, 10% PDR.",
308 u"PDR50": u"Mid-load, 50% PDR.",
309 u"PDR90": u"High-load, 90% PDR.",
310 u"PDR": u"Full-load, 100% PDR.",
311 u"NDR10": u"Low-load, 10% NDR.",
312 u"NDR50": u"Mid-load, 50% NDR.",
313 u"NDR90": u"High-load, 90% NDR.",
314 u"NDR": u"Full-load, 100% NDR."
324 file_links = plot.get(u"output-file-links", None)
325 target_links = plot.get(u"target-links", None)
329 if test[u"type"] not in (u"NDRPDR",):
330 logging.warning(f"Invalid test type: {test[u'type']}")
332 name = re.sub(REGEX_NIC, u"", test[u"parent"].
333 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
335 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
336 except (IndexError, AttributeError, KeyError, ValueError):
338 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
340 logging.info(f" Generating the graph: {name_link}")
343 layout = deepcopy(plot[u"layout"])
345 for color, graph in enumerate(graphs):
346 for idx, direction in enumerate((u"direction1", u"direction2")):
353 decoded = hdrh.histogram.HdrHistogram.decode(
354 test[u"latency"][graph][direction][u"hdrh"]
356 except (hdrh.codec.HdrLengthException, TypeError):
358 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
362 for item in decoded.get_recorded_iterator():
363 # The real value is "percentile".
364 # For 100%, we cut that down to "x_perc" to avoid
366 percentile = item.percentile_level_iterated_to
367 x_perc = min(percentile, PERCENTILE_MAX)
368 xaxis.append(previous_x)
369 yaxis.append(item.value_iterated_to)
371 f"<b>{desc[graph]}</b><br>"
372 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
373 f"Percentile: {prev_perc:.5f}-{percentile:.5f}%<br>"
374 f"Latency: {item.value_iterated_to}uSec"
376 next_x = 100.0 / (100.0 - x_perc)
378 yaxis.append(item.value_iterated_to)
380 f"<b>{desc[graph]}</b><br>"
381 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
382 f"Percentile: {prev_perc:.5f}-{percentile:.5f}%<br>"
383 f"Latency: {item.value_iterated_to}uSec"
386 prev_perc = percentile
393 legendgroup=desc[graph],
394 showlegend=not(bool(idx)),
398 width=1 if idx % 2 else 2
405 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
406 x_max = log(100.0 / (100.0 - PERCENTILE_MAX), 10)
407 layout[u"xaxis"][u"range"] = [0, x_max]
408 fig.update_layout(layout)
411 file_name = f"{plot[u'output-file']}-{name_link}.html"
412 logging.info(f" Writing file {file_name}")
416 ploff.plot(fig, show_link=False, auto_open=False,
418 # Add link to the file:
419 if file_links and target_links:
420 with open(file_links, u"a") as file_handler:
423 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
425 except FileNotFoundError as err:
427 f"Not possible to write the link to the file "
428 f"{file_links}\n{err}"
430 except PlotlyError as err:
431 logging.error(f" Finished with error: {repr(err)}")
433 except hdrh.codec.HdrLengthException as err:
434 logging.warning(repr(err))
437 except (ValueError, KeyError) as err:
438 logging.warning(repr(err))
442 def plot_nf_reconf_box_name(plot, input_data):
443 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
444 specified in the specification file.
446 :param plot: Plot to generate.
447 :param input_data: Data to process.
448 :type plot: pandas.Series
449 :type input_data: InputData
454 f" Creating the data set for the {plot.get(u'type', u'')} "
455 f"{plot.get(u'title', u'')}."
457 data = input_data.filter_tests_by_name(
458 plot, params=[u"result", u"parent", u"tags", u"type"]
461 logging.error(u"No data.")
464 for core in plot.get(u"core", tuple()):
465 # Prepare the data for the plot
466 y_vals = OrderedDict()
468 for item in plot.get(u"include", tuple()):
469 reg_ex = re.compile(str(item.format(core=core)).lower())
472 for test_id, test in build.iteritems():
473 if not re.match(reg_ex, str(test_id).lower()):
475 if y_vals.get(test[u"parent"], None) is None:
476 y_vals[test[u"parent"]] = list()
477 loss[test[u"parent"]] = list()
479 y_vals[test[u"parent"]].append(
480 test[u"result"][u"time"]
482 loss[test[u"parent"]].append(
483 test[u"result"][u"loss"]
485 except (KeyError, TypeError):
486 y_vals[test[u"parent"]].append(None)
488 # Add None to the lists with missing data
490 nr_of_samples = list()
491 for val in y_vals.values():
492 if len(val) > max_len:
494 nr_of_samples.append(len(val))
495 for val in y_vals.values():
496 if len(val) < max_len:
497 val.extend([None for _ in range(max_len - len(val))])
501 df_y = pd.DataFrame(y_vals)
503 for i, col in enumerate(df_y.columns):
506 col.lower().replace(u'-reconf', u'').replace(u'2n1l-', u'').
507 replace(u'2n-', u'').replace(u'-testpmd', u'')
509 traces.append(plgo.Box(
510 x=[str(i + 1) + u'.'] * len(df_y[col]),
514 f"({nr_of_samples[i]:02d} "
515 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
516 f"packets lost average: {mean(loss[col]):.1f}) "
517 f"{u'-'.join(tst_name.split(u'-')[2:])}"
523 layout = deepcopy(plot[u"layout"])
524 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
525 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
526 layout[u"legend"][u"font"][u"size"] = 14
527 layout[u"yaxis"].pop(u"range")
528 plpl = plgo.Figure(data=traces, layout=layout)
531 file_name = f"{plot[u'output-file'].format(core=core)}.html"
532 logging.info(f" Writing file {file_name}")
539 except PlotlyError as err:
541 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
545 def plot_perf_box_name(plot, input_data):
546 """Generate the plot(s) with algorithm: plot_perf_box_name
547 specified in the specification file.
549 Use only for soak and hoststack tests.
551 :param plot: Plot to generate.
552 :param input_data: Data to process.
553 :type plot: pandas.Series
554 :type input_data: InputData
559 f" Creating data set for the {plot.get(u'type', u'')} "
560 f"{plot.get(u'title', u'')}."
562 data = input_data.filter_tests_by_name(
564 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
566 logging.error(u"No data.")
569 # Prepare the data for the plot
570 y_vals = OrderedDict()
573 for item in plot.get(u"include", tuple()):
574 reg_ex = re.compile(str(item).lower())
577 for test_id, test in build.iteritems():
578 if not re.match(reg_ex, str(test_id).lower()):
580 if y_vals.get(test[u"parent"], None) is None:
581 y_vals[test[u"parent"]] = list()
583 if test[u"type"] in (u"SOAK",):
584 y_vals[test[u"parent"]]. \
585 append(test[u"throughput"][u"LOWER"])
588 elif test[u"type"] in (u"HOSTSTACK",):
589 if u"LDPRELOAD" in test[u"tags"]:
590 y_vals[test[u"parent"]].append(
592 test[u"result"][u"bits_per_second"]
595 elif u"VPPECHO" in test[u"tags"]:
596 y_vals[test[u"parent"]].append(
598 test[u"result"][u"client"][u"tx_data"]
601 test[u"result"][u"client"][u"time"]
604 test[u"result"][u"server"][u"time"])
607 test_type = u"HOSTSTACK"
609 elif test[u"type"] in (u"LDP_NGINX",):
610 if u"TCP_CPS" in test[u"tags"]:
611 test_type = u"VSAP_CPS"
612 y_vals[test[u"parent"]].append(
613 test[u"result"][u"cps"]
615 elif u"TCP_RPS" in test[u"tags"]:
616 test_type = u"VSAP_RPS"
617 y_vals[test[u"parent"]].append(
618 test[u"result"][u"rps"]
625 except (KeyError, TypeError):
626 y_vals[test[u"parent"]].append(None)
628 # Add None to the lists with missing data
630 nr_of_samples = list()
631 for val in y_vals.values():
632 if len(val) > max_len:
634 nr_of_samples.append(len(val))
635 for val in y_vals.values():
636 if len(val) < max_len:
637 val.extend([None for _ in range(max_len - len(val))])
641 df_y = pd.DataFrame(y_vals)
644 for i, col in enumerate(df_y.columns):
645 tst_name = re.sub(REGEX_NIC, u"",
646 col.lower().replace(u'-ndrpdr', u'').
647 replace(u'2n1l-', u''))
648 if test_type in (u"VSAP_CPS", u"VSAP_RPS"):
649 data_y = [y if y else None for y in df_y[col]]
651 data_y = [y / 1e6 if y else None for y in df_y[col]]
653 x=[str(i + 1) + u'.'] * len(df_y[col]),
657 f"({nr_of_samples[i]:02d} "
658 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
663 if test_type in (u"SOAK", ):
664 kwargs[u"boxpoints"] = u"all"
666 traces.append(plgo.Box(**kwargs))
669 val_max = max(df_y[col])
671 y_max.append(int(val_max / 1e6))
672 except (ValueError, TypeError) as err:
673 logging.error(repr(err))
678 layout = deepcopy(plot[u"layout"])
679 if layout.get(u"title", None):
680 if test_type in (u"HOSTSTACK", ):
681 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
682 elif test_type == u"VSAP_CPS":
683 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
684 layout[u"yaxis"][u"title"] = u"<b>Connection Rate [cps]</b>"
685 elif test_type == u"VSAP_RPS":
686 layout[u"title"] = f"<b>RPS:</b> {layout[u'title']}"
687 layout[u"yaxis"][u"title"] = u"<b>Connection Rate [rps]</b>"
689 layout[u"title"] = f"<b>Tput:</b> {layout[u'title']}"
690 if y_max and max(y_max) > 1:
691 layout[u"yaxis"][u"range"] = [0, max(y_max) + 2]
692 plpl = plgo.Figure(data=traces, layout=layout)
695 logging.info(f" Writing file {plot[u'output-file']}.html.")
700 filename=f"{plot[u'output-file']}.html"
702 except PlotlyError as err:
704 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
709 def plot_ndrpdr_box_name(plot, input_data):
710 """Generate the plot(s) with algorithm: plot_ndrpdr_box_name
711 specified in the specification file.
713 :param plot: Plot to generate.
714 :param input_data: Data to process.
715 :type plot: pandas.Series
716 :type input_data: InputData
721 f" Creating data set for the {plot.get(u'type', u'')} "
722 f"{plot.get(u'title', u'')}."
724 data = input_data.filter_tests_by_name(
726 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
729 logging.error(u"No data.")
732 if u"-gbps" in plot.get(u"title", u"").lower():
736 value = u"throughput"
741 for ttype in plot.get(u"test-type", (u"ndr", u"pdr")):
742 for core in plot.get(u"core", tuple()):
743 # Prepare the data for the plot
745 data_y = OrderedDict()
748 for item in plot.get(u"include", tuple()):
749 reg_ex = re.compile(str(item.format(core=core)).lower())
752 for test_id, test in build.iteritems():
753 if not re.match(reg_ex, str(test_id).lower()):
755 if data_y.get(test[u"parent"], None) is None:
756 data_y[test[u"parent"]] = list()
757 test_type = test[u"type"]
761 data_y[test[u"parent"]].append(
762 test[value][ttype.upper()][u"LOWER"] *
765 except (KeyError, TypeError):
770 for idx, (key, vals) in enumerate(data_y.items()):
772 REGEX_NIC, u'', key.lower().replace(u'-ndrpdr', u'').
773 replace(u'2n1l-', u'')
777 x=[data_x[idx], ] * len(data_x),
778 y=[y / 1e6 if y else None for y in vals],
783 f"{u's' if len(vals) > 1 else u''}) "
790 data_y_max.append(max(vals))
791 except ValueError as err:
792 logging.warning(f"No values to use.\n{err!r}")
795 layout = deepcopy(plot[u"layout"])
796 if layout.get(u"title", None):
798 layout[u'title'].format(core=core, test_type=ttype)
799 if test_type in (u"CPS", ):
800 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
803 f"<b>Tput:</b> {layout[u'title']}"
805 layout[u"yaxis"][u"range"] = [0, max(data_y_max) / 1e6 + 1]
806 plpl = plgo.Figure(data=traces, layout=layout)
810 f"{plot[u'output-file'].format(core=core, test_type=ttype)}"
813 logging.info(f" Writing file {file_name}")
820 except PlotlyError as err:
822 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
826 def plot_mrr_box_name(plot, input_data):
827 """Generate the plot(s) with algorithm: plot_mrr_box_name
828 specified in the specification file.
830 :param plot: Plot to generate.
831 :param input_data: Data to process.
832 :type plot: pandas.Series
833 :type input_data: InputData
838 f" Creating data set for the {plot.get(u'type', u'')} "
839 f"{plot.get(u'title', u'')}."
841 data = input_data.filter_tests_by_name(
843 params=[u"result", u"parent", u"tags", u"type"]
846 logging.error(u"No data.")
849 for core in plot.get(u"core", tuple()):
850 # Prepare the data for the plot
856 for item in plot.get(u"include", tuple()):
857 reg_ex = re.compile(str(item.format(core=core)).lower())
860 for test_id, test in build.iteritems():
861 if not re.match(reg_ex, str(test_id).lower()):
866 REGEX_NIC, u'', test[u'parent'].lower().
867 replace(u'-mrr', u'').replace(u'2n1l-', u'')
869 data_y.append(test[u"result"][u"samples"])
872 f"({len(data_y[-1]):02d} "
873 f"run{u's' if len(data_y[-1]) > 1 else u''}) "
876 data_y_max.append(max(data_y[-1]))
878 except (KeyError, TypeError):
883 for idx, x_item in enumerate(data_x):
886 x=[x_item, ] * len(data_y[idx]),
888 name=data_names[idx],
895 layout = deepcopy(plot[u"layout"])
896 if layout.get(u"title", None):
898 f"<b>Tput:</b> {layout[u'title'].format(core=core)}"
901 layout[u"yaxis"][u"range"] = [0, max(data_y_max) + 1]
902 plpl = plgo.Figure(data=traces, layout=layout)
905 file_name = f"{plot[u'output-file'].format(core=core)}.html"
906 logging.info(f" Writing file {file_name}")
913 except PlotlyError as err:
915 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
919 def plot_tsa_name(plot, input_data):
920 """Generate the plot(s) with algorithm:
922 specified in the specification file.
924 :param plot: Plot to generate.
925 :param input_data: Data to process.
926 :type plot: pandas.Series
927 :type input_data: InputData
931 plot_title = plot.get(u"title", u"")
933 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
935 data = input_data.filter_tests_by_name(
937 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
940 logging.error(u"No data.")
943 plot_title = plot_title.lower()
945 if u"-gbps" in plot_title:
950 value = u"throughput"
954 for ttype in plot.get(u"test-type", (u"ndr", u"pdr")):
955 y_vals = OrderedDict()
956 for item in plot.get(u"include", tuple()):
957 reg_ex = re.compile(str(item).lower())
960 for test_id, test in build.iteritems():
961 if re.match(reg_ex, str(test_id).lower()):
962 if y_vals.get(test[u"parent"], None) is None:
963 y_vals[test[u"parent"]] = {
969 if test[u"type"] not in (u"NDRPDR", u"CPS"):
972 if u"1C" in test[u"tags"]:
973 y_vals[test[u"parent"]][u"1"].append(
974 test[value][ttype.upper()][u"LOWER"] *
977 elif u"2C" in test[u"tags"]:
978 y_vals[test[u"parent"]][u"2"].append(
979 test[value][ttype.upper()][u"LOWER"] *
982 elif u"4C" in test[u"tags"]:
983 y_vals[test[u"parent"]][u"4"].append(
984 test[value][ttype.upper()][u"LOWER"] *
987 except (KeyError, TypeError):
991 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
995 for test_name, test_vals in y_vals.items():
996 for key, test_val in test_vals.items():
998 avg_val = sum(test_val) / len(test_val)
999 y_vals[test_name][key] = [avg_val, len(test_val)]
1000 ideal = avg_val / (int(key) * 1e6)
1001 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
1002 y_1c_max[test_name] = ideal
1004 vals = OrderedDict()
1009 for test_name, test_vals in y_vals.items():
1011 if test_vals[u"1"][1]:
1015 test_name.replace(u'-ndrpdr', u'').
1016 replace(u'2n1l-', u'')
1018 vals[name] = OrderedDict()
1019 y_val_1 = test_vals[u"1"][0] / 1e6
1020 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
1022 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
1025 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
1026 vals[name][u"rel"] = [1.0, None, None]
1027 vals[name][u"ideal"] = [
1028 y_1c_max[test_name],
1029 y_1c_max[test_name] * 2,
1030 y_1c_max[test_name] * 4
1032 vals[name][u"diff"] = [
1033 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1,
1037 vals[name][u"count"] = [
1044 val_max = max(vals[name][u"val"])
1045 except ValueError as err:
1046 logging.error(repr(err))
1049 y_max.append(val_max)
1052 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
1053 vals[name][u"diff"][1] = \
1054 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
1056 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
1057 vals[name][u"diff"][2] = \
1058 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
1059 except IndexError as err:
1060 logging.warning(f"No data for {test_name}")
1061 logging.warning(repr(err))
1064 if u"x520" in test_name:
1065 limit = plot[u"limits"][u"nic"][u"x520"]
1066 elif u"x710" in test_name:
1067 limit = plot[u"limits"][u"nic"][u"x710"]
1068 elif u"xxv710" in test_name:
1069 limit = plot[u"limits"][u"nic"][u"xxv710"]
1070 elif u"xl710" in test_name:
1071 limit = plot[u"limits"][u"nic"][u"xl710"]
1072 elif u"x553" in test_name:
1073 limit = plot[u"limits"][u"nic"][u"x553"]
1074 elif u"cx556a" in test_name:
1075 limit = plot[u"limits"][u"nic"][u"cx556a"]
1076 elif u"e810cq" in test_name:
1077 limit = plot[u"limits"][u"nic"][u"e810cq"]
1080 if limit > nic_limit:
1083 mul = 2 if u"ge2p" in test_name else 1
1084 if u"10ge" in test_name:
1085 limit = plot[u"limits"][u"link"][u"10ge"] * mul
1086 elif u"25ge" in test_name:
1087 limit = plot[u"limits"][u"link"][u"25ge"] * mul
1088 elif u"40ge" in test_name:
1089 limit = plot[u"limits"][u"link"][u"40ge"] * mul
1090 elif u"100ge" in test_name:
1091 limit = plot[u"limits"][u"link"][u"100ge"] * mul
1094 if limit > lnk_limit:
1097 if u"cx556a" in test_name:
1098 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
1100 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
1101 if limit > pci_limit:
1105 annotations = list()
1109 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
1113 min_limit = min((nic_limit, lnk_limit, pci_limit))
1114 if nic_limit == min_limit:
1115 traces.append(plgo.Scatter(
1117 y=[nic_limit, ] * len(x_vals),
1118 name=f"NIC: {nic_limit:.2f}Mpps",
1127 annotations.append(dict(
1134 text=f"NIC: {nic_limit:.2f}Mpps",
1142 y_max.append(nic_limit)
1143 elif lnk_limit == min_limit:
1144 traces.append(plgo.Scatter(
1146 y=[lnk_limit, ] * len(x_vals),
1147 name=f"Link: {lnk_limit:.2f}Mpps",
1156 annotations.append(dict(
1163 text=f"Link: {lnk_limit:.2f}Mpps",
1171 y_max.append(lnk_limit)
1172 elif pci_limit == min_limit:
1173 traces.append(plgo.Scatter(
1175 y=[pci_limit, ] * len(x_vals),
1176 name=f"PCIe: {pci_limit:.2f}Mpps",
1185 annotations.append(dict(
1192 text=f"PCIe: {pci_limit:.2f}Mpps",
1200 y_max.append(pci_limit)
1202 # Perfect and measured:
1204 for name, val in vals.items():
1207 for idx in range(len(val[u"val"])):
1209 if isinstance(val[u"val"][idx], float):
1211 f"No. of Runs: {val[u'count'][idx]}<br>"
1212 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
1214 if isinstance(val[u"diff"][idx], float):
1215 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
1216 if isinstance(val[u"rel"][idx], float):
1217 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
1218 hovertext.append(htext)
1225 mode=u"lines+markers",
1234 hoverinfo=u"text+name"
1241 name=f"{name} perfect",
1249 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1254 except (IndexError, ValueError, KeyError) as err:
1255 logging.warning(f"No data for {name}\n{repr(err)}")
1259 file_name = f"{plot[u'output-file'].format(test_type=ttype)}.html"
1260 logging.info(f" Writing file {file_name}")
1261 layout = deepcopy(plot[u"layout"])
1262 if layout.get(u"title", None):
1263 layout[u"title"] = (
1264 f"<b>Speedup Multi-core:</b> "
1265 f"{layout[u'title'].format(test_type=ttype)}"
1267 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1268 layout[u"annotations"].extend(annotations)
1269 plpl = plgo.Figure(data=traces, layout=layout)
1278 except PlotlyError as err:
1280 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1284 def plot_http_server_perf_box(plot, input_data):
1285 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1286 specified in the specification file.
1288 :param plot: Plot to generate.
1289 :param input_data: Data to process.
1290 :type plot: pandas.Series
1291 :type input_data: InputData
1294 # Transform the data
1296 f" Creating the data set for the {plot.get(u'type', u'')} "
1297 f"{plot.get(u'title', u'')}."
1299 data = input_data.filter_data(plot)
1301 logging.error(u"No data.")
1304 # Prepare the data for the plot
1309 if y_vals.get(test[u"name"], None) is None:
1310 y_vals[test[u"name"]] = list()
1312 y_vals[test[u"name"]].append(test[u"result"])
1313 except (KeyError, TypeError):
1314 y_vals[test[u"name"]].append(None)
1316 # Add None to the lists with missing data
1318 nr_of_samples = list()
1319 for val in y_vals.values():
1320 if len(val) > max_len:
1322 nr_of_samples.append(len(val))
1323 for val in y_vals.values():
1324 if len(val) < max_len:
1325 val.extend([None for _ in range(max_len - len(val))])
1329 df_y = pd.DataFrame(y_vals)
1331 for i, col in enumerate(df_y.columns):
1334 f"({nr_of_samples[i]:02d} " \
1335 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1336 f"{col.lower().replace(u'-ndrpdr', u'')}"
1338 name_lst = name.split(u'-')
1341 for segment in name_lst:
1342 if (len(name) + len(segment) + 1) > 50 and split_name:
1345 name += segment + u'-'
1348 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1354 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1358 f" Writing file {plot[u'output-file']}"
1359 f"{plot[u'output-file-type']}."
1365 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1367 except PlotlyError as err:
1369 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1374 def plot_nf_heatmap(plot, input_data):
1375 """Generate the plot(s) with algorithm: plot_nf_heatmap
1376 specified in the specification file.
1378 :param plot: Plot to generate.
1379 :param input_data: Data to process.
1380 :type plot: pandas.Series
1381 :type input_data: InputData
1384 def sort_by_int(value):
1385 """Makes possible to sort a list of strings which represent integers.
1387 :param value: Integer as a string.
1389 :returns: Integer representation of input parameter 'value'.
1394 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1395 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1397 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
1400 # Transform the data
1402 f" Creating the data set for the {plot.get(u'type', u'')} "
1403 f"{plot.get(u'title', u'')}."
1405 in_data = input_data.filter_tests_by_name(
1407 continue_on_error=True,
1408 params=[u"throughput", u"result", u"name", u"tags", u"type"]
1410 if in_data is None or in_data.empty:
1411 logging.error(u"No data.")
1414 for ttype in plot.get(u"test-type", (u"ndr", u"pdr")):
1415 for core in plot.get(u"core", tuple()):
1416 for item in plot.get(u"include", tuple()):
1417 reg_ex = re.compile(str(item.format(core=core)).lower())
1420 for test_id, test in build.iteritems():
1421 if not re.match(reg_ex, str(test_id).lower()):
1423 for tag in test[u"tags"]:
1424 groups = re.search(regex_cn, tag)
1426 chain = str(groups.group(1))
1427 node = str(groups.group(2))
1431 groups = re.search(regex_test_name, test[u"name"])
1432 if groups and len(groups.groups()) == 3:
1434 f"{str(groups.group(1))}-"
1435 f"{str(groups.group(2))}-"
1436 f"{str(groups.group(3))}"
1440 if vals.get(chain, None) is None:
1441 vals[chain] = dict()
1442 if vals[chain].get(node, None) is None:
1443 vals[chain][node] = dict(
1452 result = test[u"result"][u"receive-rate"]
1453 elif ttype == u"pdr":
1455 test[u"throughput"][u"PDR"][u"LOWER"]
1456 elif ttype == u"ndr":
1458 test[u"throughput"][u"NDR"][u"LOWER"]
1465 vals[chain][node][u"vals"].append(result)
1468 logging.error(u"No data.")
1474 txt_chains.append(key_c)
1475 for key_n in vals[key_c].keys():
1476 txt_nodes.append(key_n)
1477 if vals[key_c][key_n][u"vals"]:
1478 vals[key_c][key_n][u"nr"] = \
1479 len(vals[key_c][key_n][u"vals"])
1480 vals[key_c][key_n][u"mean"] = \
1481 round(mean(vals[key_c][key_n][u"vals"]) / 1e6, 1)
1482 vals[key_c][key_n][u"stdev"] = \
1483 round(stdev(vals[key_c][key_n][u"vals"]) / 1e6, 1)
1484 txt_nodes = list(set(txt_nodes))
1486 txt_chains = sorted(txt_chains, key=sort_by_int)
1487 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1489 chains = [i + 1 for i in range(len(txt_chains))]
1490 nodes = [i + 1 for i in range(len(txt_nodes))]
1492 data = [list() for _ in range(len(chains))]
1493 for chain in chains:
1496 val = vals[txt_chains[chain - 1]] \
1497 [txt_nodes[node - 1]][u"mean"]
1498 except (KeyError, IndexError):
1500 data[chain - 1].append(val)
1503 my_green = [[0.0, u"rgb(235, 249, 242)"],
1504 [1.0, u"rgb(45, 134, 89)"]]
1506 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1507 [1.0, u"rgb(57, 115, 172)"]]
1509 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1510 [1.0, u"rgb(102, 102, 102)"]]
1513 annotations = list()
1515 text = (u"Test: {name}<br>"
1520 for chain, _ in enumerate(txt_chains):
1522 for node, _ in enumerate(txt_nodes):
1523 if data[chain][node] is not None:
1532 text=str(data[chain][node]),
1540 hover_line.append(text.format(
1541 name=vals[txt_chains[chain]][txt_nodes[node]]
1543 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1544 val=data[chain][node],
1545 stdev=vals[txt_chains[chain]][txt_nodes[node]]
1548 hovertext.append(hover_line)
1556 title=plot.get(u"z-axis", u"{test_type}").
1557 format(test_type=ttype.upper()),
1571 colorscale=my_green,
1577 for idx, item in enumerate(txt_nodes):
1595 for idx, item in enumerate(txt_chains):
1622 text=plot.get(u"x-axis", u""),
1639 text=plot.get(u"y-axis", u""),
1648 updatemenus = list([
1659 u"colorscale": [my_green, ],
1660 u"reversescale": False
1669 u"colorscale": [my_blue, ],
1670 u"reversescale": False
1679 u"colorscale": [my_grey, ],
1680 u"reversescale": False
1691 layout = deepcopy(plot[u"layout"])
1692 except KeyError as err:
1694 f"Finished with error: No layout defined\n{repr(err)}"
1698 layout[u"annotations"] = annotations
1699 layout[u'updatemenus'] = updatemenus
1700 if layout.get(u"title", None):
1701 layout[u"title"] = layout[u'title'].replace(u"test_type", ttype)
1705 plpl = plgo.Figure(data=traces, layout=layout)
1709 f"{plot[u'output-file'].format(core=core, test_type=ttype)}"
1712 logging.info(f" Writing file {file_name}")
1719 except PlotlyError as err:
1721 f" Finished with error: {repr(err)}".replace(u"\n", u" ")