blob: f6fb458c2eb1925231f97d6b08a5f3f1619d58f1 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001#!/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#
16import argparse
17import json
18import logging
19import os
20import re
21import sys
22from collections import namedtuple, OrderedDict
23from operator import attrgetter
24from xml.etree import ElementTree as ET
25
26# Import oe libs
27scripts_path = os.path.dirname(os.path.realpath(__file__))
28sys.path.append(os.path.join(scripts_path, 'lib'))
29import scriptpath
30from build_perf import print_table
31from build_perf.report import (metadata_xml_to_json, results_xml_to_json,
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032 aggregate_data, aggregate_metadata, measurement_stats,
33 AggregateTestData)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050034from build_perf import html
Brad Bishopd7bf8c12018-02-25 22:55:05 -050035from buildstats import BuildStats, diff_buildstats, BSVerDiff
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036
37scriptpath.add_oe_lib_path()
38
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039from oeqa.utils.git import GitRepo, GitError
Andrew Geissler99467da2019-02-25 18:54:23 -060040import oeqa.utils.gitarchive as gitarchive
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041
42
43# Setup logging
44logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
45log = logging.getLogger('oe-build-perf-report')
46
Brad Bishopd7bf8c12018-02-25 22:55:05 -050047def list_test_revs(repo, tag_name, verbosity, **kwargs):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 """Get list of all tested revisions"""
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049 valid_kwargs = dict([(k, v) for k, v in kwargs.items() if v is not None])
50
Andrew Geissler99467da2019-02-25 18:54:23 -060051 fields, revs = gitarchive.get_test_runs(log, repo, tag_name, **valid_kwargs)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052 ignore_fields = ['tag_number']
Brad Bishopd7bf8c12018-02-25 22:55:05 -050053 if verbosity < 2:
54 extra_fields = ['COMMITS', 'TEST RUNS']
55 ignore_fields.extend(['commit_number', 'commit'])
56 else:
57 extra_fields = ['TEST RUNS']
58
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 print_fields = [i for i, f in enumerate(fields) if f not in ignore_fields]
60
61 # Sort revs
Brad Bishopd7bf8c12018-02-25 22:55:05 -050062 rows = [[fields[i].upper() for i in print_fields] + extra_fields]
63
64 prev = [''] * len(print_fields)
65 prev_commit = None
66 commit_cnt = 0
67 commit_field = fields.index('commit')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050068 for rev in revs:
69 # Only use fields that we want to print
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070 cols = [rev[i] for i in print_fields]
Brad Bishop6e60e8b2018-02-01 10:27:11 -050071
Brad Bishopd7bf8c12018-02-25 22:55:05 -050072
73 if cols != prev:
74 commit_cnt = 1
75 test_run_cnt = 1
76 new_row = [''] * (len(print_fields) + len(extra_fields))
77
Brad Bishop6e60e8b2018-02-01 10:27:11 -050078 for i in print_fields:
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 if cols[i] != prev[i]:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050080 break
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081 new_row[i:-len(extra_fields)] = cols[i:]
Brad Bishop6e60e8b2018-02-01 10:27:11 -050082 rows.append(new_row)
83 else:
Brad Bishopd7bf8c12018-02-25 22:55:05 -050084 if rev[commit_field] != prev_commit:
85 commit_cnt += 1
86 test_run_cnt += 1
87
88 if verbosity < 2:
89 new_row[-2] = commit_cnt
90 new_row[-1] = test_run_cnt
91 prev = cols
92 prev_commit = rev[commit_field]
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093
94 print_table(rows)
95
Brad Bishop6e60e8b2018-02-01 10:27:11 -050096def is_xml_format(repo, commit):
97 """Check if the commit contains xml (or json) data"""
98 if repo.rev_parse(commit + ':results.xml'):
99 log.debug("Detected report in xml format in %s", commit)
100 return True
101 else:
102 log.debug("No xml report in %s, assuming json formatted results", commit)
103 return False
104
105def read_results(repo, tags, xml=True):
106 """Read result files from repo"""
107
108 def parse_xml_stream(data):
109 """Parse multiple concatenated XML objects"""
110 objs = []
111 xml_d = ""
112 for line in data.splitlines():
113 if xml_d and line.startswith('<?xml version='):
114 objs.append(ET.fromstring(xml_d))
115 xml_d = line
116 else:
117 xml_d += line
118 objs.append(ET.fromstring(xml_d))
119 return objs
120
121 def parse_json_stream(data):
122 """Parse multiple concatenated JSON objects"""
123 objs = []
124 json_d = ""
125 for line in data.splitlines():
126 if line == '}{':
127 json_d += '}'
128 objs.append(json.loads(json_d, object_pairs_hook=OrderedDict))
129 json_d = '{'
130 else:
131 json_d += line
132 objs.append(json.loads(json_d, object_pairs_hook=OrderedDict))
133 return objs
134
135 num_revs = len(tags)
136
137 # Optimize by reading all data with one git command
138 log.debug("Loading raw result data from %d tags, %s...", num_revs, tags[0])
139 if xml:
140 git_objs = [tag + ':metadata.xml' for tag in tags] + [tag + ':results.xml' for tag in tags]
141 data = parse_xml_stream(repo.run_cmd(['show'] + git_objs + ['--']))
142 return ([metadata_xml_to_json(e) for e in data[0:num_revs]],
143 [results_xml_to_json(e) for e in data[num_revs:]])
144 else:
145 git_objs = [tag + ':metadata.json' for tag in tags] + [tag + ':results.json' for tag in tags]
146 data = parse_json_stream(repo.run_cmd(['show'] + git_objs + ['--']))
147 return data[0:num_revs], data[num_revs:]
148
149
150def get_data_item(data, key):
151 """Nested getitem lookup"""
152 for k in key.split('.'):
153 data = data[k]
154 return data
155
156
157def metadata_diff(metadata_l, metadata_r):
158 """Prepare a metadata diff for printing"""
159 keys = [('Hostname', 'hostname', 'hostname'),
160 ('Branch', 'branch', 'layers.meta.branch'),
161 ('Commit number', 'commit_num', 'layers.meta.commit_count'),
162 ('Commit', 'commit', 'layers.meta.commit'),
163 ('Number of test runs', 'testrun_count', 'testrun_count')
164 ]
165
166 def _metadata_diff(key):
167 """Diff metadata from two test reports"""
168 try:
169 val1 = get_data_item(metadata_l, key)
170 except KeyError:
171 val1 = '(N/A)'
172 try:
173 val2 = get_data_item(metadata_r, key)
174 except KeyError:
175 val2 = '(N/A)'
176 return val1, val2
177
178 metadata = OrderedDict()
179 for title, key, key_json in keys:
180 value_l, value_r = _metadata_diff(key_json)
181 metadata[key] = {'title': title,
182 'value_old': value_l,
183 'value': value_r}
184 return metadata
185
186
187def print_diff_report(metadata_l, data_l, metadata_r, data_r):
188 """Print differences between two data sets"""
189
190 # First, print general metadata
191 print("\nTEST METADATA:\n==============")
192 meta_diff = metadata_diff(metadata_l, metadata_r)
193 rows = []
194 row_fmt = ['{:{wid}} ', '{:<{wid}} ', '{:<{wid}}']
195 rows = [['', 'CURRENT COMMIT', 'COMPARING WITH']]
196 for key, val in meta_diff.items():
197 # Shorten commit hashes
198 if key == 'commit':
199 rows.append([val['title'] + ':', val['value'][:20], val['value_old'][:20]])
200 else:
201 rows.append([val['title'] + ':', val['value'], val['value_old']])
202 print_table(rows, row_fmt)
203
204
205 # Print test results
206 print("\nTEST RESULTS:\n=============")
207
208 tests = list(data_l['tests'].keys())
209 # Append tests that are only present in 'right' set
210 tests += [t for t in list(data_r['tests'].keys()) if t not in tests]
211
212 # Prepare data to be printed
213 rows = []
214 row_fmt = ['{:8}', '{:{wid}}', '{:{wid}}', ' {:>{wid}}', ' {:{wid}} ', '{:{wid}}',
215 ' {:>{wid}}', ' {:>{wid}}']
216 num_cols = len(row_fmt)
217 for test in tests:
218 test_l = data_l['tests'][test] if test in data_l['tests'] else None
219 test_r = data_r['tests'][test] if test in data_r['tests'] else None
220 pref = ' '
221 if test_l is None:
222 pref = '+'
223 elif test_r is None:
224 pref = '-'
225 descr = test_l['description'] if test_l else test_r['description']
226 heading = "{} {}: {}".format(pref, test, descr)
227
228 rows.append([heading])
229
230 # Generate the list of measurements
231 meas_l = test_l['measurements'] if test_l else {}
232 meas_r = test_r['measurements'] if test_r else {}
233 measurements = list(meas_l.keys())
234 measurements += [m for m in list(meas_r.keys()) if m not in measurements]
235
236 for meas in measurements:
237 m_pref = ' '
238 if meas in meas_l:
239 stats_l = measurement_stats(meas_l[meas], 'l.')
240 else:
241 stats_l = measurement_stats(None, 'l.')
242 m_pref = '+'
243 if meas in meas_r:
244 stats_r = measurement_stats(meas_r[meas], 'r.')
245 else:
246 stats_r = measurement_stats(None, 'r.')
247 m_pref = '-'
248 stats = stats_l.copy()
249 stats.update(stats_r)
250
251 absdiff = stats['val_cls'](stats['r.mean'] - stats['l.mean'])
252 reldiff = "{:+.1f} %".format(absdiff * 100 / stats['l.mean'])
253 if stats['r.mean'] > stats['l.mean']:
254 absdiff = '+' + str(absdiff)
255 else:
256 absdiff = str(absdiff)
257 rows.append(['', m_pref, stats['name'] + ' ' + stats['quantity'],
258 str(stats['l.mean']), '->', str(stats['r.mean']),
259 absdiff, reldiff])
260 rows.append([''] * num_cols)
261
262 print_table(rows, row_fmt)
263
264 print()
265
266
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500267class BSSummary(object):
268 def __init__(self, bs1, bs2):
269 self.tasks = {'count': bs2.num_tasks,
270 'change': '{:+d}'.format(bs2.num_tasks - bs1.num_tasks)}
271 self.top_consumer = None
272 self.top_decrease = None
273 self.top_increase = None
274 self.ver_diff = OrderedDict()
275
276 tasks_diff = diff_buildstats(bs1, bs2, 'cputime')
277
278 # Get top consumers of resources
279 tasks_diff = sorted(tasks_diff, key=attrgetter('value2'))
280 self.top_consumer = tasks_diff[-5:]
281
282 # Get biggest increase and decrease in resource usage
283 tasks_diff = sorted(tasks_diff, key=attrgetter('absdiff'))
284 self.top_decrease = tasks_diff[0:5]
285 self.top_increase = tasks_diff[-5:]
286
287 # Compare recipe versions and prepare data for display
288 ver_diff = BSVerDiff(bs1, bs2)
289 if ver_diff:
290 if ver_diff.new:
291 self.ver_diff['New recipes'] = [(n, r.evr) for n, r in ver_diff.new.items()]
292 if ver_diff.dropped:
293 self.ver_diff['Dropped recipes'] = [(n, r.evr) for n, r in ver_diff.dropped.items()]
294 if ver_diff.echanged:
295 self.ver_diff['Epoch changed'] = [(n, "{} &rarr; {}".format(r.left.evr, r.right.evr)) for n, r in ver_diff.echanged.items()]
296 if ver_diff.vchanged:
297 self.ver_diff['Version changed'] = [(n, "{} &rarr; {}".format(r.left.version, r.right.version)) for n, r in ver_diff.vchanged.items()]
298 if ver_diff.rchanged:
299 self.ver_diff['Revision changed'] = [(n, "{} &rarr; {}".format(r.left.evr, r.right.evr)) for n, r in ver_diff.rchanged.items()]
300
301
302def print_html_report(data, id_comp, buildstats):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303 """Print report in html format"""
304 # Handle metadata
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500305 metadata = metadata_diff(data[id_comp].metadata, data[-1].metadata)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500306
307 # Generate list of tests
308 tests = []
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500309 for test in data[-1].results['tests'].keys():
310 test_r = data[-1].results['tests'][test]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500311 new_test = {'name': test_r['name'],
312 'description': test_r['description'],
313 'status': test_r['status'],
314 'measurements': [],
315 'err_type': test_r.get('err_type'),
316 }
317 # Limit length of err output shown
318 if 'message' in test_r:
319 lines = test_r['message'].splitlines()
320 if len(lines) > 20:
321 new_test['message'] = '...\n' + '\n'.join(lines[-20:])
322 else:
323 new_test['message'] = test_r['message']
324
325
326 # Generate the list of measurements
327 for meas in test_r['measurements'].keys():
328 meas_r = test_r['measurements'][meas]
329 meas_type = 'time' if meas_r['type'] == 'sysres' else 'size'
330 new_meas = {'name': meas_r['name'],
331 'legend': meas_r['legend'],
332 'description': meas_r['name'] + ' ' + meas_type,
333 }
334 samples = []
335
336 # Run through all revisions in our data
337 for meta, test_data in data:
338 if (not test in test_data['tests'] or
339 not meas in test_data['tests'][test]['measurements']):
340 samples.append(measurement_stats(None))
341 continue
342 test_i = test_data['tests'][test]
343 meas_i = test_i['measurements'][meas]
344 commit_num = get_data_item(meta, 'layers.meta.commit_count')
345 samples.append(measurement_stats(meas_i))
346 samples[-1]['commit_num'] = commit_num
347
348 absdiff = samples[-1]['val_cls'](samples[-1]['mean'] - samples[id_comp]['mean'])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800349 reldiff = absdiff * 100 / samples[id_comp]['mean']
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500350 new_meas['absdiff'] = absdiff
351 new_meas['absdiff_str'] = str(absdiff) if absdiff < 0 else '+' + str(absdiff)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800352 new_meas['reldiff'] = reldiff
353 new_meas['reldiff_str'] = "{:+.1f} %".format(reldiff)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500354 new_meas['samples'] = samples
355 new_meas['value'] = samples[-1]
356 new_meas['value_type'] = samples[-1]['val_cls']
357
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500358 # Compare buildstats
359 bs_key = test + '.' + meas
Andrew Geissler99467da2019-02-25 18:54:23 -0600360 rev = str(metadata['commit_num']['value'])
361 comp_rev = str(metadata['commit_num']['value_old'])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500362 if (rev in buildstats and bs_key in buildstats[rev] and
363 comp_rev in buildstats and bs_key in buildstats[comp_rev]):
364 new_meas['buildstats'] = BSSummary(buildstats[comp_rev][bs_key],
365 buildstats[rev][bs_key])
366
367
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500368 new_test['measurements'].append(new_meas)
369 tests.append(new_test)
370
371 # Chart options
372 chart_opts = {'haxis': {'min': get_data_item(data[0][0], 'layers.meta.commit_count'),
373 'max': get_data_item(data[-1][0], 'layers.meta.commit_count')}
374 }
375
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500376 print(html.template.render(title="Build Perf Test Report",
377 metadata=metadata, test_data=tests,
378 chart_opts=chart_opts))
379
380
381def get_buildstats(repo, notes_ref, revs, outdir=None):
382 """Get the buildstats from git notes"""
383 full_ref = 'refs/notes/' + notes_ref
384 if not repo.rev_parse(full_ref):
385 log.error("No buildstats found, please try running "
386 "'git fetch origin %s:%s' to fetch them from the remote",
387 full_ref, full_ref)
388 return
389
390 missing = False
391 buildstats = {}
392 log.info("Parsing buildstats from 'refs/notes/%s'", notes_ref)
393 for rev in revs:
394 buildstats[rev.commit_number] = {}
395 log.debug('Dumping buildstats for %s (%s)', rev.commit_number,
396 rev.commit)
397 for tag in rev.tags:
398 log.debug(' %s', tag)
399 try:
400 bs_all = json.loads(repo.run_cmd(['notes', '--ref', notes_ref,
401 'show', tag + '^0']))
402 except GitError:
403 log.warning("Buildstats not found for %s", tag)
404 bs_all = {}
405 missing = True
406
407 for measurement, bs in bs_all.items():
408 # Write out onto disk
409 if outdir:
410 tag_base, run_id = tag.rsplit('/', 1)
411 tag_base = tag_base.replace('/', '_')
412 bs_dir = os.path.join(outdir, measurement, tag_base)
413 if not os.path.exists(bs_dir):
414 os.makedirs(bs_dir)
415 with open(os.path.join(bs_dir, run_id + '.json'), 'w') as f:
416 json.dump(bs, f, indent=2)
417
418 # Read buildstats into a dict
419 _bs = BuildStats.from_json(bs)
420 if measurement not in buildstats[rev.commit_number]:
421 buildstats[rev.commit_number][measurement] = _bs
422 else:
423 buildstats[rev.commit_number][measurement].aggregate(_bs)
424
425 if missing:
426 log.info("Buildstats were missing for some test runs, please "
427 "run 'git fetch origin %s:%s' and try again",
428 full_ref, full_ref)
429
430 return buildstats
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500431
432
433def auto_args(repo, args):
434 """Guess arguments, if not defined by the user"""
435 # Get the latest commit in the repo
436 log.debug("Guessing arguments from the latest commit")
437 msg = repo.run_cmd(['log', '-1', '--branches', '--remotes', '--format=%b'])
438 for line in msg.splitlines():
439 split = line.split(':', 1)
440 if len(split) != 2:
441 continue
442
443 key = split[0]
444 val = split[1].strip()
Andrew Geissler99467da2019-02-25 18:54:23 -0600445 if key == 'hostname' and not args.hostname:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500446 log.debug("Using hostname %s", val)
447 args.hostname = val
Andrew Geissler99467da2019-02-25 18:54:23 -0600448 elif key == 'branch' and not args.branch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500449 log.debug("Using branch %s", val)
450 args.branch = val
451
452
453def parse_args(argv):
454 """Parse command line arguments"""
455 description = """
456Examine build performance test results from a Git repository"""
457 parser = argparse.ArgumentParser(
458 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
459 description=description)
460
461 parser.add_argument('--debug', '-d', action='store_true',
462 help="Verbose logging")
463 parser.add_argument('--repo', '-r', required=True,
464 help="Results repository (local git clone)")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500465 parser.add_argument('--list', '-l', action='count',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500466 help="List available test runs")
467 parser.add_argument('--html', action='store_true',
468 help="Generate report in html format")
469 group = parser.add_argument_group('Tag and revision')
470 group.add_argument('--tag-name', '-t',
471 default='{hostname}/{branch}/{machine}/{commit_number}-g{commit}/{tag_number}',
472 help="Tag name (pattern) for finding results")
473 group.add_argument('--hostname', '-H')
Andrew Geissler99467da2019-02-25 18:54:23 -0600474 group.add_argument('--branch', '-B', default='master', help="Branch to find commit in")
475 group.add_argument('--branch2', help="Branch to find comparision revisions in")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500476 group.add_argument('--machine', default='qemux86')
477 group.add_argument('--history-length', default=25, type=int,
478 help="Number of tested revisions to plot in html report")
479 group.add_argument('--commit',
480 help="Revision to search for")
481 group.add_argument('--commit-number',
482 help="Revision number to search for, redundant if "
483 "--commit is specified")
484 group.add_argument('--commit2',
485 help="Revision to compare with")
486 group.add_argument('--commit-number2',
487 help="Revision number to compare with, redundant if "
488 "--commit2 is specified")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500489 parser.add_argument('--dump-buildstats', nargs='?', const='.',
490 help="Dump buildstats of the tests")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500491
492 return parser.parse_args(argv)
493
494
495def main(argv=None):
496 """Script entry point"""
497 args = parse_args(argv)
498 if args.debug:
499 log.setLevel(logging.DEBUG)
500
501 repo = GitRepo(args.repo)
502
503 if args.list:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500504 list_test_revs(repo, args.tag_name, args.list, hostname=args.hostname)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500505 return 0
506
507 # Determine hostname which to use
508 if not args.hostname:
509 auto_args(repo, args)
510
Andrew Geissler99467da2019-02-25 18:54:23 -0600511 revs = gitarchive.get_test_revs(log, repo, args.tag_name, hostname=args.hostname,
512 branch=args.branch, machine=args.machine)
513 if args.branch2:
514 revs2 = gitarchive.get_test_revs(log, repo, args.tag_name, hostname=args.hostname,
515 branch=args.branch2, machine=args.machine)
516 if not len(revs2):
517 log.error("No revisions found to compare against")
518 return 1
519 if not len(revs):
520 log.error("No revision to report on found")
521 return 1
522 else:
523 if len(revs) < 2:
524 log.error("Only %d tester revisions found, unable to generate report" % len(revs))
525 return 1
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500526
527 # Pick revisions
528 if args.commit:
529 if args.commit_number:
530 log.warning("Ignoring --commit-number as --commit was specified")
Andrew Geissler99467da2019-02-25 18:54:23 -0600531 index1 = gitarchive.rev_find(revs, 'commit', args.commit)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500532 elif args.commit_number:
Andrew Geissler99467da2019-02-25 18:54:23 -0600533 index1 = gitarchive.rev_find(revs, 'commit_number', args.commit_number)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500534 else:
535 index1 = len(revs) - 1
536
Andrew Geissler99467da2019-02-25 18:54:23 -0600537 if args.branch2:
538 revs2.append(revs[index1])
539 index1 = len(revs2) - 1
540 revs = revs2
541
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500542 if args.commit2:
543 if args.commit_number2:
544 log.warning("Ignoring --commit-number2 as --commit2 was specified")
Andrew Geissler99467da2019-02-25 18:54:23 -0600545 index2 = gitarchive.rev_find(revs, 'commit', args.commit2)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500546 elif args.commit_number2:
Andrew Geissler99467da2019-02-25 18:54:23 -0600547 index2 = gitarchive.rev_find(revs, 'commit_number', args.commit_number2)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500548 else:
549 if index1 > 0:
550 index2 = index1 - 1
Andrew Geissler99467da2019-02-25 18:54:23 -0600551 # Find the closest matching commit number for comparision
552 # In future we could check the commit is a common ancestor and
553 # continue back if not but this good enough for now
554 while index2 > 0 and revs[index2].commit_number > revs[index1].commit_number:
555 index2 = index2 - 1
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500556 else:
557 log.error("Unable to determine the other commit, use "
558 "--commit2 or --commit-number2 to specify it")
559 return 1
560
561 index_l = min(index1, index2)
562 index_r = max(index1, index2)
563
564 rev_l = revs[index_l]
565 rev_r = revs[index_r]
566 log.debug("Using 'left' revision %s (%s), %s test runs:\n %s",
567 rev_l.commit_number, rev_l.commit, len(rev_l.tags),
568 '\n '.join(rev_l.tags))
569 log.debug("Using 'right' revision %s (%s), %s test runs:\n %s",
570 rev_r.commit_number, rev_r.commit, len(rev_r.tags),
571 '\n '.join(rev_r.tags))
572
573 # Check report format used in the repo (assume all reports in the same fmt)
574 xml = is_xml_format(repo, revs[index_r].tags[-1])
575
576 if args.html:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500577 index_0 = max(0, min(index_l, index_r - args.history_length))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500578 rev_range = range(index_0, index_r + 1)
579 else:
580 # We do not need range of commits for text report (no graphs)
581 index_0 = index_l
582 rev_range = (index_l, index_r)
583
584 # Read raw data
585 log.debug("Reading %d revisions, starting from %s (%s)",
586 len(rev_range), revs[index_0].commit_number, revs[index_0].commit)
587 raw_data = [read_results(repo, revs[i].tags, xml) for i in rev_range]
588
589 data = []
590 for raw_m, raw_d in raw_data:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500591 data.append(AggregateTestData(aggregate_metadata(raw_m),
592 aggregate_data(raw_d)))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500593
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500594 # Read buildstats only when needed
595 buildstats = None
596 if args.dump_buildstats or args.html:
597 outdir = 'oe-build-perf-buildstats' if args.dump_buildstats else None
598 notes_ref = 'buildstats/{}/{}/{}'.format(args.hostname, args.branch,
599 args.machine)
600 buildstats = get_buildstats(repo, notes_ref, [rev_l, rev_r], outdir)
601
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500602 # Print report
603 if not args.html:
Brad Bishop00111322018-04-01 22:23:53 -0400604 print_diff_report(data[0].metadata, data[0].results,
605 data[1].metadata, data[1].results)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500606 else:
Brad Bishop00111322018-04-01 22:23:53 -0400607 # Re-map 'left' list index to the data table where index_0 maps to 0
608 print_html_report(data, index_l - index_0, buildstats)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500609
610 return 0
611
612if __name__ == "__main__":
613 sys.exit(main())