Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
benchmark.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
4# for details. All rights reserved. Use of this source code is governed by a
5# BSD-style license that can be found in the LICENSE file.
6
7# Simple wrapper for running benchmarks.
8
9import getopt
10import optparse
11import os
12from os.path import join, dirname, realpath, abspath
13import subprocess
14import sys
15import utils
16import re
17
18HOST_OS = utils.GuessOS()
19HOST_CPUS = utils.GuessCpus()
20
21
22# Returns whether 'bench' matches any element in the 'filt' list.
23def match(bench, filt):
24 bench = bench.lower()
25 for element in filt:
26 if element.search(bench):
27 return True
28 return False
29
30
32 benchmark_root_path = [dirname(sys.argv[0]), '..', '..'] + ['benchmarks']
33 return realpath(os.path.sep.join(benchmark_root_path + path))
34
35
36def ReadBenchmarkList(mode, path, core):
37 filename = GetBenchmarkFile([path])
38 benchmarks = dict()
39 with open(filename) as infile:
40 exec(infile.read(), benchmarks)
41 if (mode == "release") and not core:
42 return benchmarks['SUPPORTED_BENCHMARKS']
43 else:
44 return benchmarks['SUPPORTED_CORE_BENCHMARKS']
45
46
48 result = optparse.OptionParser()
49 result.add_option(
50 "-m",
51 "--mode",
52 help='Build variants (comma-separated).',
53 metavar='[all,debug,release]',
54 default='release')
55 result.add_option(
56 "-v",
57 "--verbose",
58 help='Verbose output.',
59 default=False,
60 action="store_true")
61 result.add_option(
62 "-c",
63 "--core",
64 help='Run only core benchmarks.',
65 default=False,
66 action="store_true")
67 result.add_option(
68 "--arch",
69 help='Target architectures (comma-separated).',
70 metavar='[all,ia32,x64,simarm,arm,dartc]',
72 result.add_option(
73 "--executable",
74 help='Virtual machine to execute.',
75 metavar='[dart, (path to dart binary)]',
76 default=None)
77 result.add_option(
78 "-w",
79 "--warmup",
80 help='Only run the warmup period.',
81 default=False,
82 action="store_true")
83 return result
84
85
86def ProcessOptions(options):
87 if options.arch == 'all':
88 options.arch = 'ia32,x64,simarm,dartc'
89 if options.mode == 'all':
90 options.mode = 'debug,release'
91 options.mode = options.mode.split(',')
92 options.arch = options.arch.split(',')
93 for mode in options.mode:
94 if not mode in ['debug', 'release']:
95 print("Unknown mode %s" % mode)
96 return False
97 for arch in options.arch:
98 if not arch in ['ia32', 'x64', 'simarm', 'arm', 'dartc']:
99 print("Unknown arch %s" % arch)
100 return False
101 return True
102
103
104def GetBuildRoot(mode, arch, sanitizer):
105 return utils.GetBuildRoot(HOST_OS, mode, arch, sanitizer)
106
107
108def GetDart(mode, arch, sanitizer):
109 executable = [abspath(join(GetBuildRoot(mode, arch, sanitizer), 'dart'))]
110 return executable
111
112
113def Main():
114 # Parse the options.
115 parser = BuildOptions()
116 (options, args) = parser.parse_args()
117 if not ProcessOptions(options):
118 parser.print_help()
119 return 1
120
121 chosen_benchmarks = ReadBenchmarkList(options.mode, 'BENCHMARKS',
122 options.core)
123
124 # Use arguments to filter the benchmarks.
125 if len(args) > 0:
126 filt = [re.compile(x.lower()) for x in args]
127 chosen_benchmarks = [b for b in chosen_benchmarks if match(b[0], filt)]
128
129 for mode in options.mode:
130 for arch in options.arch:
131 if options.executable is None:
132 # Construct the path to the dart binary.
133 executable = GetDart(mode, arch)
134 else:
135 executable = [options.executable]
136 for benchmark, vmargs, progargs in chosen_benchmarks:
137 command = executable
138 command = command + [
139 GetBenchmarkFile([benchmark, 'dart', benchmark + '.dart']),
140 ]
141 if options.verbose:
142 print(' '.join(command))
143 subprocess.call(command)
144 return 0
145
146
147if __name__ == '__main__':
148 sys.exit(Main())
void print(void *str)
Definition bridge.cpp:126
GetBuildRoot(mode, arch, sanitizer)
Definition benchmark.py:104
BuildOptions()
Definition benchmark.py:47
GetDart(mode, arch, sanitizer)
Definition benchmark.py:108
ReadBenchmarkList(mode, path, core)
Definition benchmark.py:36
GetBenchmarkFile(path)
Definition benchmark.py:31
ProcessOptions(options)
Definition benchmark.py:86
match(bench, filt)
Definition benchmark.py:23
GuessArchitecture()
Definition utils.py:42
GetBuildRoot(host_os, mode=None, arch=None, sanitizer=None)
Definition utils.py:143
GuessCpus()
Definition utils.py:55
GuessOS()
Definition utils.py:21