| OLD | NEW |
| 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 25 matching lines...) Expand all Loading... |
| 36 - 'avg_duration' - average duration of the targeted event | 36 - 'avg_duration' - average duration of the targeted event |
| 37 | 37 |
| 38 |benchmark_list_file| may reference the |target_os| global that will be any of | 38 |benchmark_list_file| may reference the |target_os| global that will be any of |
| 39 ['android', 'linux'], indicating the system on which the benchmarks are to be | 39 ['android', 'linux'], indicating the system on which the benchmarks are to be |
| 40 run. | 40 run. |
| 41 """ | 41 """ |
| 42 | 42 |
| 43 _logger = logging.getLogger() | 43 _logger = logging.getLogger() |
| 44 | 44 |
| 45 _BENCHMARK_APP = 'https://core.mojoapps.io/benchmark.mojo' | 45 _BENCHMARK_APP = 'https://core.mojoapps.io/benchmark.mojo' |
| 46 _CACHE_SERVICE_URL = 'mojo:url_response_disk_cache' |
| 46 | 47 |
| 47 # Additional time in seconds allocated per shell run to accommodate start-up. | 48 # Additional time in seconds allocated per shell run to accommodate start-up. |
| 48 # The shell should terminate before hitting this time out, it is an error if it | 49 # The shell should terminate before hitting this time out, it is an error if it |
| 49 # doesn't. | 50 # doesn't. |
| 50 _EXTRA_TIMEOUT = 20 | 51 _EXTRA_TIMEOUT = 20 |
| 51 | 52 |
| 52 | 53 |
| 53 def _run_benchmark(shell, shell_args, name, app, duration_seconds, measurements, | 54 def _run_benchmark(shell, shell_args, name, app, duration_seconds, measurements, |
| 54 verbose): | 55 cold_start, verbose): |
| 55 """Runs `benchmark.mojo` in a shell with correct arguments, parses and | 56 """Runs `benchmark.mojo` in shell with correct arguments, parses and |
| 56 presents the benchmark results. | 57 presents the benchmark results. |
| 57 """ | 58 """ |
| 58 timeout = duration_seconds + _EXTRA_TIMEOUT | 59 timeout = duration_seconds + _EXTRA_TIMEOUT |
| 59 benchmark_args = [] | 60 benchmark_args = [] |
| 60 benchmark_args.append('--app=' + app) | 61 benchmark_args.append('--app=' + app) |
| 61 benchmark_args.append('--duration=' + str(duration_seconds)) | 62 benchmark_args.append('--duration=' + str(duration_seconds)) |
| 62 for measurement in measurements: | 63 for measurement in measurements: |
| 63 benchmark_args.append(measurement) | 64 benchmark_args.append(measurement) |
| 65 |
| 66 shell_args = list(shell_args) |
| 64 shell_args.append(_BENCHMARK_APP) | 67 shell_args.append(_BENCHMARK_APP) |
| 65 shell_args.append('--args-for=%s %s' % (_BENCHMARK_APP, | 68 shell_args.append('--args-for=%s %s' % (_BENCHMARK_APP, |
| 66 ' '.join(benchmark_args))) | 69 ' '.join(benchmark_args))) |
| 70 |
| 71 if cold_start: |
| 72 shell_args.append('--args-for=%s %s' % (_CACHE_SERVICE_URL, '--clear')) |
| 73 |
| 67 if verbose: | 74 if verbose: |
| 68 print 'shell arguments: ' + str(shell_args) | 75 print 'shell arguments: ' + str(shell_args) |
| 69 print '[' + name + ']' | 76 print '[ %s ] %s' % (name, 'cold start' if cold_start else 'warm start') |
| 70 return_code, output, did_time_out = shell.run_and_get_output( | 77 return_code, output, did_time_out = shell.run_and_get_output( |
| 71 shell_args, timeout=timeout) | 78 shell_args, timeout=timeout) |
| 72 output_lines = [line.strip() for line in output.split('\n')] | 79 output_lines = [line.strip() for line in output.split('\n')] |
| 73 | 80 |
| 74 if return_code or did_time_out or 'benchmark succeeded' not in output_lines: | 81 if return_code or did_time_out or 'benchmark succeeded' not in output_lines: |
| 75 print 'timed out' if did_time_out else 'failed' | 82 print 'timed out' if did_time_out else 'failed' |
| 76 if return_code: | 83 if return_code: |
| 77 print 'Return code: ' + str(return_code) | 84 print 'Return code: ' + str(return_code) |
| 78 print 'Output: ' | 85 print 'Output: ' |
| 79 print output | 86 print output |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 benchmark_list = benchmark_list_params['benchmarks'] | 118 benchmark_list = benchmark_list_params['benchmarks'] |
| 112 | 119 |
| 113 succeeded = True | 120 succeeded = True |
| 114 for benchmark_spec in benchmark_list: | 121 for benchmark_spec in benchmark_list: |
| 115 name = benchmark_spec['name'] | 122 name = benchmark_spec['name'] |
| 116 app = benchmark_spec['app'] | 123 app = benchmark_spec['app'] |
| 117 duration = benchmark_spec['duration'] | 124 duration = benchmark_spec['duration'] |
| 118 shell_args = benchmark_spec.get('shell-args', []) + common_shell_args | 125 shell_args = benchmark_spec.get('shell-args', []) + common_shell_args |
| 119 measurements = benchmark_spec['measurements'] | 126 measurements = benchmark_spec['measurements'] |
| 120 _run_benchmark(shell, shell_args, name, app, duration, measurements, | 127 _run_benchmark(shell, shell_args, name, app, duration, measurements, |
| 121 script_args.verbose) | 128 cold_start=True, verbose=script_args.verbose) |
| 129 _run_benchmark(shell, shell_args, name, app, duration, measurements, |
| 130 cold_start=False, verbose=script_args.verbose) |
| 122 | 131 |
| 123 return 0 if succeeded else 1 | 132 return 0 if succeeded else 1 |
| 124 | 133 |
| 125 if __name__ == '__main__': | 134 if __name__ == '__main__': |
| 126 sys.exit(main()) | 135 sys.exit(main()) |
| OLD | NEW |