Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 optparse | 5 import optparse |
| 6 | 6 |
| 7 from py_utils import class_util | |
| 7 from telemetry import decorators | 8 from telemetry import decorators |
| 8 from telemetry.internal import story_runner | 9 from telemetry.internal import story_runner |
| 9 from telemetry.internal.util import command_line | 10 from telemetry.internal.util import command_line |
| 10 from telemetry.page import legacy_page_test | 11 from telemetry.page import legacy_page_test |
| 11 from telemetry.story import expectations | 12 from telemetry.story import expectations |
| 12 from telemetry.web_perf import timeline_based_measurement | 13 from telemetry.web_perf import timeline_based_measurement |
| 13 from tracing.value import histogram | 14 from tracing.value import histogram |
| 14 | 15 |
| 15 Disabled = decorators.Disabled | 16 Disabled = decorators.Disabled |
| 16 Enabled = decorators.Enabled | 17 Enabled = decorators.Enabled |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 | 66 |
| 66 def __init__(self, max_failures=None): | 67 def __init__(self, max_failures=None): |
| 67 """Creates a new Benchmark. | 68 """Creates a new Benchmark. |
| 68 | 69 |
| 69 Args: | 70 Args: |
| 70 max_failures: The number of story run's failures before bailing | 71 max_failures: The number of story run's failures before bailing |
| 71 from executing subsequent page runs. If None, we never bail. | 72 from executing subsequent page runs. If None, we never bail. |
| 72 """ | 73 """ |
| 73 self._expectations = None | 74 self._expectations = None |
| 74 self._max_failures = max_failures | 75 self._max_failures = max_failures |
| 75 self._has_original_tbm_options = ( | 76 # TODO: There should be an assertion here that checks that only one of |
| 76 self.CreateTimelineBasedMeasurementOptions.__func__ == | 77 # the following is true: |
| 77 Benchmark.CreateTimelineBasedMeasurementOptions.__func__) | 78 # * It's a TBM benchmark, with CreateCoreTimelineBasedMeasurementOptions |
| 78 has_original_create_page_test = ( | 79 # defined. |
| 79 self.CreatePageTest.__func__ == Benchmark.CreatePageTest.__func__) | 80 # * It's a legacy benchmark, with either CreatePageTest defined or |
| 80 assert self._has_original_tbm_options or has_original_create_page_test, ( | 81 # Benchmark.test set. |
| 81 'Cannot override both CreatePageTest and ' | 82 # See https://github.com/catapult-project/catapult/issues/3708 |
| 82 'CreateTimelineBasedMeasurementOptions.') | 83 |
| 83 | 84 |
| 84 # pylint: disable=unused-argument | 85 # pylint: disable=unused-argument |
| 85 @classmethod | 86 @classmethod |
| 86 def ShouldDisable(cls, possible_browser): | 87 def ShouldDisable(cls, possible_browser): |
| 87 """Override this method to disable a benchmark under specific conditions. | 88 """Override this method to disable a benchmark under specific conditions. |
| 88 | 89 |
| 89 Supports logic too complex for simple Enabled and Disabled decorators. | 90 Supports logic too complex for simple Enabled and Disabled decorators. |
| 90 Decorators are still respected in cases where this function returns False. | 91 Decorators are still respected in cases where this function returns False. |
| 91 """ | 92 """ |
| 92 return False | 93 return False |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 | 223 |
| 223 def GetOwnership(self): | 224 def GetOwnership(self): |
| 224 """Returns an Ownership Diagnostic containing the benchmark's information. | 225 """Returns an Ownership Diagnostic containing the benchmark's information. |
| 225 | 226 |
| 226 Returns: | 227 Returns: |
| 227 Diagnostic with the benchmark's owners' e-mails and component name | 228 Diagnostic with the benchmark's owners' e-mails and component name |
| 228 """ | 229 """ |
| 229 return histogram.Ownership( | 230 return histogram.Ownership( |
| 230 decorators.GetEmails(self), decorators.GetComponent(self)) | 231 decorators.GetEmails(self), decorators.GetComponent(self)) |
| 231 | 232 |
| 233 @decorators.Deprecated( | |
| 234 2017, 9, 1, 'Use CreateCoreTimelineBasedMeasurementOptions instead.') | |
| 232 def CreateTimelineBasedMeasurementOptions(self): | 235 def CreateTimelineBasedMeasurementOptions(self): |
| 233 """Return the TimelineBasedMeasurementOptions for this Benchmark. | 236 """See CreateCoreTimelineBasedMeasurementOptions.""" |
| 237 return self.CreateCoreTimelineBasedMeasurementOptions() | |
| 234 | 238 |
| 235 Override this method to configure a TimelineBasedMeasurement benchmark. | 239 def CreateCoreTimelineBasedMeasurementOptions(self): |
| 236 Otherwise, override CreatePageTest for PageTest tests. Do not override | 240 """Return the base TimelineBasedMeasurementOptions for this Benchmark. |
| 237 both methods. | 241 |
| 242 Additional chrome and atrace categories can be appended when running the | |
| 243 benchmark with the --extra-chrome-categories and --extra-atrace-categories | |
| 244 flags. | |
| 245 | |
| 246 Override this method to configure a TimelineBasedMeasurement benchmark. If | |
| 247 this is not a TimelineBasedMeasurement benchmark, override CreatePageTest | |
| 248 for PageTest tests. Do not override both methods. | |
| 238 """ | 249 """ |
| 239 return timeline_based_measurement.Options() | 250 return timeline_based_measurement.Options() |
| 240 | 251 |
| 252 def _GetTimelineBasedMeasurementOptions(self, options): | |
| 253 """Return all timeline based measurements for the curren benchmark run. | |
| 254 | |
| 255 This includes the benchmark-configured measurements in | |
| 256 CreateCoreTimelineBasedMeasurementOptions as well as the user-flag- | |
| 257 configured options from --extra-chrome-categories and | |
| 258 --extra-atrace-categories. | |
| 259 """ | |
| 260 # TODO(sullivan): the benchmark options should all be configured in | |
| 261 # CreateCoreTimelineBasedMeasurementOptions. Remove references to | |
| 262 # CreateTimelineBasedMeasurementOptions when it is fully deprecated. | |
| 263 # In the short term, if the benchmark overrides | |
| 264 # CreateTimelineBasedMeasurementOptions use the overridden version, | |
| 265 # otherwise call CreateCoreTimelineBasedMeasurementOptions. | |
| 266 # https://github.com/catapult-project/catapult/issues/3450 | |
| 267 tbm_options = None | |
| 268 if class_util.IsMethodOverridden( | |
| 269 Benchmark, self.__class__, 'CreateTimelineBasedMeasurementOptions'): | |
| 270 tbm_options = self.CreateTimelineBasedMeasurementOptions() | |
| 271 else: | |
| 272 tbm_options = self.CreateCoreTimelineBasedMeasurementOptions() | |
| 273 if options and options.extra_chrome_categories: | |
| 274 # If Chrome tracing categories for this benchmark are not already | |
| 275 # enabled, there is probably a good reason why (for example, maybe | |
| 276 # it is the benchmark that runs a BattOr without Chrome to get an energy | |
| 277 # baseline). Don't change whether Chrome tracing is enabled. | |
| 278 assert tbm_options.config.enable_chrome_trace, ( | |
| 279 'This benchmark does not support Chrome tracing.') | |
| 280 tbm_options.config.chrome_trace_config.category_filter.AddFilterString( | |
| 281 options.extra_chrome_categories) | |
| 282 if options and options.extra_atrace_categories: | |
| 283 # Many benchmarks on Android run without atrace by default. Hopefully the | |
| 284 # user understands that atrace is only supported on Android when setting | |
| 285 # this option. | |
| 286 tbm_options.config.enable_atrace_trace = True | |
| 287 | |
| 288 categories = tbm_options.config.atrace_config.categories | |
|
nednguyen
2017/07/13 18:12:41
If the option is restricted to string, we can be s
sullivan
2017/07/13 18:33:14
I restricted the --enable-atrace-categories flag t
| |
| 289 if type(categories) != list: | |
| 290 # Categories can either be a list or comma-separated string. | |
| 291 # https://github.com/catapult-project/catapult/issues/3712 | |
| 292 categories = categories.split(',') | |
| 293 for category in options.extra_atrace_categories.split(','): | |
| 294 if category not in categories: | |
| 295 categories.append(category) | |
| 296 tbm_options.config.atrace_config.categories = categories | |
| 297 return tbm_options | |
| 298 | |
| 299 | |
| 241 def CreatePageTest(self, options): # pylint: disable=unused-argument | 300 def CreatePageTest(self, options): # pylint: disable=unused-argument |
| 242 """Return the PageTest for this Benchmark. | 301 """Return the PageTest for this Benchmark. |
| 243 | 302 |
| 244 Override this method for PageTest tests. | 303 Override this method for PageTest tests. |
| 245 Override, override CreateTimelineBasedMeasurementOptions to configure | 304 Override, CreateCoreTimelineBasedMeasurementOptions to configure |
| 246 TimelineBasedMeasurement tests. Do not override both methods. | 305 TimelineBasedMeasurement tests. Do not override both methods. |
| 247 | 306 |
| 248 Args: | 307 Args: |
| 249 options: a browser_options.BrowserFinderOptions instance | 308 options: a browser_options.BrowserFinderOptions instance |
| 250 Returns: | 309 Returns: |
| 251 |test()| if |test| is a PageTest class. | 310 |test()| if |test| is a PageTest class. |
| 252 Otherwise, a TimelineBasedMeasurement instance. | 311 Otherwise, a TimelineBasedMeasurement instance. |
| 253 """ | 312 """ |
| 254 is_page_test = issubclass(self.test, legacy_page_test.LegacyPageTest) | 313 is_page_test = issubclass(self.test, legacy_page_test.LegacyPageTest) |
| 255 is_tbm = self.test == timeline_based_measurement.TimelineBasedMeasurement | 314 is_tbm = self.test == timeline_based_measurement.TimelineBasedMeasurement |
| 256 if not is_page_test and not is_tbm: | 315 if not is_page_test and not is_tbm: |
| 257 raise TypeError('"%s" is not a PageTest or a TimelineBasedMeasurement.' % | 316 raise TypeError('"%s" is not a PageTest or a TimelineBasedMeasurement.' % |
| 258 self.test.__name__) | 317 self.test.__name__) |
| 259 if is_page_test: | 318 if is_page_test: |
| 260 assert self._has_original_tbm_options, ( | 319 # TODO: assert that CreateCoreTimelineBasedMeasurementOptions is not |
| 261 'Cannot override CreateTimelineBasedMeasurementOptions ' | 320 # defined. That's incorrect for a page test. See |
| 262 'with a PageTest.') | 321 # https://github.com/catapult-project/catapult/issues/3708 |
| 263 return self.test() # pylint: disable=no-value-for-parameter | 322 return self.test() # pylint: disable=no-value-for-parameter |
| 264 | 323 |
| 265 opts = self.CreateTimelineBasedMeasurementOptions() | 324 opts = self._GetTimelineBasedMeasurementOptions(options) |
| 266 self.SetupTraceRerunOptions(options, opts) | 325 self.SetupTraceRerunOptions(options, opts) |
| 267 return timeline_based_measurement.TimelineBasedMeasurement(opts) | 326 return timeline_based_measurement.TimelineBasedMeasurement(opts) |
| 268 | 327 |
| 269 def CreateStorySet(self, options): | 328 def CreateStorySet(self, options): |
| 270 """Creates the instance of StorySet used to run the benchmark. | 329 """Creates the instance of StorySet used to run the benchmark. |
| 271 | 330 |
| 272 Can be overridden by subclasses. | 331 Can be overridden by subclasses. |
| 273 """ | 332 """ |
| 274 del options # unused | 333 del options # unused |
| 275 # TODO(aiolos, nednguyen, eakufner): replace class attribute page_set with | 334 # TODO(aiolos, nednguyen, eakufner): replace class attribute page_set with |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 305 """ | 364 """ |
| 306 return expectations.StoryExpectations() | 365 return expectations.StoryExpectations() |
| 307 | 366 |
| 308 | 367 |
| 309 def AddCommandLineArgs(parser): | 368 def AddCommandLineArgs(parser): |
| 310 story_runner.AddCommandLineArgs(parser) | 369 story_runner.AddCommandLineArgs(parser) |
| 311 | 370 |
| 312 | 371 |
| 313 def ProcessCommandLineArgs(parser, args): | 372 def ProcessCommandLineArgs(parser, args): |
| 314 story_runner.ProcessCommandLineArgs(parser, args) | 373 story_runner.ProcessCommandLineArgs(parser, args) |
| OLD | NEW |