summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/buildperf
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2016-08-29 22:48:28 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-09-03 09:58:42 +0100
commit81b8ccc1f65dcb162d10f857059920dac032e6aa (patch)
tree9e7c030ee07f336ec34fa85e476f6c5739d8aceb /meta/lib/oeqa/buildperf
parentf1fb013d48602805e9b28a3a00c2e05fcf07612f (diff)
downloadpoky-81b8ccc1f65dcb162d10f857059920dac032e6aa.tar.gz
oeqa.buildperf: convert buildstats into json format
Instead of archiving buildstats in raw text file format convert all buildstats into one json-formatted file. Some redundant information, i.e. 'Event:', 'utime:', 'stime:', 'cutime:' and 'cstime:' fields, are dropped. (From OE-Core rev: efcf74b194f2a40eb3e6359dd41386db3eb25287) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/buildperf')
-rw-r--r--meta/lib/oeqa/buildperf/base.py69
1 files changed, 66 insertions, 3 deletions
diff --git a/meta/lib/oeqa/buildperf/base.py b/meta/lib/oeqa/buildperf/base.py
index 95a0abfa5d..c71622005f 100644
--- a/meta/lib/oeqa/buildperf/base.py
+++ b/meta/lib/oeqa/buildperf/base.py
@@ -409,13 +409,76 @@ class BuildPerfTestCase(unittest.TestCase):
409 409
410 def save_buildstats(self, label=None): 410 def save_buildstats(self, label=None):
411 """Save buildstats""" 411 """Save buildstats"""
412 def split_nevr(nevr):
413 """Split name and version information from recipe "nevr" string"""
414 name, e_v, revision = nevr.rsplit('-', 2)
415 match = re.match(r'^((?P<epoch>[0-9]{1,5})_)?(?P<version>.*)$', e_v)
416 version = match.group('version')
417 epoch = match.group('epoch')
418 return name, epoch, version, revision
419
420 def bs_to_json(filename):
421 """Convert (task) buildstats file into json format"""
422 bs_json = {'iostat': {},
423 'rusage': {},
424 'child_rusage': {}}
425 with open(filename) as fobj:
426 for line in fobj.readlines():
427 key, val = line.split(':', 1)
428 val = val.strip()
429 if key == 'Started':
430 start_time = datetime.utcfromtimestamp(float(val))
431 bs_json['start_time'] = start_time
432 elif key == 'Ended':
433 end_time = datetime.utcfromtimestamp(float(val))
434 elif key.startswith('IO '):
435 split = key.split()
436 bs_json['iostat'][split[1]] = int(val)
437 elif key.find('rusage') >= 0:
438 split = key.split()
439 ru_key = split[-1]
440 if ru_key in ('ru_stime', 'ru_utime'):
441 val = float(val)
442 else:
443 val = int(val)
444 ru_type = 'rusage' if split[0] == 'rusage' else \
445 'child_rusage'
446 bs_json[ru_type][ru_key] = val
447 elif key == 'Status':
448 bs_json['status'] = val
449 bs_json['elapsed_time'] = end_time - start_time
450 return bs_json
451
452 log.info('Saving buildstats in JSON format')
412 bs_dirs = os.listdir(self.bb_vars['BUILDSTATS_BASE']) 453 bs_dirs = os.listdir(self.bb_vars['BUILDSTATS_BASE'])
413 if len(bs_dirs) > 1: 454 if len(bs_dirs) > 1:
414 log.warning("Multiple buildstats found for test %s, only " 455 log.warning("Multiple buildstats found for test %s, only "
415 "archiving the last one", self.name) 456 "archiving the last one", self.name)
416 postfix = '-' + label if label else '' 457 bs_dir = os.path.join(self.bb_vars['BUILDSTATS_BASE'], bs_dirs[-1])
417 shutil.move(os.path.join(self.bb_vars['BUILDSTATS_BASE'], bs_dirs[-1]), 458
418 os.path.join(self.out_dir, 'buildstats' + postfix)) 459 buildstats = []
460 for fname in os.listdir(bs_dir):
461 recipe_dir = os.path.join(bs_dir, fname)
462 if not os.path.isdir(recipe_dir):
463 continue
464 name, epoch, version, revision = split_nevr(fname)
465 recipe_bs = {'name': name,
466 'epoch': epoch,
467 'version': version,
468 'revision': revision,
469 'tasks': {}}
470 for task in os.listdir(recipe_dir):
471 recipe_bs['tasks'][task] = bs_to_json(os.path.join(recipe_dir,
472 task))
473 buildstats.append(recipe_bs)
474
475 # Write buildstats into json file
476 postfix = '.' + label if label else ''
477 postfix += '.json'
478 outfile = os.path.join(self.out_dir, 'buildstats' + postfix)
479 with open(outfile, 'w') as fobj:
480 json.dump(buildstats, fobj, indent=4, sort_keys=True,
481 cls=ResultsJsonEncoder)
419 482
420 def rm_tmp(self): 483 def rm_tmp(self):
421 """Cleanup temporary/intermediate files and directories""" 484 """Cleanup temporary/intermediate files and directories"""