oeqa.buildperf: store measurements as a dict (object) in the JSON report

Store measurements as a dict, instead of an array, in the JSON report.
This change makes traversing of the report much easier. The change also
disallows identically named measurements under one test, as a sanity
check for the test cases.

[YOCTO #10590]

(From OE-Core rev: 81065092f38c9631dcf5917d70a25809a21de5f4)

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Markus Lehtonen 2017-01-19 12:16:45 +02:00 committed by Richard Purdie
parent 7171710acd
commit f4c96ea829
1 changed files with 11 additions and 4 deletions

View File

@ -214,7 +214,7 @@ class BuildPerfTestResult(unittest.TextTestResult):
elif status not in ('SUCCESS', 'UNEXPECTED_SUCCESS'):
raise TypeError("BUG: invalid test status '%s'" % status)
for data in test.measurements:
for data in test.measurements.values():
measurement = ET.SubElement(testcase, data['type'])
measurement.set('name', data['name'])
measurement.set('legend', data['legend'])
@ -255,7 +255,7 @@ class BuildPerfTestCase(unittest.TestCase):
self.base_dir = None
self.start_time = None
self.elapsed_time = None
self.measurements = []
self.measurements = OrderedDict()
# self.err is supposed to be a tuple from sys.exc_info()
self.err = None
self.bb_vars = get_bb_vars()
@ -298,6 +298,13 @@ class BuildPerfTestCase(unittest.TestCase):
log.error("Command failed: %s", err.retcode)
raise
def _append_measurement(self, measurement):
"""Simple helper for adding measurements results"""
if measurement['name'] in self.measurements:
raise ValueError('BUG: two measurements with the same name in {}'.format(
self.__class__.__name__))
self.measurements[measurement['name']] = measurement
def measure_cmd_resources(self, cmd, name, legend, save_bs=False):
"""Measure system resource usage of a command"""
def _worker(data_q, cmd, **kwargs):
@ -357,7 +364,7 @@ class BuildPerfTestCase(unittest.TestCase):
measurement['values']['buildstats_file'] = \
os.path.relpath(bs_file, self.base_dir)
self.measurements.append(measurement)
self._append_measurement(measurement)
# Append to 'times' array for globalres log
e_sec = etime.total_seconds()
@ -379,7 +386,7 @@ class BuildPerfTestCase(unittest.TestCase):
('name', name),
('legend', legend)])
measurement['values'] = OrderedDict([('size', size)])
self.measurements.append(measurement)
self._append_measurement(measurement)
# Append to 'sizes' array for globalres log
self.sizes.append(str(size))