yzshen | 5b7319a | 2014-11-14 14:22:08 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import argparse |
| 7 | import imp |
| 8 | import importlib |
| 9 | import os |
| 10 | import sys |
| 11 | |
| 12 | try: |
| 13 | imp.find_module('mopy') |
| 14 | except ImportError: |
| 15 | sys.path.append(os.path.abspath(os.path.join( |
| 16 | __file__, os.pardir, os.pardir, 'mojo', 'tools'))) |
| 17 | from mopy.paths import Paths |
| 18 | |
| 19 | |
| 20 | class BenchmarkRunner(object): |
| 21 | def __init__(self, args): |
| 22 | self._args = args |
| 23 | self._benchmark_dir = os.path.dirname(os.path.realpath(__file__)) |
| 24 | if args.release: |
| 25 | build_directory = os.path.join('out', 'Release') |
| 26 | else: |
| 27 | build_directory = os.path.join('out', 'Debug') |
Przemysław Pietrzkiewicz | 64dbd1d | 2015-07-21 12:54:34 -0700 | [diff] [blame] | 28 | self._paths = Paths(build_dir=build_directory) |
yzshen | 5b7319a | 2014-11-14 14:22:08 -0800 | [diff] [blame] | 29 | |
| 30 | def _list_tests(self): |
| 31 | for name in os.listdir(self._benchmark_dir): |
| 32 | path = os.path.join(self._benchmark_dir, name) |
| 33 | if os.path.isdir(path): |
| 34 | yield name |
| 35 | |
| 36 | def _run_test(self, test_name): |
| 37 | print "Running %s ..." % test_name |
| 38 | run_script_path = os.path.join(self._benchmark_dir, test_name, 'run.py') |
| 39 | if os.path.isfile(run_script_path): |
| 40 | run_module = '.'.join([test_name, 'run']) |
| 41 | importlib.import_module(run_module) |
| 42 | result = sys.modules[run_module].run(self._args, self._paths) |
| 43 | |
| 44 | #TODO(yzshen): (1) consider using more structured result; |
| 45 | # (2) upload the result to server. |
| 46 | print result |
| 47 | |
| 48 | def run(self): |
| 49 | for test in self._list_tests(): |
| 50 | self._run_test(test) |
| 51 | |
| 52 | |
| 53 | def main(): |
| 54 | parser = argparse.ArgumentParser( |
| 55 | description='Mojo performance benchmark runner') |
| 56 | |
| 57 | debug_group = parser.add_mutually_exclusive_group() |
| 58 | debug_group.add_argument('--release', |
| 59 | help='test against release build (default)', |
| 60 | default=True, action='store_true') |
| 61 | debug_group.add_argument('--debug', help='test against debug build', |
| 62 | default=False, dest='release', action='store_false') |
| 63 | |
| 64 | args = parser.parse_args() |
| 65 | |
| 66 | BenchmarkRunner(args).run() |
| 67 | |
| 68 | |
| 69 | if __name__ == '__main__': |
| 70 | sys.exit(main()) |