Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: mojo/devtools/common/mojo_benchmark

Issue 1400003005: Refactor mojo_benchmark to get rid of warm/cold start special cases. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Address Trung's comments. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Runner for Mojo application benchmarks.""" 6 """Runner for Mojo application benchmarks."""
7 7
8 import argparse 8 import argparse
9 import logging 9 import logging
10 import sys 10 import sys
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 ['android', 'linux'], indicating the system on which the benchmarks are to be 43 ['android', 'linux'], indicating the system on which the benchmarks are to be
44 run. 44 run.
45 """ 45 """
46 46
47 _logger = logging.getLogger() 47 _logger = logging.getLogger()
48 48
49 _BENCHMARK_APP = 'https://core.mojoapps.io/benchmark.mojo' 49 _BENCHMARK_APP = 'https://core.mojoapps.io/benchmark.mojo'
50 _CACHE_SERVICE_URL = 'mojo:url_response_disk_cache' 50 _CACHE_SERVICE_URL = 'mojo:url_response_disk_cache'
51 _NETWORK_SERVICE_URL = 'mojo:network_service' 51 _NETWORK_SERVICE_URL = 'mojo:network_service'
52 52
53 _COLD_START_SHELL_ARGS = [
54 '--args-for=%s %s' % (_CACHE_SERVICE_URL, '--clear'),
55 '--args-for=%s %s' % (_NETWORK_SERVICE_URL, '--clear'),
56 ]
57
53 # Additional time in seconds allocated per shell run to accommodate start-up. 58 # Additional time in seconds allocated per shell run to accommodate start-up.
54 # The shell should terminate before hitting this time out, it is an error if it 59 # The shell should terminate before hitting this time out, it is an error if it
55 # doesn't. 60 # doesn't.
56 _EXTRA_TIMEOUT = 20 61 _EXTRA_TIMEOUT = 20
57 62
58 63
59 def _get_output_file(shell, name, cold_start): 64 def _generate_benchmark_variants(benchmark_spec):
60 file_name = 'benchmark-%s-%s-%s.trace' % ( 65 """Generates benchmark specifications for individual variants of the given
61 name.replace(' ', '_'), 66 benchmark: cold start and warm start.
62 'cold_start' if cold_start else 'warm_start', 67
63 time.strftime('%Y%m%d%H%M%S')) 68 Returns:
64 return file_name 69 A list of benchmark specs corresponding to individual variants of the given
70 benchmark.
71 """
72 variants = []
73 # Cold start.
74 variants.append({
75 'name': benchmark_spec['name'] + ' (cold start)',
76 'app': benchmark_spec['app'],
77 'duration': benchmark_spec['duration'],
78 'measurements': benchmark_spec['measurements'],
79 'shell-args': benchmark_spec.get('shell-args',
80 []) + _COLD_START_SHELL_ARGS})
81 # Warm start.
82 variants.append({
83 'name': benchmark_spec['name'] + ' (warm start)',
84 'app': benchmark_spec['app'],
85 'duration': benchmark_spec['duration'],
86 'measurements': benchmark_spec['measurements'],
87 'shell-args': benchmark_spec.get('shell-args', [])})
88 return variants
65 89
66 90
67 def _run_benchmark(shell, shell_args, name, app, duration_seconds, measurements, 91 def _run_benchmark(shell, shell_args, name, app, duration_seconds, measurements,
68 cold_start, verbose, android, save_traces): 92 verbose, android, save_traces):
69 """Runs `benchmark.mojo` in shell with correct arguments, parses and 93 """Runs `benchmark.mojo` in shell with correct arguments, parses and
70 presents the benchmark results. 94 presents the benchmark results.
71 """ 95 """
72 timeout = duration_seconds + _EXTRA_TIMEOUT 96 timeout = duration_seconds + _EXTRA_TIMEOUT
73 benchmark_args = [] 97 benchmark_args = []
74 benchmark_args.append('--app=' + app) 98 benchmark_args.append('--app=' + app)
75 benchmark_args.append('--duration=' + str(duration_seconds)) 99 benchmark_args.append('--duration=' + str(duration_seconds))
76 100
77 output_file = None 101 output_file = None
78 device_output_file = None 102 device_output_file = None
79 if save_traces: 103 if save_traces:
80 output_file = _get_output_file(shell, name, cold_start) 104 output_file = 'benchmark-%s-%s.trace' % (name.replace(' ', '_'),
105 time.strftime('%Y%m%d%H%M%S'))
81 if android: 106 if android:
82 device_output_file = os.path.join(shell.get_tmp_dir_path(), output_file) 107 device_output_file = os.path.join(shell.get_tmp_dir_path(), output_file)
83 benchmark_args.append('--trace-output=' + device_output_file) 108 benchmark_args.append('--trace-output=' + device_output_file)
84 else: 109 else:
85 benchmark_args.append('--trace-output=' + output_file) 110 benchmark_args.append('--trace-output=' + output_file)
86 111
87 for measurement in measurements: 112 for measurement in measurements:
88 benchmark_args.append(measurement) 113 benchmark_args.append(measurement)
89 114
90 shell_args = list(shell_args) 115 shell_args = list(shell_args)
91 shell_args.append(_BENCHMARK_APP) 116 shell_args.append(_BENCHMARK_APP)
92 shell_args.append('--force-offline-by-default') 117 shell_args.append('--force-offline-by-default')
93 shell_args.append('--args-for=%s %s' % (_BENCHMARK_APP, 118 shell_args.append('--args-for=%s %s' % (_BENCHMARK_APP,
94 ' '.join(benchmark_args))) 119 ' '.join(benchmark_args)))
95 120
96 if cold_start:
97 shell_args.append('--args-for=%s %s' % (_CACHE_SERVICE_URL, '--clear'))
98 shell_args.append('--args-for=%s %s' % (_NETWORK_SERVICE_URL, '--clear'))
99
100 if verbose: 121 if verbose:
101 print 'shell arguments: ' + str(shell_args) 122 print 'shell arguments: ' + str(shell_args)
102 print '[ %s ] %s' % (name, 'cold start' if cold_start else 'warm start') 123 print '[ %s ]' % name
103 return_code, output, did_time_out = shell.run_and_get_output( 124 return_code, output, did_time_out = shell.run_and_get_output(
104 shell_args, timeout=timeout) 125 shell_args, timeout=timeout)
105 output_lines = [line.strip() for line in output.split('\n')] 126 output_lines = [line.strip() for line in output.split('\n')]
106 127
107 if return_code or did_time_out or 'benchmark succeeded' not in output_lines: 128 if return_code or did_time_out or 'benchmark succeeded' not in output_lines:
108 print 'timed out' if did_time_out else 'failed' 129 print 'timed out' if did_time_out else 'failed'
109 if return_code: 130 if return_code:
110 print 'Return code: ' + str(return_code) 131 print 'Return code: ' + str(return_code)
111 print 'Output: ' 132 print 'Output: '
112 print output 133 print output
(...skipping 26 matching lines...) Expand all
139 160
140 try: 161 try:
141 shell, common_shell_args = shell_arguments.get_shell(config, []) 162 shell, common_shell_args = shell_arguments.get_shell(config, [])
142 except shell_arguments.ShellConfigurationException as e: 163 except shell_arguments.ShellConfigurationException as e:
143 print e 164 print e
144 return 1 165 return 1
145 166
146 target_os = 'android' if script_args.android else 'linux' 167 target_os = 'android' if script_args.android else 'linux'
147 benchmark_list_params = {"target_os": target_os} 168 benchmark_list_params = {"target_os": target_os}
148 exec script_args.benchmark_list_file in benchmark_list_params 169 exec script_args.benchmark_list_file in benchmark_list_params
149 benchmark_list = benchmark_list_params['benchmarks']
150 170
151 succeeded = True 171 succeeded = True
152 for benchmark_spec in benchmark_list: 172 for benchmark_spec in benchmark_list_params['benchmarks']:
153 name = benchmark_spec['name'] 173 for variant_spec in _generate_benchmark_variants(benchmark_spec):
154 app = benchmark_spec['app'] 174 name = variant_spec['name']
155 duration = benchmark_spec['duration'] 175 app = variant_spec['app']
156 shell_args = benchmark_spec.get('shell-args', []) + common_shell_args 176 duration = variant_spec['duration']
157 measurements = benchmark_spec['measurements'] 177 shell_args = variant_spec.get('shell-args', []) + common_shell_args
158 _run_benchmark(shell, shell_args, name, app, duration, measurements, 178 measurements = variant_spec['measurements']
159 cold_start=True, verbose=script_args.verbose, 179 _run_benchmark(shell, shell_args, name, app, duration, measurements,
160 android=script_args.android, 180 script_args.verbose, script_args.android,
161 save_traces=script_args.save_traces) 181 script_args.save_traces)
162 _run_benchmark(shell, shell_args, name, app, duration, measurements,
163 cold_start=False, verbose=script_args.verbose,
164 android=script_args.android,
165 save_traces=script_args.save_traces)
166 182
167 return 0 if succeeded else 1 183 return 0 if succeeded else 1
168 184
169 if __name__ == '__main__': 185 if __name__ == '__main__':
170 sys.exit(main()) 186 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698