1 # Copyright (c) 2019 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
27 import plotly.offline as ploff
28 import plotly.graph_objs as plgo
30 from plotly.subplots import make_subplots
31 from plotly.exceptions import PlotlyError
33 from pal_utils import mean, stdev
36 COLORS = [u"SkyBlue", u"Olive", u"Purple", u"Coral", u"Indigo", u"Pink",
37 u"Chocolate", u"Brown", u"Magenta", u"Cyan", u"Orange", u"Black",
38 u"Violet", u"Blue", u"Yellow", u"BurlyWood", u"CadetBlue", u"Crimson",
39 u"DarkBlue", u"DarkCyan", u"DarkGreen", u"Green", u"GoldenRod",
40 u"LightGreen", u"LightSeaGreen", u"LightSkyBlue", u"Maroon",
41 u"MediumSeaGreen", u"SeaGreen", u"LightSlateGrey"]
43 REGEX_NIC = re.compile(r'\d*ge\dp\d\D*\d*-')
46 def generate_plots(spec, data):
47 """Generate all plots specified in the specification file.
49 :param spec: Specification read from the specification file.
50 :param data: Data to process.
51 :type spec: Specification
56 u"plot_nf_reconf_box_name": plot_nf_reconf_box_name,
57 u"plot_perf_box_name": plot_perf_box_name,
58 u"plot_lat_err_bars_name": plot_lat_err_bars_name,
59 u"plot_tsa_name": plot_tsa_name,
60 u"plot_http_server_perf_box": plot_http_server_perf_box,
61 u"plot_nf_heatmap": plot_nf_heatmap,
62 u"plot_lat_hdrh_bar_name": plot_lat_hdrh_bar_name
65 logging.info(u"Generating the plots ...")
66 for index, plot in enumerate(spec.plots):
68 logging.info(f" Plot nr {index + 1}: {plot.get(u'title', u'')}")
69 plot[u"limits"] = spec.configuration[u"limits"]
70 generator[plot[u"algorithm"]](plot, data)
71 logging.info(u" Done.")
72 except NameError as err:
74 f"Probably algorithm {plot[u'algorithm']} is not defined: "
77 logging.info(u"Done.")
80 def plot_lat_hdrh_bar_name(plot, input_data):
81 """Generate the plot(s) with algorithm: plot_lat_hdrh_bar_name
82 specified in the specification file.
84 :param plot: Plot to generate.
85 :param input_data: Data to process.
86 :type plot: pandas.Series
87 :type input_data: InputData
91 plot_title = plot.get(u"title", u"")
93 f" Creating the data set for the {plot.get(u'type', u'')} "
96 data = input_data.filter_tests_by_name(
97 plot, params=[u"latency", u"parent", u"tags", u"type"])
98 if data is None or len(data[0][0]) == 0:
99 logging.error(u"No data.")
102 # Prepare the data for the plot
103 directions = [u"W-E", u"E-W"]
106 for idx_row, test in enumerate(data[0][0]):
108 if test[u"type"] in (u"NDRPDR",):
109 if u"-pdr" in plot_title.lower():
111 elif u"-ndr" in plot_title.lower():
114 logging.warning(f"Invalid test type: {test[u'type']}")
116 name = re.sub(REGEX_NIC, u"", test[u"parent"].
117 replace(u'-ndrpdr', u'').
118 replace(u'2n1l-', u''))
120 for idx_col, direction in enumerate(
121 (u"direction1", u"direction2", )):
123 hdr_lat = test[u"latency"][ttype][direction][u"hdrh"]
124 # TODO: Workaround, HDRH data must be aligned to 4
125 # bytes, remove when not needed.
126 hdr_lat += u"=" * (len(hdr_lat) % 4)
130 decoded = hdrh.histogram.HdrHistogram.decode(hdr_lat)
131 total_count = decoded.get_total_count()
132 for item in decoded.get_recorded_iterator():
133 xaxis.append(item.value_iterated_to)
134 prob = float(item.count_added_in_this_iter_step) / \
139 f"Direction: {directions[idx_col]}<br>"
140 f"Latency: {item.value_iterated_to}uSec<br>"
141 f"Probability: {prob:.2f}%<br>"
143 f"{item.percentile_level_iterated_to:.2f}"
145 marker_color = [COLORS[idx_row], ] * len(yaxis)
146 marker_color[xaxis.index(
147 decoded.get_value_at_percentile(50.0))] = u"red"
148 marker_color[xaxis.index(
149 decoded.get_value_at_percentile(90.0))] = u"red"
150 marker_color[xaxis.index(
151 decoded.get_value_at_percentile(95.0))] = u"red"
158 marker={u"color": marker_color},
163 except hdrh.codec.HdrLengthException as err:
165 f"No or invalid data for HDRHistogram for the test "
169 if len(histograms) == 2:
170 traces.append(histograms)
173 logging.warning(f"Invalid test type: {test[u'type']}")
175 except (ValueError, KeyError) as err:
176 logging.warning(repr(err))
179 logging.warning(f"No data for {plot_title}.")
186 [{u"type": u"bar"}, {u"type": u"bar"}] for _ in range(len(tests))
191 gridcolor=u"rgb(220, 220, 220)",
192 linecolor=u"rgb(220, 220, 220)",
197 tickcolor=u"rgb(220, 220, 220)",
200 for idx_row, test in enumerate(tests):
201 for idx_col in range(2):
203 traces[idx_row][idx_col],
218 layout = deepcopy(plot[u"layout"])
220 layout[u"title"][u"text"] = \
221 f"<b>Latency:</b> {plot.get(u'graph-title', u'')}"
222 layout[u"height"] = 250 * len(tests) + 130
224 layout[u"annotations"][2][u"y"] = 1.06 - 0.008 * len(tests)
225 layout[u"annotations"][3][u"y"] = 1.06 - 0.008 * len(tests)
227 for idx, test in enumerate(tests):
228 layout[u"annotations"].append({
233 u"text": f"<b>{test}</b>",
236 u"xanchor": u"center",
238 u"y": 1.0 - float(idx) * 1.06 / len(tests),
239 u"yanchor": u"bottom",
243 fig[u"layout"].update(layout)
246 file_type = plot.get(u"output-file-type", u".html")
247 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
250 ploff.plot(fig, show_link=False, auto_open=False,
251 filename=f"{plot[u'output-file']}{file_type}")
252 except PlotlyError as err:
253 logging.error(f" Finished with error: {repr(err)}")
256 def plot_nf_reconf_box_name(plot, input_data):
257 """Generate the plot(s) with algorithm: plot_nf_reconf_box_name
258 specified in the specification file.
260 :param plot: Plot to generate.
261 :param input_data: Data to process.
262 :type plot: pandas.Series
263 :type input_data: InputData
268 f" Creating the data set for the {plot.get(u'type', u'')} "
269 f"{plot.get(u'title', u'')}."
271 data = input_data.filter_tests_by_name(
272 plot, params=[u"result", u"parent", u"tags", u"type"]
275 logging.error(u"No data.")
278 # Prepare the data for the plot
279 y_vals = OrderedDict()
284 if y_vals.get(test[u"parent"], None) is None:
285 y_vals[test[u"parent"]] = list()
286 loss[test[u"parent"]] = list()
288 y_vals[test[u"parent"]].append(test[u"result"][u"time"])
289 loss[test[u"parent"]].append(test[u"result"][u"loss"])
290 except (KeyError, TypeError):
291 y_vals[test[u"parent"]].append(None)
293 # Add None to the lists with missing data
295 nr_of_samples = list()
296 for val in y_vals.values():
297 if len(val) > max_len:
299 nr_of_samples.append(len(val))
300 for val in y_vals.values():
301 if len(val) < max_len:
302 val.extend([None for _ in range(max_len - len(val))])
306 df_y = pd.DataFrame(y_vals)
308 for i, col in enumerate(df_y.columns):
309 tst_name = re.sub(REGEX_NIC, u"",
310 col.lower().replace(u'-ndrpdr', u'').
311 replace(u'2n1l-', u''))
313 traces.append(plgo.Box(
314 x=[str(i + 1) + u'.'] * len(df_y[col]),
315 y=[y if y else None for y in df_y[col]],
318 f"({nr_of_samples[i]:02d} "
319 f"run{u's' if nr_of_samples[i] > 1 else u''}, "
320 f"packets lost average: {mean(loss[col]):.1f}) "
321 f"{u'-'.join(tst_name.split(u'-')[3:-2])}"
327 layout = deepcopy(plot[u"layout"])
328 layout[u"title"] = f"<b>Time Lost:</b> {layout[u'title']}"
329 layout[u"yaxis"][u"title"] = u"<b>Implied Time Lost [s]</b>"
330 layout[u"legend"][u"font"][u"size"] = 14
331 layout[u"yaxis"].pop(u"range")
332 plpl = plgo.Figure(data=traces, layout=layout)
335 file_type = plot.get(u"output-file-type", u".html")
336 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
341 filename=f"{plot[u'output-file']}{file_type}"
343 except PlotlyError as err:
345 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
350 def plot_perf_box_name(plot, input_data):
351 """Generate the plot(s) with algorithm: plot_perf_box_name
352 specified in the specification file.
354 :param plot: Plot to generate.
355 :param input_data: Data to process.
356 :type plot: pandas.Series
357 :type input_data: InputData
362 f" Creating data set for the {plot.get(u'type', u'')} "
363 f"{plot.get(u'title', u'')}."
365 data = input_data.filter_tests_by_name(
366 plot, params=[u"throughput", u"parent", u"tags", u"type"])
368 logging.error(u"No data.")
371 # Prepare the data for the plot
372 y_vals = OrderedDict()
376 if y_vals.get(test[u"parent"], None) is None:
377 y_vals[test[u"parent"]] = list()
379 if (test[u"type"] in (u"NDRPDR", ) and
380 u"-pdr" in plot.get(u"title", u"").lower()):
381 y_vals[test[u"parent"]].\
382 append(test[u"throughput"][u"PDR"][u"LOWER"])
383 elif (test[u"type"] in (u"NDRPDR", ) and
384 u"-ndr" in plot.get(u"title", u"").lower()):
385 y_vals[test[u"parent"]]. \
386 append(test[u"throughput"][u"NDR"][u"LOWER"])
387 elif test[u"type"] in (u"SOAK", ):
388 y_vals[test[u"parent"]].\
389 append(test[u"throughput"][u"LOWER"])
392 except (KeyError, TypeError):
393 y_vals[test[u"parent"]].append(None)
395 # Add None to the lists with missing data
397 nr_of_samples = list()
398 for val in y_vals.values():
399 if len(val) > max_len:
401 nr_of_samples.append(len(val))
402 for val in y_vals.values():
403 if len(val) < max_len:
404 val.extend([None for _ in range(max_len - len(val))])
408 df_y = pd.DataFrame(y_vals)
411 for i, col in enumerate(df_y.columns):
412 tst_name = re.sub(REGEX_NIC, u"",
413 col.lower().replace(u'-ndrpdr', u'').
414 replace(u'2n1l-', u''))
417 x=[str(i + 1) + u'.'] * len(df_y[col]),
418 y=[y / 1000000 if y else None for y in df_y[col]],
421 f"({nr_of_samples[i]:02d} "
422 f"run{u's' if nr_of_samples[i] > 1 else u''}) "
429 val_max = max(df_y[col])
431 y_max.append(int(val_max / 1000000) + 2)
432 except (ValueError, TypeError) as err:
433 logging.error(repr(err))
438 layout = deepcopy(plot[u"layout"])
439 if layout.get(u"title", None):
440 layout[u"title"] = f"<b>Throughput:</b> {layout[u'title']}"
442 layout[u"yaxis"][u"range"] = [0, max(y_max)]
443 plpl = plgo.Figure(data=traces, layout=layout)
446 logging.info(f" Writing file {plot[u'output-file']}.html.")
451 filename=f"{plot[u'output-file']}.html"
453 except PlotlyError as err:
455 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
460 def plot_lat_err_bars_name(plot, input_data):
461 """Generate the plot(s) with algorithm: plot_lat_err_bars_name
462 specified in the specification file.
464 :param plot: Plot to generate.
465 :param input_data: Data to process.
466 :type plot: pandas.Series
467 :type input_data: InputData
471 plot_title = plot.get(u"title", u"")
473 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
475 data = input_data.filter_tests_by_name(
476 plot, params=[u"latency", u"parent", u"tags", u"type"])
478 logging.error(u"No data.")
481 # Prepare the data for the plot
482 y_tmp_vals = OrderedDict()
487 logging.debug(f"test[u'latency']: {test[u'latency']}\n")
488 except ValueError as err:
489 logging.warning(repr(err))
490 if y_tmp_vals.get(test[u"parent"], None) is None:
491 y_tmp_vals[test[u"parent"]] = [
492 list(), # direction1, min
493 list(), # direction1, avg
494 list(), # direction1, max
495 list(), # direction2, min
496 list(), # direction2, avg
497 list() # direction2, max
500 if test[u"type"] not in (u"NDRPDR", ):
501 logging.warning(f"Invalid test type: {test[u'type']}")
503 if u"-pdr" in plot_title.lower():
505 elif u"-ndr" in plot_title.lower():
509 f"Invalid test type: {test[u'type']}"
512 y_tmp_vals[test[u"parent"]][0].append(
513 test[u"latency"][ttype][u"direction1"][u"min"])
514 y_tmp_vals[test[u"parent"]][1].append(
515 test[u"latency"][ttype][u"direction1"][u"avg"])
516 y_tmp_vals[test[u"parent"]][2].append(
517 test[u"latency"][ttype][u"direction1"][u"max"])
518 y_tmp_vals[test[u"parent"]][3].append(
519 test[u"latency"][ttype][u"direction2"][u"min"])
520 y_tmp_vals[test[u"parent"]][4].append(
521 test[u"latency"][ttype][u"direction2"][u"avg"])
522 y_tmp_vals[test[u"parent"]][5].append(
523 test[u"latency"][ttype][u"direction2"][u"max"])
524 except (KeyError, TypeError) as err:
525 logging.warning(repr(err))
531 nr_of_samples = list()
532 for key, val in y_tmp_vals.items():
533 name = re.sub(REGEX_NIC, u"", key.replace(u'-ndrpdr', u'').
534 replace(u'2n1l-', u''))
535 x_vals.append(name) # dir 1
536 y_vals.append(mean(val[1]) if val[1] else None)
537 y_mins.append(mean(val[0]) if val[0] else None)
538 y_maxs.append(mean(val[2]) if val[2] else None)
539 nr_of_samples.append(len(val[1]) if val[1] else 0)
540 x_vals.append(name) # dir 2
541 y_vals.append(mean(val[4]) if val[4] else None)
542 y_mins.append(mean(val[3]) if val[3] else None)
543 y_maxs.append(mean(val[5]) if val[5] else None)
544 nr_of_samples.append(len(val[3]) if val[3] else 0)
549 for idx, _ in enumerate(x_vals):
550 if not bool(int(idx % 2)):
551 direction = u"West-East"
553 direction = u"East-West"
555 f"No. of Runs: {nr_of_samples[idx]}<br>"
556 f"Test: {x_vals[idx]}<br>"
557 f"Direction: {direction}<br>"
559 if isinstance(y_maxs[idx], float):
560 hovertext += f"Max: {y_maxs[idx]:.2f}uSec<br>"
561 if isinstance(y_vals[idx], float):
562 hovertext += f"Mean: {y_vals[idx]:.2f}uSec<br>"
563 if isinstance(y_mins[idx], float):
564 hovertext += f"Min: {y_mins[idx]:.2f}uSec"
566 if isinstance(y_maxs[idx], float) and isinstance(y_vals[idx], float):
567 array = [y_maxs[idx] - y_vals[idx], ]
570 if isinstance(y_mins[idx], float) and isinstance(y_vals[idx], float):
571 arrayminus = [y_vals[idx] - y_mins[idx], ]
573 arrayminus = [None, ]
574 traces.append(plgo.Scatter(
578 legendgroup=x_vals[idx],
579 showlegend=bool(int(idx % 2)),
585 arrayminus=arrayminus,
586 color=COLORS[int(idx / 2)]
590 color=COLORS[int(idx / 2)],
595 annotations.append(dict(
602 text=u"E-W" if bool(int(idx % 2)) else u"W-E",
612 file_type = plot.get(u"output-file-type", u".html")
613 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
614 layout = deepcopy(plot[u"layout"])
615 if layout.get(u"title", None):
616 layout[u"title"] = f"<b>Latency:</b> {layout[u'title']}"
617 layout[u"annotations"] = annotations
618 plpl = plgo.Figure(data=traces, layout=layout)
623 show_link=False, auto_open=False,
624 filename=f"{plot[u'output-file']}{file_type}"
626 except PlotlyError as err:
628 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
633 def plot_tsa_name(plot, input_data):
634 """Generate the plot(s) with algorithm:
636 specified in the specification file.
638 :param plot: Plot to generate.
639 :param input_data: Data to process.
640 :type plot: pandas.Series
641 :type input_data: InputData
645 plot_title = plot.get(u"title", u"")
647 f" Creating data set for the {plot.get(u'type', u'')} {plot_title}."
649 data = input_data.filter_tests_by_name(
650 plot, params=[u"throughput", u"parent", u"tags", u"type"])
652 logging.error(u"No data.")
655 y_vals = OrderedDict()
659 if y_vals.get(test[u"parent"], None) is None:
660 y_vals[test[u"parent"]] = {
666 if test[u"type"] not in (u"NDRPDR",):
669 if u"-pdr" in plot_title.lower():
671 elif u"-ndr" in plot_title.lower():
676 if u"1C" in test[u"tags"]:
677 y_vals[test[u"parent"]][u"1"]. \
678 append(test[u"throughput"][ttype][u"LOWER"])
679 elif u"2C" in test[u"tags"]:
680 y_vals[test[u"parent"]][u"2"]. \
681 append(test[u"throughput"][ttype][u"LOWER"])
682 elif u"4C" in test[u"tags"]:
683 y_vals[test[u"parent"]][u"4"]. \
684 append(test[u"throughput"][ttype][u"LOWER"])
685 except (KeyError, TypeError):
689 logging.warning(f"No data for the plot {plot.get(u'title', u'')}")
693 for test_name, test_vals in y_vals.items():
694 for key, test_val in test_vals.items():
696 avg_val = sum(test_val) / len(test_val)
697 y_vals[test_name][key] = [avg_val, len(test_val)]
698 ideal = avg_val / (int(key) * 1000000.0)
699 if test_name not in y_1c_max or ideal > y_1c_max[test_name]:
700 y_1c_max[test_name] = ideal
706 pci_limit = plot[u"limits"][u"pci"][u"pci-g3-x8"]
707 for test_name, test_vals in y_vals.items():
709 if test_vals[u"1"][1]:
713 test_name.replace(u'-ndrpdr', u'').replace(u'2n1l-', u'')
715 vals[name] = OrderedDict()
716 y_val_1 = test_vals[u"1"][0] / 1000000.0
717 y_val_2 = test_vals[u"2"][0] / 1000000.0 if test_vals[u"2"][0] \
719 y_val_4 = test_vals[u"4"][0] / 1000000.0 if test_vals[u"4"][0] \
722 vals[name][u"val"] = [y_val_1, y_val_2, y_val_4]
723 vals[name][u"rel"] = [1.0, None, None]
724 vals[name][u"ideal"] = [
726 y_1c_max[test_name] * 2,
727 y_1c_max[test_name] * 4
729 vals[name][u"diff"] = [
730 (y_val_1 - y_1c_max[test_name]) * 100 / y_val_1, None, None
732 vals[name][u"count"] = [
739 val_max = max(vals[name][u"val"])
740 except ValueError as err:
741 logging.error(repr(err))
744 y_max.append(val_max)
747 vals[name][u"rel"][1] = round(y_val_2 / y_val_1, 2)
748 vals[name][u"diff"][1] = \
749 (y_val_2 - vals[name][u"ideal"][1]) * 100 / y_val_2
751 vals[name][u"rel"][2] = round(y_val_4 / y_val_1, 2)
752 vals[name][u"diff"][2] = \
753 (y_val_4 - vals[name][u"ideal"][2]) * 100 / y_val_4
754 except IndexError as err:
755 logging.warning(f"No data for {test_name}")
756 logging.warning(repr(err))
759 if u"x520" in test_name:
760 limit = plot[u"limits"][u"nic"][u"x520"]
761 elif u"x710" in test_name:
762 limit = plot[u"limits"][u"nic"][u"x710"]
763 elif u"xxv710" in test_name:
764 limit = plot[u"limits"][u"nic"][u"xxv710"]
765 elif u"xl710" in test_name:
766 limit = plot[u"limits"][u"nic"][u"xl710"]
767 elif u"x553" in test_name:
768 limit = plot[u"limits"][u"nic"][u"x553"]
771 if limit > nic_limit:
774 mul = 2 if u"ge2p" in test_name else 1
775 if u"10ge" in test_name:
776 limit = plot[u"limits"][u"link"][u"10ge"] * mul
777 elif u"25ge" in test_name:
778 limit = plot[u"limits"][u"link"][u"25ge"] * mul
779 elif u"40ge" in test_name:
780 limit = plot[u"limits"][u"link"][u"40ge"] * mul
781 elif u"100ge" in test_name:
782 limit = plot[u"limits"][u"link"][u"100ge"] * mul
785 if limit > lnk_limit:
794 threshold = 1.1 * max(y_max) # 10%
795 except ValueError as err:
798 nic_limit /= 1000000.0
799 traces.append(plgo.Scatter(
801 y=[nic_limit, ] * len(x_vals),
802 name=f"NIC: {nic_limit:.2f}Mpps",
811 annotations.append(dict(
818 text=f"NIC: {nic_limit:.2f}Mpps",
826 y_max.append(nic_limit)
828 lnk_limit /= 1000000.0
829 if lnk_limit < threshold:
830 traces.append(plgo.Scatter(
832 y=[lnk_limit, ] * len(x_vals),
833 name=f"Link: {lnk_limit:.2f}Mpps",
842 annotations.append(dict(
849 text=f"Link: {lnk_limit:.2f}Mpps",
857 y_max.append(lnk_limit)
859 pci_limit /= 1000000.0
860 if (pci_limit < threshold and
861 (pci_limit < lnk_limit * 0.95 or lnk_limit > lnk_limit * 1.05)):
862 traces.append(plgo.Scatter(
864 y=[pci_limit, ] * len(x_vals),
865 name=f"PCIe: {pci_limit:.2f}Mpps",
874 annotations.append(dict(
881 text=f"PCIe: {pci_limit:.2f}Mpps",
889 y_max.append(pci_limit)
891 # Perfect and measured:
893 for name, val in vals.items():
896 for idx in range(len(val[u"val"])):
898 if isinstance(val[u"val"][idx], float):
900 f"No. of Runs: {val[u'count'][idx]}<br>"
901 f"Mean: {val[u'val'][idx]:.2f}Mpps<br>"
903 if isinstance(val[u"diff"][idx], float):
904 htext += f"Diff: {round(val[u'diff'][idx]):.0f}%<br>"
905 if isinstance(val[u"rel"][idx], float):
906 htext += f"Speedup: {val[u'rel'][idx]:.2f}"
907 hovertext.append(htext)
914 mode=u"lines+markers",
923 hoverinfo=u"text+name"
930 name=f"{name} perfect",
938 text=[f"Perfect: {y:.2f}Mpps" for y in val[u"ideal"]],
943 except (IndexError, ValueError, KeyError) as err:
944 logging.warning(f"No data for {name}\n{repr(err)}")
948 file_type = plot.get(u"output-file-type", u".html")
949 logging.info(f" Writing file {plot[u'output-file']}{file_type}.")
950 layout = deepcopy(plot[u"layout"])
951 if layout.get(u"title", None):
952 layout[u"title"] = f"<b>Speedup Multi-core:</b> {layout[u'title']}"
953 layout[u"yaxis"][u"range"] = [0, int(max(y_max) * 1.1)]
954 layout[u"annotations"].extend(annotations)
955 plpl = plgo.Figure(data=traces, layout=layout)
962 filename=f"{plot[u'output-file']}{file_type}"
964 except PlotlyError as err:
966 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
971 def plot_http_server_perf_box(plot, input_data):
972 """Generate the plot(s) with algorithm: plot_http_server_perf_box
973 specified in the specification file.
975 :param plot: Plot to generate.
976 :param input_data: Data to process.
977 :type plot: pandas.Series
978 :type input_data: InputData
983 f" Creating the data set for the {plot.get(u'type', u'')} "
984 f"{plot.get(u'title', u'')}."
986 data = input_data.filter_data(plot)
988 logging.error(u"No data.")
991 # Prepare the data for the plot
996 if y_vals.get(test[u"name"], None) is None:
997 y_vals[test[u"name"]] = list()
999 y_vals[test[u"name"]].append(test[u"result"])
1000 except (KeyError, TypeError):
1001 y_vals[test[u"name"]].append(None)
1003 # Add None to the lists with missing data
1005 nr_of_samples = list()
1006 for val in y_vals.values():
1007 if len(val) > max_len:
1009 nr_of_samples.append(len(val))
1010 for val in y_vals.values():
1011 if len(val) < max_len:
1012 val.extend([None for _ in range(max_len - len(val))])
1016 df_y = pd.DataFrame(y_vals)
1018 for i, col in enumerate(df_y.columns):
1021 f"({nr_of_samples[i]:02d} " \
1022 f"run{u's' if nr_of_samples[i] > 1 else u''}) " \
1023 f"{col.lower().replace(u'-ndrpdr', u'')}"
1025 name_lst = name.split(u'-')
1028 for segment in name_lst:
1029 if (len(name) + len(segment) + 1) > 50 and split_name:
1032 name += segment + u'-'
1035 traces.append(plgo.Box(x=[str(i + 1) + u'.'] * len(df_y[col]),
1041 plpl = plgo.Figure(data=traces, layout=plot[u"layout"])
1045 f" Writing file {plot[u'output-file']}"
1046 f"{plot[u'output-file-type']}."
1052 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1054 except PlotlyError as err:
1056 f" Finished with error: {repr(err)}".replace(u"\n", u" ")
1061 def plot_nf_heatmap(plot, input_data):
1062 """Generate the plot(s) with algorithm: plot_nf_heatmap
1063 specified in the specification file.
1065 :param plot: Plot to generate.
1066 :param input_data: Data to process.
1067 :type plot: pandas.Series
1068 :type input_data: InputData
1071 regex_cn = re.compile(r'^(\d*)R(\d*)C$')
1072 regex_test_name = re.compile(r'^.*-(\d+ch|\d+pl)-'
1074 r'(\d+vm\d+t|\d+dcr\d+t).*$')
1077 # Transform the data
1079 f" Creating the data set for the {plot.get(u'type', u'')} "
1080 f"{plot.get(u'title', u'')}."
1082 data = input_data.filter_data(plot, continue_on_error=True)
1083 if data is None or data.empty:
1084 logging.error(u"No data.")
1090 for tag in test[u"tags"]:
1091 groups = re.search(regex_cn, tag)
1093 chain = str(groups.group(1))
1094 node = str(groups.group(2))
1098 groups = re.search(regex_test_name, test[u"name"])
1099 if groups and len(groups.groups()) == 3:
1101 f"{str(groups.group(1))}-"
1102 f"{str(groups.group(2))}-"
1103 f"{str(groups.group(3))}"
1107 if vals.get(chain, None) is None:
1108 vals[chain] = dict()
1109 if vals[chain].get(node, None) is None:
1110 vals[chain][node] = dict(
1118 if plot[u"include-tests"] == u"MRR":
1119 result = test[u"result"][u"receive-rate"]
1120 elif plot[u"include-tests"] == u"PDR":
1121 result = test[u"throughput"][u"PDR"][u"LOWER"]
1122 elif plot[u"include-tests"] == u"NDR":
1123 result = test[u"throughput"][u"NDR"][u"LOWER"]
1130 vals[chain][node][u"vals"].append(result)
1133 logging.error(u"No data.")
1139 txt_chains.append(key_c)
1140 for key_n in vals[key_c].keys():
1141 txt_nodes.append(key_n)
1142 if vals[key_c][key_n][u"vals"]:
1143 vals[key_c][key_n][u"nr"] = len(vals[key_c][key_n][u"vals"])
1144 vals[key_c][key_n][u"mean"] = \
1145 round(mean(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1146 vals[key_c][key_n][u"stdev"] = \
1147 round(stdev(vals[key_c][key_n][u"vals"]) / 1000000, 1)
1148 txt_nodes = list(set(txt_nodes))
1150 def sort_by_int(value):
1151 """Makes possible to sort a list of strings which represent integers.
1153 :param value: Integer as a string.
1155 :returns: Integer representation of input parameter 'value'.
1160 txt_chains = sorted(txt_chains, key=sort_by_int)
1161 txt_nodes = sorted(txt_nodes, key=sort_by_int)
1163 chains = [i + 1 for i in range(len(txt_chains))]
1164 nodes = [i + 1 for i in range(len(txt_nodes))]
1166 data = [list() for _ in range(len(chains))]
1167 for chain in chains:
1170 val = vals[txt_chains[chain - 1]][txt_nodes[node - 1]][u"mean"]
1171 except (KeyError, IndexError):
1173 data[chain - 1].append(val)
1176 my_green = [[0.0, u"rgb(235, 249, 242)"],
1177 [1.0, u"rgb(45, 134, 89)"]]
1179 my_blue = [[0.0, u"rgb(236, 242, 248)"],
1180 [1.0, u"rgb(57, 115, 172)"]]
1182 my_grey = [[0.0, u"rgb(230, 230, 230)"],
1183 [1.0, u"rgb(102, 102, 102)"]]
1186 annotations = list()
1188 text = (u"Test: {name}<br>"
1193 for chain, _ in enumerate(txt_chains):
1195 for node, _ in enumerate(txt_nodes):
1196 if data[chain][node] is not None:
1205 text=str(data[chain][node]),
1213 hover_line.append(text.format(
1214 name=vals[txt_chains[chain]][txt_nodes[node]][u"name"],
1215 nr=vals[txt_chains[chain]][txt_nodes[node]][u"nr"],
1216 val=data[chain][node],
1217 stdev=vals[txt_chains[chain]][txt_nodes[node]][u"stdev"]))
1218 hovertext.append(hover_line)
1226 title=plot.get(u"z-axis", u""),
1240 colorscale=my_green,
1246 for idx, item in enumerate(txt_nodes):
1264 for idx, item in enumerate(txt_chains):
1291 text=plot.get(u"x-axis", u""),
1308 text=plot.get(u"y-axis", u""),
1317 updatemenus = list([
1328 u"colorscale": [my_green, ],
1329 u"reversescale": False
1338 u"colorscale": [my_blue, ],
1339 u"reversescale": False
1348 u"colorscale": [my_grey, ],
1349 u"reversescale": False
1360 layout = deepcopy(plot[u"layout"])
1361 except KeyError as err:
1362 logging.error(f"Finished with error: No layout defined\n{repr(err)}")
1365 layout[u"annotations"] = annotations
1366 layout[u'updatemenus'] = updatemenus
1370 plpl = plgo.Figure(data=traces, layout=layout)
1374 f" Writing file {plot[u'output-file']}"
1375 f"{plot[u'output-file-type']}."
1381 filename=f"{plot[u'output-file']}{plot[u'output-file-type']}"
1383 except PlotlyError as err:
1385 f" Finished with error: {repr(err)}".replace(u"\n", u" ")