aboutsummaryrefslogtreecommitdiff
path: root/cros_utils/tabulator.py
diff options
context:
space:
mode:
Diffstat (limited to 'cros_utils/tabulator.py')
-rw-r--r--cros_utils/tabulator.py100
1 files changed, 54 insertions, 46 deletions
diff --git a/cros_utils/tabulator.py b/cros_utils/tabulator.py
index 300c2d79..1a3fd4a7 100644
--- a/cros_utils/tabulator.py
+++ b/cros_utils/tabulator.py
@@ -64,12 +64,13 @@ table:
from __future__ import division
from __future__ import print_function
+import collections
import getpass
import math
+import statistics
import sys
-# TODO(zhizhouy): Drop numpy in the future
+# TODO(crbug.com/980719): Drop scipy in the future.
# pylint: disable=import-error
-import numpy
import scipy
from cros_utils.email_sender import EmailSender
@@ -112,21 +113,22 @@ class TableGenerator(object):
SORT_BY_KEYS_DESC = 1
SORT_BY_VALUES = 2
SORT_BY_VALUES_DESC = 3
+ NO_SORT = 4
MISSING_VALUE = 'x'
- def __init__(self, d, l, sort=SORT_BY_KEYS, key_name='keys'):
+ def __init__(self, d, l, sort=NO_SORT, key_name='keys'):
self._runs = d
self._labels = l
self._sort = sort
self._key_name = key_name
def _AggregateKeys(self):
- keys = set([])
+ keys = collections.OrderedDict()
for run_list in self._runs:
for run in run_list:
- keys = keys.union(run.keys())
- return keys
+ keys.update(dict.fromkeys(run.keys()))
+ return list(keys.keys())
def _GetHighestValue(self, key):
values = []
@@ -159,6 +161,8 @@ class TableGenerator(object):
elif self._sort == self.SORT_BY_VALUES_DESC:
# pylint: disable=unnecessary-lambda
return sorted(keys, key=lambda x: self._GetHighestValue(x), reverse=True)
+ elif self._sort == self.NO_SORT:
+ return keys
else:
assert 0, 'Unimplemented sort %s' % self._sort
@@ -295,8 +299,8 @@ class SamplesTableGenerator(TableGenerator):
all_runs_empty = all(not dict for label in bench_runs for dict in label)
if all_runs_empty:
cell = Cell()
- cell.string_value = 'Benchmark %s contains no result.' + \
- ' Is the benchmark name valid?' % k
+ cell.string_value = ('Benchmark %s contains no result.'
+ ' Is the benchmark name valid?' % k)
table.append([cell])
else:
row = [k]
@@ -318,7 +322,7 @@ class SamplesTableGenerator(TableGenerator):
v.append(None)
run_fail += 1
one_tuple = ((run_pass, run_fail), v)
- if iterations != 0 and iterations != run_pass + run_fail:
+ if iterations not in (0, run_pass + run_fail):
raise ValueError('Iterations of each benchmark run ' \
'are not the same')
iterations = run_pass + run_fail
@@ -358,7 +362,7 @@ class SamplesTableGenerator(TableGenerator):
# Accumulate each run result to composite benchmark run
# If any run fails, then we set this run for composite benchmark
# to None so that we know it fails.
- if bench_runs[index] and row[label_index][index] != None:
+ if bench_runs[index] and row[label_index][index] is not None:
row[label_index][index] += bench_runs[index]
else:
row[label_index][index] = None
@@ -552,17 +556,15 @@ class AmeanResult(StringMeanResult):
def _ComputeFloat(self, cell, values, baseline_values):
if self.ignore_min_max:
values = _RemoveMinMax(cell, values)
- cell.value = numpy.mean(values)
+ cell.value = statistics.mean(values)
class RawResult(Result):
"""Raw result."""
- pass
class IterationResult(Result):
"""Iteration result."""
- pass
class MinResult(Result):
@@ -608,7 +610,7 @@ class StdResult(NumericalResult):
def _ComputeFloat(self, cell, values, baseline_values):
if self.ignore_min_max:
values = _RemoveMinMax(cell, values)
- cell.value = numpy.std(values)
+ cell.value = statistics.pstdev(values)
class CoeffVarResult(NumericalResult):
@@ -621,8 +623,8 @@ class CoeffVarResult(NumericalResult):
def _ComputeFloat(self, cell, values, baseline_values):
if self.ignore_min_max:
values = _RemoveMinMax(cell, values)
- if numpy.mean(values) != 0.0:
- noise = numpy.abs(numpy.std(values) / numpy.mean(values))
+ if statistics.mean(values) != 0.0:
+ noise = abs(statistics.pstdev(values) / statistics.mean(values))
else:
noise = 0.0
cell.value = noise
@@ -707,7 +709,7 @@ class KeyAwareComparisonResult(ComparisonResult):
'dropped_percent', '(ms)', '(seconds)', '--ms',
'--average_num_missing_tiles', '--experimental_jank',
'--experimental_mean_frame', '--experimental_median_frame_time',
- '--total_deferred_image_decode_count', '--seconds', 'samples'
+ '--total_deferred_image_decode_count', '--seconds', 'samples', 'bytes'
]
return any([l in key for l in lower_is_better_keys])
@@ -729,9 +731,12 @@ class AmeanRatioResult(KeyAwareComparisonResult):
if self.ignore_min_max:
values = _RemoveMinMax(cell, values)
baseline_values = _RemoveMinMax(cell, baseline_values)
- if numpy.mean(baseline_values) != 0:
- cell.value = numpy.mean(values) / numpy.mean(baseline_values)
- elif numpy.mean(values) != 0:
+
+ baseline_mean = statistics.mean(baseline_values)
+ values_mean = statistics.mean(values)
+ if baseline_mean != 0:
+ cell.value = values_mean / baseline_mean
+ elif values_mean != 0:
cell.value = 0.00
# cell.value = 0 means the values and baseline_values have big difference
else:
@@ -1148,8 +1153,10 @@ class TableFormatter(object):
result_name = column.result.__class__.__name__
format_name = column.fmt.__class__.__name__
- cell.string_value = '%s %s' % (result_name.replace('Result', ''),
- format_name.replace('Format', ''))
+ cell.string_value = '%s %s' % (
+ result_name.replace('Result', ''),
+ format_name.replace('Format', ''),
+ )
header.append(cell)
@@ -1491,7 +1498,7 @@ def GetComplexTable(runs, labels, out_to=TablePrinter.CONSOLE):
if __name__ == '__main__':
# Run a few small tests here.
- runs = [[{
+ run1 = {
'k1': '10',
'k2': '12',
'k5': '40',
@@ -1501,29 +1508,30 @@ if __name__ == '__main__':
'k8': 'PASS',
'k9': 'PASS',
'k10': '0'
- },
- {
- 'k1': '13',
- 'k2': '14',
- 'k3': '15',
- 'ms_1': '10',
- 'k8': 'PASS',
- 'k9': 'FAIL',
- 'k10': '0'
- }],
- [{
- 'k1': '50',
- 'k2': '51',
- 'k3': '52',
- 'k4': '53',
- 'k5': '35',
- 'k6': '45',
- 'ms_1': '200',
- 'ms_2': '20',
- 'k7': 'FAIL',
- 'k8': 'PASS',
- 'k9': 'PASS'
- }]]
+ }
+ run2 = {
+ 'k1': '13',
+ 'k2': '14',
+ 'k3': '15',
+ 'ms_1': '10',
+ 'k8': 'PASS',
+ 'k9': 'FAIL',
+ 'k10': '0'
+ }
+ run3 = {
+ 'k1': '50',
+ 'k2': '51',
+ 'k3': '52',
+ 'k4': '53',
+ 'k5': '35',
+ 'k6': '45',
+ 'ms_1': '200',
+ 'ms_2': '20',
+ 'k7': 'FAIL',
+ 'k8': 'PASS',
+ 'k9': 'PASS'
+ }
+ runs = [[run1, run2], [run3]]
labels = ['vanilla', 'modified']
t = GetComplexTable(runs, labels, TablePrinter.CONSOLE)
print(t)