oe-build-perf-report 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. #!/usr/bin/python3
  2. #
  3. # Examine build performance test results
  4. #
  5. # Copyright (c) 2017, Intel Corporation.
  6. #
  7. # This program is free software; you can redistribute it and/or modify it
  8. # under the terms and conditions of the GNU General Public License,
  9. # version 2, as published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope it will be useful, but WITHOUT
  12. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. # more details.
  15. #
  16. import argparse
  17. import json
  18. import logging
  19. import os
  20. import re
  21. import sys
  22. from collections import namedtuple, OrderedDict
  23. from operator import attrgetter
  24. from xml.etree import ElementTree as ET
  25. # Import oe libs
  26. scripts_path = os.path.dirname(os.path.realpath(__file__))
  27. sys.path.append(os.path.join(scripts_path, 'lib'))
  28. import scriptpath
  29. from build_perf import print_table
  30. from build_perf.report import (metadata_xml_to_json, results_xml_to_json,
  31. aggregate_data, aggregate_metadata, measurement_stats,
  32. AggregateTestData)
  33. from build_perf import html
  34. from buildstats import BuildStats, diff_buildstats, BSVerDiff
  35. scriptpath.add_oe_lib_path()
  36. from oeqa.utils.git import GitRepo, GitError
  37. import oeqa.utils.gitarchive as gitarchive
  38. # Setup logging
  39. logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
  40. log = logging.getLogger('oe-build-perf-report')
  41. def list_test_revs(repo, tag_name, verbosity, **kwargs):
  42. """Get list of all tested revisions"""
  43. valid_kwargs = dict([(k, v) for k, v in kwargs.items() if v is not None])
  44. fields, revs = gitarchive.get_test_runs(log, repo, tag_name, **valid_kwargs)
  45. ignore_fields = ['tag_number']
  46. if verbosity < 2:
  47. extra_fields = ['COMMITS', 'TEST RUNS']
  48. ignore_fields.extend(['commit_number', 'commit'])
  49. else:
  50. extra_fields = ['TEST RUNS']
  51. print_fields = [i for i, f in enumerate(fields) if f not in ignore_fields]
  52. # Sort revs
  53. rows = [[fields[i].upper() for i in print_fields] + extra_fields]
  54. prev = [''] * len(print_fields)
  55. prev_commit = None
  56. commit_cnt = 0
  57. commit_field = fields.index('commit')
  58. for rev in revs:
  59. # Only use fields that we want to print
  60. cols = [rev[i] for i in print_fields]
  61. if cols != prev:
  62. commit_cnt = 1
  63. test_run_cnt = 1
  64. new_row = [''] * (len(print_fields) + len(extra_fields))
  65. for i in print_fields:
  66. if cols[i] != prev[i]:
  67. break
  68. new_row[i:-len(extra_fields)] = cols[i:]
  69. rows.append(new_row)
  70. else:
  71. if rev[commit_field] != prev_commit:
  72. commit_cnt += 1
  73. test_run_cnt += 1
  74. if verbosity < 2:
  75. new_row[-2] = commit_cnt
  76. new_row[-1] = test_run_cnt
  77. prev = cols
  78. prev_commit = rev[commit_field]
  79. print_table(rows)
  80. def is_xml_format(repo, commit):
  81. """Check if the commit contains xml (or json) data"""
  82. if repo.rev_parse(commit + ':results.xml'):
  83. log.debug("Detected report in xml format in %s", commit)
  84. return True
  85. else:
  86. log.debug("No xml report in %s, assuming json formatted results", commit)
  87. return False
  88. def read_results(repo, tags, xml=True):
  89. """Read result files from repo"""
  90. def parse_xml_stream(data):
  91. """Parse multiple concatenated XML objects"""
  92. objs = []
  93. xml_d = ""
  94. for line in data.splitlines():
  95. if xml_d and line.startswith('<?xml version='):
  96. objs.append(ET.fromstring(xml_d))
  97. xml_d = line
  98. else:
  99. xml_d += line
  100. objs.append(ET.fromstring(xml_d))
  101. return objs
  102. def parse_json_stream(data):
  103. """Parse multiple concatenated JSON objects"""
  104. objs = []
  105. json_d = ""
  106. for line in data.splitlines():
  107. if line == '}{':
  108. json_d += '}'
  109. objs.append(json.loads(json_d, object_pairs_hook=OrderedDict))
  110. json_d = '{'
  111. else:
  112. json_d += line
  113. objs.append(json.loads(json_d, object_pairs_hook=OrderedDict))
  114. return objs
  115. num_revs = len(tags)
  116. # Optimize by reading all data with one git command
  117. log.debug("Loading raw result data from %d tags, %s...", num_revs, tags[0])
  118. if xml:
  119. git_objs = [tag + ':metadata.xml' for tag in tags] + [tag + ':results.xml' for tag in tags]
  120. data = parse_xml_stream(repo.run_cmd(['show'] + git_objs + ['--']))
  121. return ([metadata_xml_to_json(e) for e in data[0:num_revs]],
  122. [results_xml_to_json(e) for e in data[num_revs:]])
  123. else:
  124. git_objs = [tag + ':metadata.json' for tag in tags] + [tag + ':results.json' for tag in tags]
  125. data = parse_json_stream(repo.run_cmd(['show'] + git_objs + ['--']))
  126. return data[0:num_revs], data[num_revs:]
  127. def get_data_item(data, key):
  128. """Nested getitem lookup"""
  129. for k in key.split('.'):
  130. data = data[k]
  131. return data
  132. def metadata_diff(metadata_l, metadata_r):
  133. """Prepare a metadata diff for printing"""
  134. keys = [('Hostname', 'hostname', 'hostname'),
  135. ('Branch', 'branch', 'layers.meta.branch'),
  136. ('Commit number', 'commit_num', 'layers.meta.commit_count'),
  137. ('Commit', 'commit', 'layers.meta.commit'),
  138. ('Number of test runs', 'testrun_count', 'testrun_count')
  139. ]
  140. def _metadata_diff(key):
  141. """Diff metadata from two test reports"""
  142. try:
  143. val1 = get_data_item(metadata_l, key)
  144. except KeyError:
  145. val1 = '(N/A)'
  146. try:
  147. val2 = get_data_item(metadata_r, key)
  148. except KeyError:
  149. val2 = '(N/A)'
  150. return val1, val2
  151. metadata = OrderedDict()
  152. for title, key, key_json in keys:
  153. value_l, value_r = _metadata_diff(key_json)
  154. metadata[key] = {'title': title,
  155. 'value_old': value_l,
  156. 'value': value_r}
  157. return metadata
  158. def print_diff_report(metadata_l, data_l, metadata_r, data_r):
  159. """Print differences between two data sets"""
  160. # First, print general metadata
  161. print("\nTEST METADATA:\n==============")
  162. meta_diff = metadata_diff(metadata_l, metadata_r)
  163. rows = []
  164. row_fmt = ['{:{wid}} ', '{:<{wid}} ', '{:<{wid}}']
  165. rows = [['', 'CURRENT COMMIT', 'COMPARING WITH']]
  166. for key, val in meta_diff.items():
  167. # Shorten commit hashes
  168. if key == 'commit':
  169. rows.append([val['title'] + ':', val['value'][:20], val['value_old'][:20]])
  170. else:
  171. rows.append([val['title'] + ':', val['value'], val['value_old']])
  172. print_table(rows, row_fmt)
  173. # Print test results
  174. print("\nTEST RESULTS:\n=============")
  175. tests = list(data_l['tests'].keys())
  176. # Append tests that are only present in 'right' set
  177. tests += [t for t in list(data_r['tests'].keys()) if t not in tests]
  178. # Prepare data to be printed
  179. rows = []
  180. row_fmt = ['{:8}', '{:{wid}}', '{:{wid}}', ' {:>{wid}}', ' {:{wid}} ', '{:{wid}}',
  181. ' {:>{wid}}', ' {:>{wid}}']
  182. num_cols = len(row_fmt)
  183. for test in tests:
  184. test_l = data_l['tests'][test] if test in data_l['tests'] else None
  185. test_r = data_r['tests'][test] if test in data_r['tests'] else None
  186. pref = ' '
  187. if test_l is None:
  188. pref = '+'
  189. elif test_r is None:
  190. pref = '-'
  191. descr = test_l['description'] if test_l else test_r['description']
  192. heading = "{} {}: {}".format(pref, test, descr)
  193. rows.append([heading])
  194. # Generate the list of measurements
  195. meas_l = test_l['measurements'] if test_l else {}
  196. meas_r = test_r['measurements'] if test_r else {}
  197. measurements = list(meas_l.keys())
  198. measurements += [m for m in list(meas_r.keys()) if m not in measurements]
  199. for meas in measurements:
  200. m_pref = ' '
  201. if meas in meas_l:
  202. stats_l = measurement_stats(meas_l[meas], 'l.')
  203. else:
  204. stats_l = measurement_stats(None, 'l.')
  205. m_pref = '+'
  206. if meas in meas_r:
  207. stats_r = measurement_stats(meas_r[meas], 'r.')
  208. else:
  209. stats_r = measurement_stats(None, 'r.')
  210. m_pref = '-'
  211. stats = stats_l.copy()
  212. stats.update(stats_r)
  213. absdiff = stats['val_cls'](stats['r.mean'] - stats['l.mean'])
  214. reldiff = "{:+.1f} %".format(absdiff * 100 / stats['l.mean'])
  215. if stats['r.mean'] > stats['l.mean']:
  216. absdiff = '+' + str(absdiff)
  217. else:
  218. absdiff = str(absdiff)
  219. rows.append(['', m_pref, stats['name'] + ' ' + stats['quantity'],
  220. str(stats['l.mean']), '->', str(stats['r.mean']),
  221. absdiff, reldiff])
  222. rows.append([''] * num_cols)
  223. print_table(rows, row_fmt)
  224. print()
  225. class BSSummary(object):
  226. def __init__(self, bs1, bs2):
  227. self.tasks = {'count': bs2.num_tasks,
  228. 'change': '{:+d}'.format(bs2.num_tasks - bs1.num_tasks)}
  229. self.top_consumer = None
  230. self.top_decrease = None
  231. self.top_increase = None
  232. self.ver_diff = OrderedDict()
  233. tasks_diff = diff_buildstats(bs1, bs2, 'cputime')
  234. # Get top consumers of resources
  235. tasks_diff = sorted(tasks_diff, key=attrgetter('value2'))
  236. self.top_consumer = tasks_diff[-5:]
  237. # Get biggest increase and decrease in resource usage
  238. tasks_diff = sorted(tasks_diff, key=attrgetter('absdiff'))
  239. self.top_decrease = tasks_diff[0:5]
  240. self.top_increase = tasks_diff[-5:]
  241. # Compare recipe versions and prepare data for display
  242. ver_diff = BSVerDiff(bs1, bs2)
  243. if ver_diff:
  244. if ver_diff.new:
  245. self.ver_diff['New recipes'] = [(n, r.evr) for n, r in ver_diff.new.items()]
  246. if ver_diff.dropped:
  247. self.ver_diff['Dropped recipes'] = [(n, r.evr) for n, r in ver_diff.dropped.items()]
  248. if ver_diff.echanged:
  249. self.ver_diff['Epoch changed'] = [(n, "{} &rarr; {}".format(r.left.evr, r.right.evr)) for n, r in ver_diff.echanged.items()]
  250. if ver_diff.vchanged:
  251. self.ver_diff['Version changed'] = [(n, "{} &rarr; {}".format(r.left.version, r.right.version)) for n, r in ver_diff.vchanged.items()]
  252. if ver_diff.rchanged:
  253. self.ver_diff['Revision changed'] = [(n, "{} &rarr; {}".format(r.left.evr, r.right.evr)) for n, r in ver_diff.rchanged.items()]
  254. def print_html_report(data, id_comp, buildstats):
  255. """Print report in html format"""
  256. # Handle metadata
  257. metadata = metadata_diff(data[id_comp].metadata, data[-1].metadata)
  258. # Generate list of tests
  259. tests = []
  260. for test in data[-1].results['tests'].keys():
  261. test_r = data[-1].results['tests'][test]
  262. new_test = {'name': test_r['name'],
  263. 'description': test_r['description'],
  264. 'status': test_r['status'],
  265. 'measurements': [],
  266. 'err_type': test_r.get('err_type'),
  267. }
  268. # Limit length of err output shown
  269. if 'message' in test_r:
  270. lines = test_r['message'].splitlines()
  271. if len(lines) > 20:
  272. new_test['message'] = '...\n' + '\n'.join(lines[-20:])
  273. else:
  274. new_test['message'] = test_r['message']
  275. # Generate the list of measurements
  276. for meas in test_r['measurements'].keys():
  277. meas_r = test_r['measurements'][meas]
  278. meas_type = 'time' if meas_r['type'] == 'sysres' else 'size'
  279. new_meas = {'name': meas_r['name'],
  280. 'legend': meas_r['legend'],
  281. 'description': meas_r['name'] + ' ' + meas_type,
  282. }
  283. samples = []
  284. # Run through all revisions in our data
  285. for meta, test_data in data:
  286. if (not test in test_data['tests'] or
  287. not meas in test_data['tests'][test]['measurements']):
  288. samples.append(measurement_stats(None))
  289. continue
  290. test_i = test_data['tests'][test]
  291. meas_i = test_i['measurements'][meas]
  292. commit_num = get_data_item(meta, 'layers.meta.commit_count')
  293. samples.append(measurement_stats(meas_i))
  294. samples[-1]['commit_num'] = commit_num
  295. absdiff = samples[-1]['val_cls'](samples[-1]['mean'] - samples[id_comp]['mean'])
  296. reldiff = absdiff * 100 / samples[id_comp]['mean']
  297. new_meas['absdiff'] = absdiff
  298. new_meas['absdiff_str'] = str(absdiff) if absdiff < 0 else '+' + str(absdiff)
  299. new_meas['reldiff'] = reldiff
  300. new_meas['reldiff_str'] = "{:+.1f} %".format(reldiff)
  301. new_meas['samples'] = samples
  302. new_meas['value'] = samples[-1]
  303. new_meas['value_type'] = samples[-1]['val_cls']
  304. # Compare buildstats
  305. bs_key = test + '.' + meas
  306. rev = str(metadata['commit_num']['value'])
  307. comp_rev = str(metadata['commit_num']['value_old'])
  308. if (rev in buildstats and bs_key in buildstats[rev] and
  309. comp_rev in buildstats and bs_key in buildstats[comp_rev]):
  310. new_meas['buildstats'] = BSSummary(buildstats[comp_rev][bs_key],
  311. buildstats[rev][bs_key])
  312. new_test['measurements'].append(new_meas)
  313. tests.append(new_test)
  314. # Chart options
  315. chart_opts = {'haxis': {'min': get_data_item(data[0][0], 'layers.meta.commit_count'),
  316. 'max': get_data_item(data[-1][0], 'layers.meta.commit_count')}
  317. }
  318. print(html.template.render(title="Build Perf Test Report",
  319. metadata=metadata, test_data=tests,
  320. chart_opts=chart_opts))
  321. def get_buildstats(repo, notes_ref, revs, outdir=None):
  322. """Get the buildstats from git notes"""
  323. full_ref = 'refs/notes/' + notes_ref
  324. if not repo.rev_parse(full_ref):
  325. log.error("No buildstats found, please try running "
  326. "'git fetch origin %s:%s' to fetch them from the remote",
  327. full_ref, full_ref)
  328. return
  329. missing = False
  330. buildstats = {}
  331. log.info("Parsing buildstats from 'refs/notes/%s'", notes_ref)
  332. for rev in revs:
  333. buildstats[rev.commit_number] = {}
  334. log.debug('Dumping buildstats for %s (%s)', rev.commit_number,
  335. rev.commit)
  336. for tag in rev.tags:
  337. log.debug(' %s', tag)
  338. try:
  339. bs_all = json.loads(repo.run_cmd(['notes', '--ref', notes_ref,
  340. 'show', tag + '^0']))
  341. except GitError:
  342. log.warning("Buildstats not found for %s", tag)
  343. bs_all = {}
  344. missing = True
  345. for measurement, bs in bs_all.items():
  346. # Write out onto disk
  347. if outdir:
  348. tag_base, run_id = tag.rsplit('/', 1)
  349. tag_base = tag_base.replace('/', '_')
  350. bs_dir = os.path.join(outdir, measurement, tag_base)
  351. if not os.path.exists(bs_dir):
  352. os.makedirs(bs_dir)
  353. with open(os.path.join(bs_dir, run_id + '.json'), 'w') as f:
  354. json.dump(bs, f, indent=2)
  355. # Read buildstats into a dict
  356. _bs = BuildStats.from_json(bs)
  357. if measurement not in buildstats[rev.commit_number]:
  358. buildstats[rev.commit_number][measurement] = _bs
  359. else:
  360. buildstats[rev.commit_number][measurement].aggregate(_bs)
  361. if missing:
  362. log.info("Buildstats were missing for some test runs, please "
  363. "run 'git fetch origin %s:%s' and try again",
  364. full_ref, full_ref)
  365. return buildstats
  366. def auto_args(repo, args):
  367. """Guess arguments, if not defined by the user"""
  368. # Get the latest commit in the repo
  369. log.debug("Guessing arguments from the latest commit")
  370. msg = repo.run_cmd(['log', '-1', '--branches', '--remotes', '--format=%b'])
  371. for line in msg.splitlines():
  372. split = line.split(':', 1)
  373. if len(split) != 2:
  374. continue
  375. key = split[0]
  376. val = split[1].strip()
  377. if key == 'hostname' and not args.hostname:
  378. log.debug("Using hostname %s", val)
  379. args.hostname = val
  380. elif key == 'branch' and not args.branch:
  381. log.debug("Using branch %s", val)
  382. args.branch = val
  383. def parse_args(argv):
  384. """Parse command line arguments"""
  385. description = """
  386. Examine build performance test results from a Git repository"""
  387. parser = argparse.ArgumentParser(
  388. formatter_class=argparse.ArgumentDefaultsHelpFormatter,
  389. description=description)
  390. parser.add_argument('--debug', '-d', action='store_true',
  391. help="Verbose logging")
  392. parser.add_argument('--repo', '-r', required=True,
  393. help="Results repository (local git clone)")
  394. parser.add_argument('--list', '-l', action='count',
  395. help="List available test runs")
  396. parser.add_argument('--html', action='store_true',
  397. help="Generate report in html format")
  398. group = parser.add_argument_group('Tag and revision')
  399. group.add_argument('--tag-name', '-t',
  400. default='{hostname}/{branch}/{machine}/{commit_number}-g{commit}/{tag_number}',
  401. help="Tag name (pattern) for finding results")
  402. group.add_argument('--hostname', '-H')
  403. group.add_argument('--branch', '-B', default='master', help="Branch to find commit in")
  404. group.add_argument('--branch2', help="Branch to find comparision revisions in")
  405. group.add_argument('--machine', default='qemux86')
  406. group.add_argument('--history-length', default=25, type=int,
  407. help="Number of tested revisions to plot in html report")
  408. group.add_argument('--commit',
  409. help="Revision to search for")
  410. group.add_argument('--commit-number',
  411. help="Revision number to search for, redundant if "
  412. "--commit is specified")
  413. group.add_argument('--commit2',
  414. help="Revision to compare with")
  415. group.add_argument('--commit-number2',
  416. help="Revision number to compare with, redundant if "
  417. "--commit2 is specified")
  418. parser.add_argument('--dump-buildstats', nargs='?', const='.',
  419. help="Dump buildstats of the tests")
  420. return parser.parse_args(argv)
  421. def main(argv=None):
  422. """Script entry point"""
  423. args = parse_args(argv)
  424. if args.debug:
  425. log.setLevel(logging.DEBUG)
  426. repo = GitRepo(args.repo)
  427. if args.list:
  428. list_test_revs(repo, args.tag_name, args.list, hostname=args.hostname)
  429. return 0
  430. # Determine hostname which to use
  431. if not args.hostname:
  432. auto_args(repo, args)
  433. revs = gitarchive.get_test_revs(log, repo, args.tag_name, hostname=args.hostname,
  434. branch=args.branch, machine=args.machine)
  435. if args.branch2:
  436. revs2 = gitarchive.get_test_revs(log, repo, args.tag_name, hostname=args.hostname,
  437. branch=args.branch2, machine=args.machine)
  438. if not len(revs2):
  439. log.error("No revisions found to compare against")
  440. return 1
  441. if not len(revs):
  442. log.error("No revision to report on found")
  443. return 1
  444. else:
  445. if len(revs) < 2:
  446. log.error("Only %d tester revisions found, unable to generate report" % len(revs))
  447. return 1
  448. # Pick revisions
  449. if args.commit:
  450. if args.commit_number:
  451. log.warning("Ignoring --commit-number as --commit was specified")
  452. index1 = gitarchive.rev_find(revs, 'commit', args.commit)
  453. elif args.commit_number:
  454. index1 = gitarchive.rev_find(revs, 'commit_number', args.commit_number)
  455. else:
  456. index1 = len(revs) - 1
  457. if args.branch2:
  458. revs2.append(revs[index1])
  459. index1 = len(revs2) - 1
  460. revs = revs2
  461. if args.commit2:
  462. if args.commit_number2:
  463. log.warning("Ignoring --commit-number2 as --commit2 was specified")
  464. index2 = gitarchive.rev_find(revs, 'commit', args.commit2)
  465. elif args.commit_number2:
  466. index2 = gitarchive.rev_find(revs, 'commit_number', args.commit_number2)
  467. else:
  468. if index1 > 0:
  469. index2 = index1 - 1
  470. # Find the closest matching commit number for comparision
  471. # In future we could check the commit is a common ancestor and
  472. # continue back if not but this good enough for now
  473. while index2 > 0 and revs[index2].commit_number > revs[index1].commit_number:
  474. index2 = index2 - 1
  475. else:
  476. log.error("Unable to determine the other commit, use "
  477. "--commit2 or --commit-number2 to specify it")
  478. return 1
  479. index_l = min(index1, index2)
  480. index_r = max(index1, index2)
  481. rev_l = revs[index_l]
  482. rev_r = revs[index_r]
  483. log.debug("Using 'left' revision %s (%s), %s test runs:\n %s",
  484. rev_l.commit_number, rev_l.commit, len(rev_l.tags),
  485. '\n '.join(rev_l.tags))
  486. log.debug("Using 'right' revision %s (%s), %s test runs:\n %s",
  487. rev_r.commit_number, rev_r.commit, len(rev_r.tags),
  488. '\n '.join(rev_r.tags))
  489. # Check report format used in the repo (assume all reports in the same fmt)
  490. xml = is_xml_format(repo, revs[index_r].tags[-1])
  491. if args.html:
  492. index_0 = max(0, min(index_l, index_r - args.history_length))
  493. rev_range = range(index_0, index_r + 1)
  494. else:
  495. # We do not need range of commits for text report (no graphs)
  496. index_0 = index_l
  497. rev_range = (index_l, index_r)
  498. # Read raw data
  499. log.debug("Reading %d revisions, starting from %s (%s)",
  500. len(rev_range), revs[index_0].commit_number, revs[index_0].commit)
  501. raw_data = [read_results(repo, revs[i].tags, xml) for i in rev_range]
  502. data = []
  503. for raw_m, raw_d in raw_data:
  504. data.append(AggregateTestData(aggregate_metadata(raw_m),
  505. aggregate_data(raw_d)))
  506. # Read buildstats only when needed
  507. buildstats = None
  508. if args.dump_buildstats or args.html:
  509. outdir = 'oe-build-perf-buildstats' if args.dump_buildstats else None
  510. notes_ref = 'buildstats/{}/{}/{}'.format(args.hostname, args.branch,
  511. args.machine)
  512. buildstats = get_buildstats(repo, notes_ref, [rev_l, rev_r], outdir)
  513. # Print report
  514. if not args.html:
  515. print_diff_report(data[0].metadata, data[0].results,
  516. data[1].metadata, data[1].results)
  517. else:
  518. # Re-map 'left' list index to the data table where index_0 maps to 0
  519. print_html_report(data, index_l - index_0, buildstats)
  520. return 0
  521. if __name__ == "__main__":
  522. sys.exit(main())