Merge "Display variance and max deviation on iperf result"
diff --git a/acts/framework/acts/test_utils/power/IperfHelper.py b/acts/framework/acts/test_utils/power/IperfHelper.py
index 876ade8..d95183a 100644
--- a/acts/framework/acts/test_utils/power/IperfHelper.py
+++ b/acts/framework/acts/test_utils/power/IperfHelper.py
@@ -15,7 +15,7 @@
# limitations under the License.
import os
-import math
+import statistics
import acts.controllers.iperf_server as ipf
@@ -92,15 +92,26 @@
try:
iperf_result = ipf.IPerfResult(iperf_file)
- # Compute the throughput in Mbit/s
- throughput = (math.fsum(
- iperf_result.instantaneous_rates[self.start_meas_time:-1]
- ) / len(iperf_result.instantaneous_rates[self.start_meas_time:-1])
- ) * 8 * (1.024**2)
+ # Get instantaneous rates after measuring starts
+ samples = iperf_result.instantaneous_rates[self.start_meas_time:-1]
- log.info('The average throughput is {}'.format(throughput))
+ # Convert values to Mbit/s
+ samples = [rate * 8 * (1.024**2) for rate in samples]
+
+ # compute mean, var and max_dev
+ mean = statistics.mean(samples)
+ var = statistics.variance(samples)
+ max_dev = 0
+ for rate in samples:
+ if abs(rate - mean) > max_dev:
+ max_dev = abs(rate - mean)
+
+ log.info('The average throughput is {}. Variance is {} and max '
+ 'deviation is {}.'.format(
+ round(mean, 2), round(var, 2), round(max_dev, 2)))
except:
- log.warning('Cannot get iperf result. Setting to 0')
- throughput = 0
- return throughput
+ log.warning('Cannot get iperf result.')
+ mean = 0
+
+ return mean