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):
492 tst_name = re.sub(REGEX_NIC, u"",
493 col.lower().replace(u'-reconf', u'').
494 replace(u'2n1l-', u'').replace(u'2n-', u'').
495 replace(u'testpmd', u''))
497 traces.append(plgo.Box(
498 x=[str(i + 1) + u'.'] * len(df_y[col]),
502 f"({nr_of_samples[i]:02d} "
503 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
504 f"packets lost average: {mean(loss[col]):.1f}) "
505 f"{u'-'.join(tst_name.split(u'-')[2:])}"
511 layout = deepcopy(plot[u"layout"])
512 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
513 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
514 layout[u"legend"][u"font"][u"size"] = 14
515 layout[u"yaxis"].pop(u"range")
516 plpl = plgo.Figure(data=traces, layout=layout)
519 file_type = plot.get(u"output-file-type", u".html")
520 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
525 filename=f"{plot[u'output-file']}{file_type}"
527 except PlotlyError as err:
529 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
534 def plot_perf_box_name(plot, input_data):
535 """Generate the plot(s) with algorithm: plot_perf_box_name
536 specified in the specification file.
538 :param plot: Plot to generate.
539 :param input_data: Data to process.
540 :type plot: pandas.Series
541 :type input_data: InputData
546 f" Creating data set for the {plot.get(u'type', u'')} "
547 f"{plot.get(u'title', u'')}."
549 data = input_data.filter_tests_by_name(
551 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
553 logging.error(u"No data.")
556 # Prepare the data for the plot
557 plot_title = plot.get(u"title", u"").lower()
559 if u"-gbps" in plot_title:
563 value = u"throughput"
565 y_vals = OrderedDict()
568 for item in plot.get(u"include", tuple()):
569 reg_ex = re.compile(str(item).lower())
572 for test_id, test in build.iteritems():
573 if not re.match(reg_ex, str(test_id).lower()):
575 if y_vals.get(test[u"parent"], None) is None:
576 y_vals[test[u"parent"]] = list()
578 if test[u"type"] in (u"NDRPDR", u"CPS"):
579 test_type = test[u"type"]
581 if u"-pdr" in plot_title:
583 elif u"-ndr" in plot_title:
587 u"Wrong title. No information about test "
588 u"type. Add '-ndr' or '-pdr' to the test "
592 y_vals[test[u"parent"]].append(
593 test[value][ttype][u"LOWER"] * multiplier
596 elif test[u"type"] in (u"SOAK",):
597 y_vals[test[u"parent"]]. \
598 append(test[u"throughput"][u"LOWER"])
601 elif test[u"type"] in (u"HOSTSTACK",):
602 if u"LDPRELOAD" in test[u"tags"]:
603 y_vals[test[u"parent"]].append(
605 test[u"result"][u"bits_per_second"]
608 elif u"VPPECHO" in test[u"tags"]:
609 y_vals[test[u"parent"]].append(
611 test[u"result"][u"client"][u"tx_data"]
614 test[u"result"][u"client"][u"time"]
617 test[u"result"][u"server"][u"time"])
620 test_type = u"HOSTSTACK"
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''))
649 x=[str(i + 1) + u'.'] * len(df_y[col]),
650 y=[y / 1e6 if y else None for y in df_y[col]],
653 f"({nr_of_samples[i]:02d} "
654 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
659 if test_type in (u"SOAK", ):
660 kwargs[u"boxpoints"] = u"all"
662 traces.append(plgo.Box(**kwargs))
665 val_max = max(df_y[col])
667 y_max.append(int(val_max / 1e6) + 2)
668 except (ValueError, TypeError) as err:
669 logging.error(repr(err))
674 layout = deepcopy(plot[u"layout"])
675 if layout.get(u"title", None):
676 if test_type in (u"HOSTSTACK", ):
677 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
678 elif test_type in (u"CPS", ):
679 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
681 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
683 layout[u"yaxis"][u"range"] = [0, max(y_max)]
684 plpl = plgo.Figure(data=traces, layout=layout)
687 logging.info(f" Writing file {plot[u'output-file']}.html.")
692 filename=f"{plot[u'output-file']}.html"
694 except PlotlyError as err:
696 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
701 def plot_tsa_name(plot, input_data):
702 """Generate the plot(s) with algorithm:
704 specified in the specification file.
706 :param plot: Plot to generate.
707 :param input_data: Data to process.
708 :type plot: pandas.Series
709 :type input_data: InputData
713 plot_title = plot.get(u"title", u"")
715 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
717 data = input_data.filter_tests_by_name(
719 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
722 logging.error(u"No data.")
725 plot_title = plot_title.lower()
727 if u"-gbps" in plot_title:
732 value = u"throughput"
736 y_vals = OrderedDict()
737 for item in plot.get(u"include", tuple()):
738 reg_ex = re.compile(str(item).lower())
741 for test_id, test in build.iteritems():
742 if re.match(reg_ex, str(test_id).lower()):
743 if y_vals.get(test[u"parent"], None) is None:
744 y_vals[test[u"parent"]] = {
750 if test[u"type"] not in (u"NDRPDR", u"CPS"):
753 if u"-pdr" in plot_title:
755 elif u"-ndr" in plot_title:
760 if u"1C" in test[u"tags"]:
761 y_vals[test[u"parent"]][u"1"].append(
762 test[value][ttype][u"LOWER"] * multiplier
764 elif u"2C" in test[u"tags"]:
765 y_vals[test[u"parent"]][u"2"].append(
766 test[value][ttype][u"LOWER"] * multiplier
768 elif u"4C" in test[u"tags"]:
769 y_vals[test[u"parent"]][u"4"].append(
770 test[value][ttype][u"LOWER"] * multiplier
772 except (KeyError, TypeError):
776 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
780 for test_name, test_vals in y_vals.items():
781 for key, test_val in test_vals.items():
783 avg_val = sum(test_val) / len(test_val)
784 y_vals[test_name][key] = [avg_val, len(test_val)]
785 ideal = avg_val / (int(key) * 1e6)
786 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
787 y_1c_max[test_name] = ideal
794 for test_name, test_vals in y_vals.items():
796 if test_vals[u"1"][1]:
800 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
802 vals[name] = OrderedDict()
803 y_val_1 = test_vals[u"1"][0] / 1e6
804 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
806 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
809 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
810 vals[name][u"rel"] = [1.0, None, None]
811 vals[name][u"ideal"] = [
813 y_1c_max[test_name] * 2,
814 y_1c_max[test_name] * 4
816 vals[name][u"diff"] = [
817 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
819 vals[name][u"count"] = [
826 val_max = max(vals[name][u"val"])
827 except ValueError as err:
828 logging.error(repr(err))
831 y_max.append(val_max)
834 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
835 vals[name][u"diff"][1] = \
836 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
838 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
839 vals[name][u"diff"][2] = \
840 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
841 except IndexError as err:
842 logging.warning(f"No data for {test_name}")
843 logging.warning(repr(err))
846 if u"x520" in test_name:
847 limit = plot[u"limits"][u"nic"][u"x520"]
848 elif u"x710" in test_name:
849 limit = plot[u"limits"][u"nic"][u"x710"]
850 elif u"xxv710" in test_name:
851 limit = plot[u"limits"][u"nic"][u"xxv710"]
852 elif u"xl710" in test_name:
853 limit = plot[u"limits"][u"nic"][u"xl710"]
854 elif u"x553" in test_name:
855 limit = plot[u"limits"][u"nic"][u"x553"]
856 elif u"cx556a" in test_name:
857 limit = plot[u"limits"][u"nic"][u"cx556a"]
860 if limit > nic_limit:
863 mul = 2 if u"ge2p" in test_name else 1
864 if u"10ge" in test_name:
865 limit = plot[u"limits"][u"link"][u"10ge"] * mul
866 elif u"25ge" in test_name:
867 limit = plot[u"limits"][u"link"][u"25ge"] * mul
868 elif u"40ge" in test_name:
869 limit = plot[u"limits"][u"link"][u"40ge"] * mul
870 elif u"100ge" in test_name:
871 limit = plot[u"limits"][u"link"][u"100ge"] * mul
874 if limit > lnk_limit:
877 if u"cx556a" in test_name:
878 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
880 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
881 if limit > pci_limit:
889 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
893 min_limit = min((nic_limit, lnk_limit, pci_limit))
894 if nic_limit == min_limit:
895 traces.append(plgo.Scatter(
897 y=[nic_limit, ] * len(x_vals),
898 name=f"NIC: {nic_limit:.2f}Mpps",
907 annotations.append(dict(
914 text=f"NIC: {nic_limit:.2f}Mpps",
922 y_max.append(nic_limit)
923 elif lnk_limit == min_limit:
924 traces.append(plgo.Scatter(
926 y=[lnk_limit, ] * len(x_vals),
927 name=f"Link: {lnk_limit:.2f}Mpps",
936 annotations.append(dict(
943 text=f"Link: {lnk_limit:.2f}Mpps",
951 y_max.append(lnk_limit)
952 elif pci_limit == min_limit:
953 traces.append(plgo.Scatter(
955 y=[pci_limit, ] * len(x_vals),
956 name=f"PCIe: {pci_limit:.2f}Mpps",
965 annotations.append(dict(
972 text=f"PCIe: {pci_limit:.2f}Mpps",
980 y_max.append(pci_limit)
982 # Perfect and measured:
984 for name, val in vals.items():
987 for idx in range(len(val[u"val"])):
989 if isinstance(val[u"val"][idx], float):
991 f"No. of Runs: {val[u'count'][idx]}<br>"
992 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
994 if isinstance(val[u"diff"][idx], float):
995 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
996 if isinstance(val[u"rel"][idx], float):
997 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
998 hovertext.append(htext)
1005 mode=u"lines+markers",
1014 hoverinfo=u"text+name"
1021 name=f"{name} perfect",
1029 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1034 except (IndexError, ValueError, KeyError) as err:
1035 logging.warning(f"No data for {name}\n{repr(err)}")
1039 file_type = plot.get(u"output-file-type", u".html")
1040 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1041 layout = deepcopy(plot[u"layout"])
1042 if layout.get(u"title", None):
1043 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1044 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1045 layout[u"annotations"].extend(annotations)
1046 plpl = plgo.Figure(data=traces, layout=layout)
1053 filename=f"{plot[u'output-file']}{file_type}"
1055 except PlotlyError as err:
1057 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1062 def plot_http_server_perf_box(plot, input_data):
1063 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1064 specified in the specification file.
1066 :param plot: Plot to generate.
1067 :param input_data: Data to process.
1068 :type plot: pandas.Series
1069 :type input_data: InputData
1072 # Transform the data
1074 f" Creating the data set for the {plot.get(u'type', u'')} "
1075 f"{plot.get(u'title', u'')}."
1077 data = input_data.filter_data(plot)
1079 logging.error(u"No data.")
1082 # Prepare the data for the plot
1087 if y_vals.get(test[u"name"], None) is None:
1088 y_vals[test[u"name"]] = list()
1090 y_vals[test[u"name"]].append(test[u"result"])
1091 except (KeyError, TypeError):
1092 y_vals[test[u"name"]].append(None)
1094 # Add None to the lists with missing data
1096 nr_of_samples = list()
1097 for val in y_vals.values():
1098 if len(val) > max_len:
1100 nr_of_samples.append(len(val))
1101 for val in y_vals.values():
1102 if len(val) < max_len:
1103 val.extend([None for _ in range(max_len - len(val))])
1107 df_y = pd.DataFrame(y_vals)
1109 for i, col in enumerate(df_y.columns):
1112 f"({nr_of_samples[i]:02d} " \
1113 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1114 f"{col.lower().replace(u'-ndrpdr', u'')}"
1116 name_lst = name.split(u'-')
1119 for segment in name_lst:
1120 if (len(name) + len(segment) + 1) > 50 and split_name:
1123 name += segment + u'-'
1126 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1132 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1136 f" Writing file {plot[u'output-file']}"
1137 f"{plot[u'output-file-type']}."
1143 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1145 except PlotlyError as err:
1147 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1152 def plot_nf_heatmap(plot, input_data):
1153 """Generate the plot(s) with algorithm: plot_nf_heatmap
1154 specified in the specification file.
1156 :param plot: Plot to generate.
1157 :param input_data: Data to process.
1158 :type plot: pandas.Series
1159 :type input_data: InputData
1162 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1163 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1165 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
1168 # Transform the data
1170 f" Creating the data set for the {plot.get(u'type', u'')} "
1171 f"{plot.get(u'title', u'')}."
1173 data = input_data.filter_data(plot, continue_on_error=True)
1174 if data is None or data.empty:
1175 logging.error(u"No data.")
1181 for tag in test[u"tags"]:
1182 groups = re.search(regex_cn, tag)
1184 chain = str(groups.group(1))
1185 node = str(groups.group(2))
1189 groups = re.search(regex_test_name, test[u"name"])
1190 if groups and len(groups.groups()) == 3:
1192 f"{str(groups.group(1))}-"
1193 f"{str(groups.group(2))}-"
1194 f"{str(groups.group(3))}"
1198 if vals.get(chain, None) is None:
1199 vals[chain] = dict()
1200 if vals[chain].get(node, None) is None:
1201 vals[chain][node] = dict(
1209 if plot[u"include-tests"] == u"MRR":
1210 result = test[u"result"][u"receive-rate"]
1211 elif plot[u"include-tests"] == u"PDR":
1212 result = test[u"throughput"][u"PDR"][u"LOWER"]
1213 elif plot[u"include-tests"] == u"NDR":
1214 result = test[u"throughput"][u"NDR"][u"LOWER"]
1221 vals[chain][node][u"vals"].append(result)
1224 logging.error(u"No data.")
1230 txt_chains.append(key_c)
1231 for key_n in vals[key_c].keys():
1232 txt_nodes.append(key_n)
1233 if vals[key_c][key_n][u"vals"]:
1234 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1235 vals[key_c][key_n][u"mean"] = \
1236 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1237 vals[key_c][key_n][u"stdev"] = \
1238 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1239 txt_nodes = list(set(txt_nodes))
1241 def sort_by_int(value):
1242 """Makes possible to sort a list of strings which represent integers.
1244 :param value: Integer as a string.
1246 :returns: Integer representation of input parameter 'value'.
1251 txt_chains = sorted(txt_chains, key=sort_by_int)
1252 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1254 chains = [i + 1 for i in range(len(txt_chains))]
1255 nodes = [i + 1 for i in range(len(txt_nodes))]
1257 data = [list() for _ in range(len(chains))]
1258 for chain in chains:
1261 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1262 except (KeyError, IndexError):
1264 data[chain - 1].append(val)
1267 my_green = [[0.0, u"rgb(235, 249, 242)"],
1268 [1.0, u"rgb(45, 134, 89)"]]
1270 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1271 [1.0, u"rgb(57, 115, 172)"]]
1273 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1274 [1.0, u"rgb(102, 102, 102)"]]
1277 annotations = list()
1279 text = (u"Test: {name}<br>"
1284 for chain, _ in enumerate(txt_chains):
1286 for node, _ in enumerate(txt_nodes):
1287 if data[chain][node] is not None:
1296 text=str(data[chain][node]),
1304 hover_line.append(text.format(
1305 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1306 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1307 val=data[chain][node],
1308 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1309 hovertext.append(hover_line)
1317 title=plot.get(u"z-axis", u""),
1331 colorscale=my_green,
1337 for idx, item in enumerate(txt_nodes):
1355 for idx, item in enumerate(txt_chains):
1382 text=plot.get(u"x-axis", u""),
1399 text=plot.get(u"y-axis", u""),
1408 updatemenus = list([
1419 u"colorscale": [my_green, ],
1420 u"reversescale": False
1429 u"colorscale": [my_blue, ],
1430 u"reversescale": False
1439 u"colorscale": [my_grey, ],
1440 u"reversescale": False
1451 layout = deepcopy(plot[u"layout"])
1452 except KeyError as err:
1453 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1456 layout[u"annotations"] = annotations
1457 layout[u'updatemenus'] = updatemenus
1461 plpl = plgo.Figure(data=traces, layout=layout)
1464 logging.info(f" Writing file {plot[u'output-file']}.html")
1469 filename=f"{plot[u'output-file']}.html"
1471 except PlotlyError as err:
1473 f" Finished with error: {repr(err)}".replace(u"\n", u" ")