1 # Copyright (c) 2020 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Algorithms to generate plots.
24 import plotly.offline as ploff
25 import plotly.graph_objs as plgo
27 from collections import OrderedDict
28 from copy import deepcopy
31 from plotly.exceptions import PlotlyError
33 from pal_utils import mean, stdev
62 REGEX_NIC = re.compile(r'(\d*ge\dp\d\D*\d*[a-z]*)-')
65 def generate_plots(spec, data):
66 """Generate all plots specified in the specification file.
68 :param spec: Specification read from the specification file.
69 :param data: Data to process.
70 :type spec: Specification
75 u"plot_nf_reconf_box_name": plot_nf_reconf_box_name,
76 u"plot_perf_box_name": plot_perf_box_name,
77 u"plot_tsa_name": plot_tsa_name,
78 u"plot_http_server_perf_box": plot_http_server_perf_box,
79 u"plot_nf_heatmap": plot_nf_heatmap,
80 u"plot_hdrh_lat_by_percentile": plot_hdrh_lat_by_percentile,
81 u"plot_hdrh_lat_by_percentile_x_log": plot_hdrh_lat_by_percentile_x_log
84 logging.info(u"Generating the plots ...")
85 for index, plot in enumerate(spec.plots):
87 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
88 plot[u"limits"] = spec.configuration[u"limits"]
89 generator[plot[u"algorithm"]](plot, data)
90 logging.info(u" Done.")
91 except NameError as err:
93 f"Probably algorithm {plot[u'algorithm']} is not defined: "
96 logging.info(u"Done.")
99 def plot_hdrh_lat_by_percentile(plot, input_data):
100 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile
101 specified in the specification file.
103 :param plot: Plot to generate.
104 :param input_data: Data to process.
105 :type plot: pandas.Series
106 :type input_data: InputData
111 f" Creating the data set for the {plot.get(u'type', u'')} "
112 f"{plot.get(u'title', u'')}."
114 if plot.get(u"include", None):
115 data = input_data.filter_tests_by_name(
117 params=[u"name", u"latency", u"parent", u"tags", u"type"]
119 elif plot.get(u"filter", None):
120 data = input_data.filter_data(
122 params=[u"name", u"latency", u"parent", u"tags", u"type"],
123 continue_on_error=True
126 job = list(plot[u"data"].keys())[0]
127 build = str(plot[u"data"][job][0])
128 data = input_data.tests(job, build)
130 if data is None or len(data) == 0:
131 logging.error(u"No data.")
135 u"LAT0": u"No-load.",
136 u"PDR10": u"Low-load, 10% PDR.",
137 u"PDR50": u"Mid-load, 50% PDR.",
138 u"PDR90": u"High-load, 90% PDR.",
139 u"PDR": u"Full-load, 100% PDR.",
140 u"NDR10": u"Low-load, 10% NDR.",
141 u"NDR50": u"Mid-load, 50% NDR.",
142 u"NDR90": u"High-load, 90% NDR.",
143 u"NDR": u"Full-load, 100% NDR."
153 file_links = plot.get(u"output-file-links", None)
154 target_links = plot.get(u"target-links", None)
158 if test[u"type"] not in (u"NDRPDR",):
159 logging.warning(f"Invalid test type: {test[u'type']}")
161 name = re.sub(REGEX_NIC, u"", test[u"parent"].
162 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
164 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
165 except (IndexError, AttributeError, KeyError, ValueError):
167 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
169 logging.info(f" Generating the graph: {name_link}")
172 layout = deepcopy(plot[u"layout"])
174 for color, graph in enumerate(graphs):
175 for idx, direction in enumerate((u"direction1", u"direction2")):
179 f"<b>{desc[graph]}</b><br>"
180 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
181 f"Percentile: 0.0%<br>"
185 decoded = hdrh.histogram.HdrHistogram.decode(
186 test[u"latency"][graph][direction][u"hdrh"]
188 except hdrh.codec.HdrLengthException:
190 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
194 for item in decoded.get_recorded_iterator():
195 percentile = item.percentile_level_iterated_to
196 if percentile > 99.9:
198 xaxis.append(percentile)
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: {percentile:.5f}%<br>"
204 f"Latency: {item.value_iterated_to}uSec"
212 legendgroup=desc[graph],
213 showlegend=bool(idx),
216 dash=u"dash" if idx % 2 else u"solid"
223 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
224 fig.update_layout(layout)
227 file_name = f"{plot[u'output-file']}-{name_link}.html"
228 logging.info(f" Writing file {file_name}")
232 ploff.plot(fig, show_link=False, auto_open=False,
234 # Add link to the file:
235 if file_links and target_links:
236 with open(file_links, u"a") as file_handler:
239 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
241 except FileNotFoundError as err:
243 f"Not possible to write the link to the file "
244 f"{file_links}\n{err}"
246 except PlotlyError as err:
247 logging.error(f" Finished with error: {repr(err)}")
249 except hdrh.codec.HdrLengthException as err:
250 logging.warning(repr(err))
253 except (ValueError, KeyError) as err:
254 logging.warning(repr(err))
258 def plot_hdrh_lat_by_percentile_x_log(plot, input_data):
259 """Generate the plot(s) with algorithm: plot_hdrh_lat_by_percentile_x_log
260 specified in the specification file.
262 :param plot: Plot to generate.
263 :param input_data: Data to process.
264 :type plot: pandas.Series
265 :type input_data: InputData
270 f" Creating the data set for the {plot.get(u'type', u'')} "
271 f"{plot.get(u'title', u'')}."
273 if plot.get(u"include", None):
274 data = input_data.filter_tests_by_name(
276 params=[u"name", u"latency", u"parent", u"tags", u"type"]
278 elif plot.get(u"filter", None):
279 data = input_data.filter_data(
281 params=[u"name", u"latency", u"parent", u"tags", u"type"],
282 continue_on_error=True
285 job = list(plot[u"data"].keys())[0]
286 build = str(plot[u"data"][job][0])
287 data = input_data.tests(job, build)
289 if data is None or len(data) == 0:
290 logging.error(u"No data.")
294 u"LAT0": u"No-load.",
295 u"PDR10": u"Low-load, 10% PDR.",
296 u"PDR50": u"Mid-load, 50% PDR.",
297 u"PDR90": u"High-load, 90% PDR.",
298 u"PDR": u"Full-load, 100% PDR.",
299 u"NDR10": u"Low-load, 10% NDR.",
300 u"NDR50": u"Mid-load, 50% NDR.",
301 u"NDR90": u"High-load, 90% NDR.",
302 u"NDR": u"Full-load, 100% NDR."
312 file_links = plot.get(u"output-file-links", None)
313 target_links = plot.get(u"target-links", None)
317 if test[u"type"] not in (u"NDRPDR",):
318 logging.warning(f"Invalid test type: {test[u'type']}")
320 name = re.sub(REGEX_NIC, u"", test[u"parent"].
321 replace(u'-ndrpdr', u'').replace(u'2n1l-', u''))
323 nic = re.search(REGEX_NIC, test[u"parent"]).group(1)
324 except (IndexError, AttributeError, KeyError, ValueError):
326 name_link = f"{nic}-{test[u'name']}".replace(u'-ndrpdr', u'')
328 logging.info(f" Generating the graph: {name_link}")
331 layout = deepcopy(plot[u"layout"])
334 for color, graph in enumerate(graphs):
335 for idx, direction in enumerate((u"direction1", u"direction2")):
340 decoded = hdrh.histogram.HdrHistogram.decode(
341 test[u"latency"][graph][direction][u"hdrh"]
343 except hdrh.codec.HdrLengthException:
345 f"No data for direction {(u'W-E', u'E-W')[idx % 2]}"
349 for item in decoded.get_recorded_iterator():
350 percentile = item.percentile_level_iterated_to
351 if percentile > 99.9999999:
353 xaxis.append(100.0 / (100.0 - percentile))
354 yaxis.append(item.value_iterated_to)
356 f"<b>{desc[graph]}</b><br>"
357 f"Direction: {(u'W-E', u'E-W')[idx % 2]}<br>"
358 f"Percentile: {percentile:.5f}%<br>"
359 f"Latency: {item.value_iterated_to}uSec"
367 legendgroup=desc[graph],
368 showlegend=not(bool(idx)),
371 dash=u"dash" if idx % 2 else u"solid"
377 xaxis_max = max(xaxis) if xaxis_max < max(
378 xaxis) else xaxis_max
380 layout[u"title"][u"text"] = f"<b>Latency:</b> {name}"
381 layout[u"xaxis"][u"range"] = [0, int(log(xaxis_max, 10)) + 1]
382 fig.update_layout(layout)
385 file_name = f"{plot[u'output-file']}-{name_link}.html"
386 logging.info(f" Writing file {file_name}")
390 ploff.plot(fig, show_link=False, auto_open=False,
392 # Add link to the file:
393 if file_links and target_links:
394 with open(file_links, u"a") as file_handler:
397 f"<{target_links}/{file_name.split(u'/')[-1]}>`_\n"
399 except FileNotFoundError as err:
401 f"Not possible to write the link to the file "
402 f"{file_links}\n{err}"
404 except PlotlyError as err:
405 logging.error(f" Finished with error: {repr(err)}")
407 except hdrh.codec.HdrLengthException as err:
408 logging.warning(repr(err))
411 except (ValueError, KeyError) as err:
412 logging.warning(repr(err))
416 def plot_nf_reconf_box_name(plot, input_data):
417 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
418 specified in the specification file.
420 :param plot: Plot to generate.
421 :param input_data: Data to process.
422 :type plot: pandas.Series
423 :type input_data: InputData
428 f" Creating the data set for the {plot.get(u'type', u'')} "
429 f"{plot.get(u'title', u'')}."
431 data = input_data.filter_tests_by_name(
432 plot, params=[u"result", u"parent", u"tags", u"type"]
435 logging.error(u"No data.")
438 # Prepare the data for the plot
439 y_vals = OrderedDict()
444 if y_vals.get(test[u"parent"], None) is None:
445 y_vals[test[u"parent"]] = list()
446 loss[test[u"parent"]] = list()
448 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
449 loss[test[u"parent"]].append(test[u"result"][u"loss"])
450 except (KeyError, TypeError):
451 y_vals[test[u"parent"]].append(None)
453 # Add None to the lists with missing data
455 nr_of_samples = list()
456 for val in y_vals.values():
457 if len(val) > max_len:
459 nr_of_samples.append(len(val))
460 for val in y_vals.values():
461 if len(val) < max_len:
462 val.extend([None for _ in range(max_len - len(val))])
466 df_y = pd.DataFrame(y_vals)
468 for i, col in enumerate(df_y.columns):
469 tst_name = re.sub(REGEX_NIC, u"",
470 col.lower().replace(u'-ndrpdr', u'').
471 replace(u'2n1l-', u''))
473 traces.append(plgo.Box(
474 x=[str(i + 1) + u'.'] * len(df_y[col]),
475 y=[y if y else None for y in df_y[col]],
478 f"({nr_of_samples[i]:02d} "
479 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
480 f"packets lost average: {mean(loss[col]):.1f}) "
481 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
487 layout = deepcopy(plot[u"layout"])
488 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
489 layout[u"yaxis"][u"title"] = u"<b>Effective Blocked Time [s]</b>"
490 layout[u"legend"][u"font"][u"size"] = 14
491 layout[u"yaxis"].pop(u"range")
492 plpl = plgo.Figure(data=traces, layout=layout)
495 file_type = plot.get(u"output-file-type", u".html")
496 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
501 filename=f"{plot[u'output-file']}{file_type}"
503 except PlotlyError as err:
505 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
510 def plot_perf_box_name(plot, input_data):
511 """Generate the plot(s) with algorithm: plot_perf_box_name
512 specified in the specification file.
514 :param plot: Plot to generate.
515 :param input_data: Data to process.
516 :type plot: pandas.Series
517 :type input_data: InputData
522 f" Creating data set for the {plot.get(u'type', u'')} "
523 f"{plot.get(u'title', u'')}."
525 data = input_data.filter_tests_by_name(
527 params=[u"throughput", u"gbps", u"result", u"parent", u"tags", u"type"])
529 logging.error(u"No data.")
532 # Prepare the data for the plot
533 plot_title = plot.get(u"title", u"").lower()
535 if u"-gbps" in plot_title:
539 value = u"throughput"
541 y_vals = OrderedDict()
544 for item in plot.get(u"include", tuple()):
545 reg_ex = re.compile(str(item).lower())
548 for test_id, test in build.iteritems():
549 if not re.match(reg_ex, str(test_id).lower()):
551 if y_vals.get(test[u"parent"], None) is None:
552 y_vals[test[u"parent"]] = list()
554 if test[u"type"] in (u"NDRPDR", u"CPS"):
555 test_type = test[u"type"]
557 if u"-pdr" in plot_title:
559 elif u"-ndr" in plot_title:
563 u"Wrong title. No information about test "
564 u"type. Add '-ndr' or '-pdr' to the test "
568 y_vals[test[u"parent"]].append(
569 test[value][ttype][u"LOWER"] * multiplier
572 elif test[u"type"] in (u"SOAK",):
573 y_vals[test[u"parent"]]. \
574 append(test[u"throughput"][u"LOWER"])
577 elif test[u"type"] in (u"HOSTSTACK",):
578 if u"LDPRELOAD" in test[u"tags"]:
579 y_vals[test[u"parent"]].append(
581 test[u"result"][u"bits_per_second"]
584 elif u"VPPECHO" in test[u"tags"]:
585 y_vals[test[u"parent"]].append(
587 test[u"result"][u"client"][u"tx_data"]
590 test[u"result"][u"client"][u"time"]
593 test[u"result"][u"server"][u"time"])
596 test_type = u"HOSTSTACK"
601 except (KeyError, TypeError):
602 y_vals[test[u"parent"]].append(None)
604 # Add None to the lists with missing data
606 nr_of_samples = list()
607 for val in y_vals.values():
608 if len(val) > max_len:
610 nr_of_samples.append(len(val))
611 for val in y_vals.values():
612 if len(val) < max_len:
613 val.extend([None for _ in range(max_len - len(val))])
617 df_y = pd.DataFrame(y_vals)
620 for i, col in enumerate(df_y.columns):
621 tst_name = re.sub(REGEX_NIC, u"",
622 col.lower().replace(u'-ndrpdr', u'').
623 replace(u'2n1l-', u''))
625 x=[str(i + 1) + u'.'] * len(df_y[col]),
626 y=[y / 1e6 if y else None for y in df_y[col]],
629 f"({nr_of_samples[i]:02d} "
630 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
635 if test_type in (u"SOAK", ):
636 kwargs[u"boxpoints"] = u"all"
638 traces.append(plgo.Box(**kwargs))
641 val_max = max(df_y[col])
643 y_max.append(int(val_max / 1e6) + 2)
644 except (ValueError, TypeError) as err:
645 logging.error(repr(err))
650 layout = deepcopy(plot[u"layout"])
651 if layout.get(u"title", None):
652 if test_type in (u"HOSTSTACK", ):
653 layout[u"title"] = f"<b>Bandwidth:</b> {layout[u'title']}"
654 elif test_type in (u"CPS", ):
655 layout[u"title"] = f"<b>CPS:</b> {layout[u'title']}"
657 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
659 layout[u"yaxis"][u"range"] = [0, max(y_max)]
660 plpl = plgo.Figure(data=traces, layout=layout)
663 logging.info(f" Writing file {plot[u'output-file']}.html.")
668 filename=f"{plot[u'output-file']}.html"
670 except PlotlyError as err:
672 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
677 def plot_tsa_name(plot, input_data):
678 """Generate the plot(s) with algorithm:
680 specified in the specification file.
682 :param plot: Plot to generate.
683 :param input_data: Data to process.
684 :type plot: pandas.Series
685 :type input_data: InputData
689 plot_title = plot.get(u"title", u"")
691 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
693 data = input_data.filter_tests_by_name(
695 params=[u"throughput", u"gbps", u"parent", u"tags", u"type"]
698 logging.error(u"No data.")
701 plot_title = plot_title.lower()
703 if u"-gbps" in plot_title:
708 value = u"throughput"
712 y_vals = OrderedDict()
713 for item in plot.get(u"include", tuple()):
714 reg_ex = re.compile(str(item).lower())
717 for test_id, test in build.iteritems():
718 if re.match(reg_ex, str(test_id).lower()):
719 if y_vals.get(test[u"parent"], None) is None:
720 y_vals[test[u"parent"]] = {
726 if test[u"type"] not in (u"NDRPDR", u"CPS"):
729 if u"-pdr" in plot_title:
731 elif u"-ndr" in plot_title:
736 if u"1C" in test[u"tags"]:
737 y_vals[test[u"parent"]][u"1"].append(
738 test[value][ttype][u"LOWER"] * multiplier
740 elif u"2C" in test[u"tags"]:
741 y_vals[test[u"parent"]][u"2"].append(
742 test[value][ttype][u"LOWER"] * multiplier
744 elif u"4C" in test[u"tags"]:
745 y_vals[test[u"parent"]][u"4"].append(
746 test[value][ttype][u"LOWER"] * multiplier
748 except (KeyError, TypeError):
752 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
756 for test_name, test_vals in y_vals.items():
757 for key, test_val in test_vals.items():
759 avg_val = sum(test_val) / len(test_val)
760 y_vals[test_name][key] = [avg_val, len(test_val)]
761 ideal = avg_val / (int(key) * 1e6)
762 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
763 y_1c_max[test_name] = ideal
770 for test_name, test_vals in y_vals.items():
772 if test_vals[u"1"][1]:
776 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
778 vals[name] = OrderedDict()
779 y_val_1 = test_vals[u"1"][0] / 1e6
780 y_val_2 = test_vals[u"2"][0] / 1e6 if test_vals[u"2"][0] \
782 y_val_4 = test_vals[u"4"][0] / 1e6 if test_vals[u"4"][0] \
785 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
786 vals[name][u"rel"] = [1.0, None, None]
787 vals[name][u"ideal"] = [
789 y_1c_max[test_name] * 2,
790 y_1c_max[test_name] * 4
792 vals[name][u"diff"] = [
793 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
795 vals[name][u"count"] = [
802 val_max = max(vals[name][u"val"])
803 except ValueError as err:
804 logging.error(repr(err))
807 y_max.append(val_max)
810 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
811 vals[name][u"diff"][1] = \
812 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
814 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
815 vals[name][u"diff"][2] = \
816 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
817 except IndexError as err:
818 logging.warning(f"No data for {test_name}")
819 logging.warning(repr(err))
822 if u"x520" in test_name:
823 limit = plot[u"limits"][u"nic"][u"x520"]
824 elif u"x710" in test_name:
825 limit = plot[u"limits"][u"nic"][u"x710"]
826 elif u"xxv710" in test_name:
827 limit = plot[u"limits"][u"nic"][u"xxv710"]
828 elif u"xl710" in test_name:
829 limit = plot[u"limits"][u"nic"][u"xl710"]
830 elif u"x553" in test_name:
831 limit = plot[u"limits"][u"nic"][u"x553"]
832 elif u"cx556a" in test_name:
833 limit = plot[u"limits"][u"nic"][u"cx556a"]
836 if limit > nic_limit:
839 mul = 2 if u"ge2p" in test_name else 1
840 if u"10ge" in test_name:
841 limit = plot[u"limits"][u"link"][u"10ge"] * mul
842 elif u"25ge" in test_name:
843 limit = plot[u"limits"][u"link"][u"25ge"] * mul
844 elif u"40ge" in test_name:
845 limit = plot[u"limits"][u"link"][u"40ge"] * mul
846 elif u"100ge" in test_name:
847 limit = plot[u"limits"][u"link"][u"100ge"] * mul
850 if limit > lnk_limit:
853 if u"cx556a" in test_name:
854 limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
856 limit = plot[u"limits"][u"pci"][u"pci-g3-x16"]
857 if limit > pci_limit:
865 if u"-gbps" not in plot_title and u"-cps-" not in plot_title:
869 min_limit = min((nic_limit, lnk_limit, pci_limit))
870 if nic_limit == min_limit:
871 traces.append(plgo.Scatter(
873 y=[nic_limit, ] * len(x_vals),
874 name=f"NIC: {nic_limit:.2f}Mpps",
883 annotations.append(dict(
890 text=f"NIC: {nic_limit:.2f}Mpps",
898 y_max.append(nic_limit)
899 elif lnk_limit == min_limit:
900 traces.append(plgo.Scatter(
902 y=[lnk_limit, ] * len(x_vals),
903 name=f"Link: {lnk_limit:.2f}Mpps",
912 annotations.append(dict(
919 text=f"Link: {lnk_limit:.2f}Mpps",
927 y_max.append(lnk_limit)
928 elif pci_limit == min_limit:
929 traces.append(plgo.Scatter(
931 y=[pci_limit, ] * len(x_vals),
932 name=f"PCIe: {pci_limit:.2f}Mpps",
941 annotations.append(dict(
948 text=f"PCIe: {pci_limit:.2f}Mpps",
956 y_max.append(pci_limit)
958 # Perfect and measured:
960 for name, val in vals.items():
963 for idx in range(len(val[u"val"])):
965 if isinstance(val[u"val"][idx], float):
967 f"No. of Runs: {val[u'count'][idx]}<br>"
968 f"Mean: {val[u'val'][idx]:.2f}{h_unit}<br>"
970 if isinstance(val[u"diff"][idx], float):
971 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
972 if isinstance(val[u"rel"][idx], float):
973 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
974 hovertext.append(htext)
981 mode=u"lines+markers",
990 hoverinfo=u"text+name"
997 name=f"{name} perfect",
1005 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
1010 except (IndexError, ValueError, KeyError) as err:
1011 logging.warning(f"No data for {name}\n{repr(err)}")
1015 file_type = plot.get(u"output-file-type", u".html")
1016 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
1017 layout = deepcopy(plot[u"layout"])
1018 if layout.get(u"title", None):
1019 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
1020 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
1021 layout[u"annotations"].extend(annotations)
1022 plpl = plgo.Figure(data=traces, layout=layout)
1029 filename=f"{plot[u'output-file']}{file_type}"
1031 except PlotlyError as err:
1033 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1038 def plot_http_server_perf_box(plot, input_data):
1039 """Generate the plot(s) with algorithm: plot_http_server_perf_box
1040 specified in the specification file.
1042 :param plot: Plot to generate.
1043 :param input_data: Data to process.
1044 :type plot: pandas.Series
1045 :type input_data: InputData
1048 # Transform the data
1050 f" Creating the data set for the {plot.get(u'type', u'')} "
1051 f"{plot.get(u'title', u'')}."
1053 data = input_data.filter_data(plot)
1055 logging.error(u"No data.")
1058 # Prepare the data for the plot
1063 if y_vals.get(test[u"name"], None) is None:
1064 y_vals[test[u"name"]] = list()
1066 y_vals[test[u"name"]].append(test[u"result"])
1067 except (KeyError, TypeError):
1068 y_vals[test[u"name"]].append(None)
1070 # Add None to the lists with missing data
1072 nr_of_samples = list()
1073 for val in y_vals.values():
1074 if len(val) > max_len:
1076 nr_of_samples.append(len(val))
1077 for val in y_vals.values():
1078 if len(val) < max_len:
1079 val.extend([None for _ in range(max_len - len(val))])
1083 df_y = pd.DataFrame(y_vals)
1085 for i, col in enumerate(df_y.columns):
1088 f"({nr_of_samples[i]:02d} " \
1089 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1090 f"{col.lower().replace(u'-ndrpdr', u'')}"
1092 name_lst = name.split(u'-')
1095 for segment in name_lst:
1096 if (len(name) + len(segment) + 1) > 50 and split_name:
1099 name += segment + u'-'
1102 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1108 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1112 f" Writing file {plot[u'output-file']}"
1113 f"{plot[u'output-file-type']}."
1119 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1121 except PlotlyError as err:
1123 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1128 def plot_nf_heatmap(plot, input_data):
1129 """Generate the plot(s) with algorithm: plot_nf_heatmap
1130 specified in the specification file.
1132 :param plot: Plot to generate.
1133 :param input_data: Data to process.
1134 :type plot: pandas.Series
1135 :type input_data: InputData
1138 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1139 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1141 r'(\d+vm\d+t|\d+dcr\d+t|\d+dcr\d+c).*$')
1144 # Transform the data
1146 f" Creating the data set for the {plot.get(u'type', u'')} "
1147 f"{plot.get(u'title', u'')}."
1149 data = input_data.filter_data(plot, continue_on_error=True)
1150 if data is None or data.empty:
1151 logging.error(u"No data.")
1157 for tag in test[u"tags"]:
1158 groups = re.search(regex_cn, tag)
1160 chain = str(groups.group(1))
1161 node = str(groups.group(2))
1165 groups = re.search(regex_test_name, test[u"name"])
1166 if groups and len(groups.groups()) == 3:
1168 f"{str(groups.group(1))}-"
1169 f"{str(groups.group(2))}-"
1170 f"{str(groups.group(3))}"
1174 if vals.get(chain, None) is None:
1175 vals[chain] = dict()
1176 if vals[chain].get(node, None) is None:
1177 vals[chain][node] = dict(
1185 if plot[u"include-tests"] == u"MRR":
1186 result = test[u"result"][u"receive-rate"]
1187 elif plot[u"include-tests"] == u"PDR":
1188 result = test[u"throughput"][u"PDR"][u"LOWER"]
1189 elif plot[u"include-tests"] == u"NDR":
1190 result = test[u"throughput"][u"NDR"][u"LOWER"]
1197 vals[chain][node][u"vals"].append(result)
1200 logging.error(u"No data.")
1206 txt_chains.append(key_c)
1207 for key_n in vals[key_c].keys():
1208 txt_nodes.append(key_n)
1209 if vals[key_c][key_n][u"vals"]:
1210 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1211 vals[key_c][key_n][u"mean"] = \
1212 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1213 vals[key_c][key_n][u"stdev"] = \
1214 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1215 txt_nodes = list(set(txt_nodes))
1217 def sort_by_int(value):
1218 """Makes possible to sort a list of strings which represent integers.
1220 :param value: Integer as a string.
1222 :returns: Integer representation of input parameter 'value'.
1227 txt_chains = sorted(txt_chains, key=sort_by_int)
1228 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1230 chains = [i + 1 for i in range(len(txt_chains))]
1231 nodes = [i + 1 for i in range(len(txt_nodes))]
1233 data = [list() for _ in range(len(chains))]
1234 for chain in chains:
1237 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1238 except (KeyError, IndexError):
1240 data[chain - 1].append(val)
1243 my_green = [[0.0, u"rgb(235, 249, 242)"],
1244 [1.0, u"rgb(45, 134, 89)"]]
1246 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1247 [1.0, u"rgb(57, 115, 172)"]]
1249 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1250 [1.0, u"rgb(102, 102, 102)"]]
1253 annotations = list()
1255 text = (u"Test: {name}<br>"
1260 for chain, _ in enumerate(txt_chains):
1262 for node, _ in enumerate(txt_nodes):
1263 if data[chain][node] is not None:
1272 text=str(data[chain][node]),
1280 hover_line.append(text.format(
1281 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1282 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1283 val=data[chain][node],
1284 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1285 hovertext.append(hover_line)
1293 title=plot.get(u"z-axis", u""),
1307 colorscale=my_green,
1313 for idx, item in enumerate(txt_nodes):
1331 for idx, item in enumerate(txt_chains):
1358 text=plot.get(u"x-axis", u""),
1375 text=plot.get(u"y-axis", u""),
1384 updatemenus = list([
1395 u"colorscale": [my_green, ],
1396 u"reversescale": False
1405 u"colorscale": [my_blue, ],
1406 u"reversescale": False
1415 u"colorscale": [my_grey, ],
1416 u"reversescale": False
1427 layout = deepcopy(plot[u"layout"])
1428 except KeyError as err:
1429 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1432 layout[u"annotations"] = annotations
1433 layout[u'updatemenus'] = updatemenus
1437 plpl = plgo.Figure(data=traces, layout=layout)
1440 logging.info(f" Writing file {plot[u'output-file']}.html")
1445 filename=f"{plot[u'output-file']}.html"
1447 except PlotlyError as err:
1449 f" Finished with error: {repr(err)}".replace(u"\n", u" ")