blob: 507100ce12f27a394cd562c31f1729d67db1bd4d [file] [log] [blame]
yzshen5b7319a2014-11-14 14:22:08 -08001#!/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
6import argparse
7import imp
8import importlib
9import os
10import sys
11
12try:
13 imp.find_module('mopy')
14except ImportError:
15 sys.path.append(os.path.abspath(os.path.join(
16 __file__, os.pardir, os.pardir, 'mojo', 'tools')))
17from mopy.paths import Paths
18
19
20class 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 Pietrzkiewicz64dbd1d2015-07-21 12:54:34 -070028 self._paths = Paths(build_dir=build_directory)
yzshen5b7319a2014-11-14 14:22:08 -080029
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
53def 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
69if __name__ == '__main__':
70 sys.exit(main())