From: Ondrej Lichtner olichtne@redhat.com
Instread of throwing an exception we should simply return a float infinity value so that it propagates all the way to the user.
Same exception could also be raised by the BaseFlowMeasurement "report" methods while calculating the percentage of the standard deviation out of the average value.
A helper method was utilized to calculate the percentage for all of the measured values.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com --- .../Perf/Measurements/BaseFlowMeasurement.py | 11 +++++++++-- lnst/RecipeCommon/Perf/Results.py | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/lnst/RecipeCommon/Perf/Measurements/BaseFlowMeasurement.py b/lnst/RecipeCommon/Perf/Measurements/BaseFlowMeasurement.py index 14f0661..9890ed2 100644 --- a/lnst/RecipeCommon/Perf/Measurements/BaseFlowMeasurement.py +++ b/lnst/RecipeCommon/Perf/Measurements/BaseFlowMeasurement.py @@ -198,7 +198,7 @@ def _report_flow_results(cls, recipe, flow_results): desc.append("Generator measured throughput: {tput:.2f} +-{deviation:.2f}({percentage:.2f}%) {unit} per second." .format(tput=generator.average, deviation=generator.std_deviation, - percentage=(generator.std_deviation/generator.average) * 100, + percentage=cls._deviation_percentage(generator), unit=generator.unit)) desc.append("Generator process CPU data: {cpu:.2f} +-{cpu_deviation:.2f} {cpu_unit} per second." .format(cpu=generator_cpu.average, @@ -207,7 +207,7 @@ def _report_flow_results(cls, recipe, flow_results): desc.append("Receiver measured throughput: {tput:.2f} +-{deviation:.2f}({percentage:.2}%) {unit} per second." .format(tput=receiver.average, deviation=receiver.std_deviation, - percentage=(receiver.std_deviation/receiver.average) * 100, + percentage=cls._deviation_percentage(receiver), unit=receiver.unit)) desc.append("Receiver process CPU data: {cpu:.2f} +-{cpu_deviation:.2f} {cpu_unit} per second." .format(cpu=receiver_cpu.average, @@ -238,3 +238,10 @@ def _aggregate_flows(self, old_flow, new_flow): new_result.add_results(old_flow) new_result.add_results(new_flow) return new_result + + @classmethod + def _deviation_percentage(cls, result): + try: + return (result.std_deviation/result.average) * 100 + except ZeroDivisionError: + return float('inf') if result.std_deviation >= 0 else float("-inf") diff --git a/lnst/RecipeCommon/Perf/Results.py b/lnst/RecipeCommon/Perf/Results.py index 1b44cde..4519fb8 100644 --- a/lnst/RecipeCommon/Perf/Results.py +++ b/lnst/RecipeCommon/Perf/Results.py @@ -4,7 +4,10 @@ class PerfStatMixin(object): @property def average(self): - return float(self.value) / self.duration + try: + return float(self.value) / self.duration + except ZeroDivisionError: + return float('inf') if self.value >= 0 else float('-inf')
@property def std_deviation(self):