From d6c10465c19369715e004dff9dc3c115cbc695a0 Mon Sep 17 00:00:00 2001 From: Samuel Dobron Date: Wed, 30 Oct 2024 08:04:54 +0100 Subject: [PATCH] XDPBenchMeasurement: fixed json formatter `JsonRunSummaryFormatter` requires measurement results to be instance of `MeasurementResult` class. --- .../JsonRunSummaryFormatter.py | 5 ++ .../Perf/Measurements/XDPBenchMeasurement.py | 50 ++++++++++--------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/lnst/Controller/RunSummaryFormatters/JsonRunSummaryFormatter.py b/lnst/Controller/RunSummaryFormatters/JsonRunSummaryFormatter.py index 8436eaca7..1bd9be049 100644 --- a/lnst/Controller/RunSummaryFormatters/JsonRunSummaryFormatter.py +++ b/lnst/Controller/RunSummaryFormatters/JsonRunSummaryFormatter.py @@ -124,6 +124,11 @@ def _transform_result(self, result: BaseResult) -> Optional[dict]: measurement_data = { "bandwidth": result.data["bandwidth"].average, } + elif result.measurement_type == "xdp-bench": + measurement_data = { + "generator_results": result.data["generator_results"].average, + "receiver_results": result.data["receiver_results"].average, + } else: logging.warning(f"unhandled measurement result type: {result.measurement_type}") measurement_data = None diff --git a/lnst/RecipeCommon/Perf/Measurements/XDPBenchMeasurement.py b/lnst/RecipeCommon/Perf/Measurements/XDPBenchMeasurement.py index 2e1687374..e2f51e5d7 100644 --- a/lnst/RecipeCommon/Perf/Measurements/XDPBenchMeasurement.py +++ b/lnst/RecipeCommon/Perf/Measurements/XDPBenchMeasurement.py @@ -1,6 +1,7 @@ import time import logging +from lnst.Controller.Recipe import BaseRecipe from lnst.RecipeCommon.Perf.Measurements.Results.AggregatedXDPBenchMeasurementResults import ( AggregatedXDPBenchMeasurementResults, ) @@ -21,6 +22,7 @@ from lnst.Tests.PktGen import PktGen from lnst.Tests.XDPBench import XDPBench from lnst.Controller.Job import Job +from lnst.Controller.RecipeResults import MeasurementResult from lnst.RecipeCommon.Perf.Measurements.BaseFlowMeasurement import BaseFlowMeasurement @@ -186,26 +188,28 @@ def _aggregate_flows(self, old_flow, new_flow): return new_result @classmethod - def _report_flow_results(cls, recipe, flow_results): - generator = flow_results.generator_results - receiver = flow_results.receiver_results - - desc = [] - desc.append(flow_results.describe()) - - recipe_result = ResultType.PASS - metrics = {"Generator": generator, "Receiver": receiver} - for name, result in metrics.items(): - if cls._invalid_flow_duration(result): - recipe_result = ResultType.FAIL - desc.append("{} has invalid duration!".format(name)) - - recipe.add_result( - recipe_result, - "\n".join(desc), - data=dict( - generator_flow_data=generator, - receiver_flow_data=receiver, - flow_results=flow_results, - ), - ) + def report_results(cls, recipe: BaseRecipe, results: list[AggregatedXDPBenchMeasurementResults]): + for result in results: + generator = result.generator_results + receiver = result.receiver_results + + desc = [] + desc.append(result.describe()) + + recipe_result = ResultType.PASS + metrics = {"Generator": generator, "Receiver": receiver} + for name, result in metrics.items(): + if cls._invalid_flow_duration(result): + recipe_result = ResultType.FAIL + desc.append("{} has invalid duration!".format(name)) + + recipe_result = MeasurementResult( + "xdp-bench", + description="\n".join(desc), + data={ + "generator_results": generator, + "receiver_results": receiver, + "flow_results": result, + }, + ) + recipe.add_custom_result(recipe_result)