| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import os | 6 import os |
| 7 import logging | 7 import logging |
| 8 import platform | 8 import platform |
| 9 import re | 9 import re |
| 10 import subprocess | 10 import subprocess |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return '%s\nError running tryjob.' % self.args[0] | 71 return '%s\nError running tryjob.' % self.args[0] |
| 72 | 72 |
| 73 | 73 |
| 74 def _GetTrybotList(builders): | 74 def _GetTrybotList(builders): |
| 75 builders = ['%s' % bot.replace('_perf_bisect', '').replace('_', '-') | 75 builders = ['%s' % bot.replace('_perf_bisect', '').replace('_', '-') |
| 76 for bot in builders] | 76 for bot in builders] |
| 77 builders.extend(INCLUDE_BOTS) | 77 builders.extend(INCLUDE_BOTS) |
| 78 return sorted(builders) | 78 return sorted(builders) |
| 79 | 79 |
| 80 | 80 |
| 81 def _GetBotPlatformFromTrybotName(trybot_name): |
| 82 os_names = ['linux', 'android', 'mac', 'win'] |
| 83 try: |
| 84 return next(b for b in os_names if b in trybot_name) |
| 85 except StopIteration: |
| 86 raise TrybotError('Trybot "%s" unsupported for tryjobs.' % trybot_name) |
| 87 |
| 88 |
| 81 def _GetBuilderNames(trybot_name, builders): | 89 def _GetBuilderNames(trybot_name, builders): |
| 82 """ Return platform and its available bot name as dictionary.""" | 90 """ Return platform and its available bot name as dictionary.""" |
| 83 os_names = ['linux', 'android', 'mac', 'win'] | 91 os_names = ['linux', 'android', 'mac', 'win'] |
| 84 if 'all' not in trybot_name: | 92 if 'all' not in trybot_name: |
| 85 bot = ['%s_perf_bisect' % trybot_name.replace('-', '_')] | 93 bot = ['%s_perf_bisect' % trybot_name.replace('-', '_')] |
| 86 try: | 94 bot_platform = _GetBotPlatformFromTrybotName(trybot_name) |
| 87 bot_platform = next(b for b in os_names if b in trybot_name) | |
| 88 except StopIteration: | |
| 89 raise TrybotError('Trybot "%s" unsupported for tryjobs.' % trybot_name) | |
| 90 if 'x64' in trybot_name: | 95 if 'x64' in trybot_name: |
| 91 bot_platform += '-x64' | 96 bot_platform += '-x64' |
| 92 return {bot_platform: bot} | 97 return {bot_platform: bot} |
| 93 | 98 |
| 94 platform_and_bots = {} | 99 platform_and_bots = {} |
| 95 for os_name in os_names: | 100 for os_name in os_names: |
| 96 platform_and_bots[os_name] = [bot for bot in builders if os_name in bot] | 101 platform_and_bots[os_name] = [bot for bot in builders if os_name in bot] |
| 97 | 102 |
| 98 # Special case for Windows x64, consider it as separate platform | 103 # Special case for Windows x64, consider it as separate platform |
| 99 # config config should contain target_arch=x64 and --browser=release_x64. | 104 # config config should contain target_arch=x64 and --browser=release_x64. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 formatter_class=argparse.RawTextHelpFormatter) | 180 formatter_class=argparse.RawTextHelpFormatter) |
| 176 return parser | 181 return parser |
| 177 | 182 |
| 178 @classmethod | 183 @classmethod |
| 179 def ProcessCommandLineArgs(cls, parser, options, extra_args, environment): | 184 def ProcessCommandLineArgs(cls, parser, options, extra_args, environment): |
| 180 del environment # unused | 185 del environment # unused |
| 181 for arg in extra_args: | 186 for arg in extra_args: |
| 182 if arg == '--browser' or arg.startswith('--browser='): | 187 if arg == '--browser' or arg.startswith('--browser='): |
| 183 parser.error('--browser=... is not allowed when running trybot.') | 188 parser.error('--browser=... is not allowed when running trybot.') |
| 184 all_benchmarks = discover.DiscoverClasses( | 189 all_benchmarks = discover.DiscoverClasses( |
| 185 start_dir=path_util.GetPerfBenchmarksDir(), | 190 start_dir=path_util.GetPerfBenchmarksDir(), |
| 186 top_level_dir=path_util.GetPerfDir(), | 191 top_level_dir=path_util.GetPerfDir(), |
| 187 base_class=benchmark.Benchmark).values() | 192 base_class=benchmark.Benchmark).values() |
| 188 all_benchmark_names = [b.Name() for b in all_benchmarks] | 193 all_benchmark_names = [b.Name() for b in all_benchmarks] |
| 189 if options.benchmark_name not in all_benchmark_names: | 194 all_benchmarks_by_names = {b.Name(): b for b in all_benchmarks} |
| 195 benchmark_class = all_benchmarks_by_names.get(options.benchmark_name, None) |
| 196 if not benchmark_class: |
| 190 possible_benchmark_names = matching.GetMostLikelyMatchedObject( | 197 possible_benchmark_names = matching.GetMostLikelyMatchedObject( |
| 191 all_benchmark_names, options.benchmark_name) | 198 all_benchmark_names, options.benchmark_name) |
| 192 parser.error( | 199 parser.error( |
| 193 'No benchmark named "%s". Do you mean any of those benchmarks ' | 200 'No benchmark named "%s". Do you mean any of those benchmarks ' |
| 194 'below?\n%s' % | 201 'below?\n%s' % |
| 195 (options.benchmark_name, '\n'.join(possible_benchmark_names))) | 202 (options.benchmark_name, '\n'.join(possible_benchmark_names))) |
| 203 is_benchmark_disabled, reason = cls.IsBenchmarkDisabledOnTrybotPlatform( |
| 204 benchmark_class, options.trybot) |
| 205 also_run_disabled_option = '--also-run-disabled-tests' |
| 206 if is_benchmark_disabled and also_run_disabled_option not in extra_args: |
| 207 parser.error('%s To run the benchmark on trybot anyway, add ' |
| 208 '%s option.' % (reason, also_run_disabled_option)) |
| 209 |
| 210 @classmethod |
| 211 def IsBenchmarkDisabledOnTrybotPlatform(cls, benchmark_class, trybot_name): |
| 212 """ Return whether benchmark will be disabled on trybot platform. |
| 213 |
| 214 Note that we cannot tell with certainty whether the benchmark will be |
| 215 disabled on the trybot platform since the disable logic in ShouldDisable() |
| 216 can be very dynamic and can only be verified on the trybot server platform. |
| 217 |
| 218 We are biased on the side of enabling the benchmark, and attempt to |
| 219 early discover whether the benchmark will be disabled as our best. |
| 220 |
| 221 It should never be the case that the benchmark will be enabled on the test |
| 222 platform but this method returns True. |
| 223 |
| 224 Returns: |
| 225 A tuple (is_benchmark_disabled, reason) whereas |is_benchmark_disabled| is |
| 226 a boolean that tells whether we are sure that the benchmark will be |
| 227 disabled, and |reason| is a string that shows the reason why we think the |
| 228 benchmark is disabled for sure. |
| 229 """ |
| 230 benchmark_name = benchmark_class.Name() |
| 231 benchmark_disabled_strings = set() |
| 232 if hasattr(benchmark_class, '_disabled_strings'): |
| 233 # pylint: disable=protected-access |
| 234 benchmark_disabled_strings = benchmark_class._disabled_strings |
| 235 # pylint: enable=protected-access |
| 236 if 'all' in benchmark_disabled_strings: |
| 237 return True, 'Benchmark %s is disabled on all platform.' % benchmark_name |
| 238 if trybot_name == 'all': |
| 239 return False, '' |
| 240 trybot_platform = _GetBotPlatformFromTrybotName(trybot_name) |
| 241 if trybot_platform in benchmark_disabled_strings: |
| 242 return True, ( |
| 243 "Benchmark %s is disabled on %s, and trybot's platform is %s." % |
| 244 (benchmark_name, ', '.join(benchmark_disabled_strings), |
| 245 trybot_platform)) |
| 246 benchmark_enabled_strings = None |
| 247 if hasattr(benchmark_class, '_enabled_strings'): |
| 248 # pylint: disable=protected-access |
| 249 benchmark_enabled_strings = benchmark_class._enabled_strings |
| 250 # pylint: enable=protected-access |
| 251 if (benchmark_enabled_strings and |
| 252 trybot_platform not in benchmark_enabled_strings and |
| 253 'all' not in benchmark_enabled_strings): |
| 254 return True, ( |
| 255 "Benchmark %s is only enabled on %s, and trybot's platform is %s." % |
| 256 (benchmark_name, ', '.join(benchmark_enabled_strings), |
| 257 trybot_platform)) |
| 258 if benchmark_class.ShouldDisable != benchmark.Benchmark.ShouldDisable: |
| 259 logging.warning( |
| 260 'Benchmark %s has ShouldDisable() method defined. If your trybot run ' |
| 261 'does not produce any results, it is possible that the benchmark ' |
| 262 'is disabled on the target trybot platform.', benchmark_name) |
| 263 return False, '' |
| 196 | 264 |
| 197 @classmethod | 265 @classmethod |
| 198 def AddCommandLineArgs(cls, parser, environment): | 266 def AddCommandLineArgs(cls, parser, environment): |
| 199 del environment # unused | 267 del environment # unused |
| 200 available_bots = _GetTrybotList(cls._GetBuilderList()) | 268 available_bots = _GetTrybotList(cls._GetBuilderList()) |
| 201 parser.add_argument( | 269 parser.add_argument( |
| 202 'trybot', choices=available_bots, | 270 'trybot', choices=available_bots, |
| 203 help=('specify which bots to run telemetry benchmarks on. ' | 271 help=('specify which bots to run telemetry benchmarks on. ' |
| 204 ' Allowed values are:\n' + '\n'.join(available_bots)), | 272 ' Allowed values are:\n' + '\n'.join(available_bots)), |
| 205 metavar='<trybot name>') | 273 metavar='<trybot name>') |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 return ERROR # pylint: disable=lost-exception | 502 return ERROR # pylint: disable=lost-exception |
| 435 logging.info('Checked out original branch: %s', original_branchname) | 503 logging.info('Checked out original branch: %s', original_branchname) |
| 436 returncode, out, err = _RunProcess( | 504 returncode, out, err = _RunProcess( |
| 437 [_GIT_CMD, 'branch', '-D', 'telemetry-tryjob']) | 505 [_GIT_CMD, 'branch', '-D', 'telemetry-tryjob']) |
| 438 if returncode: | 506 if returncode: |
| 439 logging.error('Could not delete telemetry-tryjob branch. ' | 507 logging.error('Could not delete telemetry-tryjob branch. ' |
| 440 'Please delete it manually: %s', err) | 508 'Please delete it manually: %s', err) |
| 441 return ERROR # pylint: disable=lost-exception | 509 return ERROR # pylint: disable=lost-exception |
| 442 logging.info('Deleted temp branch: telemetry-tryjob') | 510 logging.info('Deleted temp branch: telemetry-tryjob') |
| 443 return SUCCESS | 511 return SUCCESS |
| OLD | NEW |