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

Side by Side Diff: telemetry/telemetry/benchmark.py

Issue 2965383002: WIP: Add support for additional flag-specified tracing categories. (Closed)
Patch Set: addressed review comments Created 3 years, 5 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
OLDNEW
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
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
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, 7, 29, '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 # CreateCoreTimelineBasedMeasurementOptions when it is fully deprecated.
263 # In the short term, if the benchmark overrides
264 # CreateCoreTimelineBasedMeasurementOptions use the overridden version,
265 # otherwise call CreateCoreTimelineBasedMeasurementOptions.
266 # https://github.com/catapult-project/catapult/issues/3450
267 tbm_options = None
268 assert not (
269 class_util.IsMethodOverridden(
270 Benchmark, self.__class__,
271 'CreateTimelineBasedMeasurementOptions') and
272 class_util.IsMethodOverridden(
273 Benchmark, self.__class__,
274 'CreateCoreTimelineBasedMeasurementOptions')), (
275 'Benchmarks should override CreateCoreTimelineBasedMeasurementOptions '
276 'and NOT also CreateTimelineBasedMeasurementOptions.')
277 if class_util.IsMethodOverridden(
278 Benchmark, self.__class__, 'CreateCoreTimelineBasedMeasurementOptions'):
279 tbm_options = self.CreateCoreTimelineBasedMeasurementOptions()
280 else:
281 tbm_options = self.CreateTimelineBasedMeasurementOptions()
282 if options and options.extra_chrome_categories:
283 # If Chrome tracing categories for this benchmark are not already
284 # enabled, there is probably a good reason why (for example, maybe
285 # it is the benchmark that runs a BattOr without Chrome to get an energy
286 # baseline). Don't change whether Chrome tracing is enabled.
287 assert tbm_options.config.enable_chrome_trace, (
288 'This benchmark does not support Chrome tracing.')
289 tbm_options.config.chrome_trace_config.category_filter.AddFilterString(
290 options.extra_chrome_categories)
291 if options and options.extra_atrace_categories:
292 # Many benchmarks on Android run without atrace by default. Hopefully the
293 # user understands that atrace is only supported on Android when setting
294 # this option.
295 tbm_options.config.enable_atrace_trace = True
296
297 categories = tbm_options.config.atrace_config.categories
298 if type(categories) != list:
299 # Categories can either be a list or comma-separated string.
300 # https://github.com/catapult-project/catapult/issues/3712
301 categories = categories.split(',')
302 for category in options.extra_atrace_categories.split(','):
303 if category not in categories:
304 categories.append(category)
305 tbm_options.config.atrace_config.categories = categories
306 return tbm_options
307
308
241 def CreatePageTest(self, options): # pylint: disable=unused-argument 309 def CreatePageTest(self, options): # pylint: disable=unused-argument
242 """Return the PageTest for this Benchmark. 310 """Return the PageTest for this Benchmark.
243 311
244 Override this method for PageTest tests. 312 Override this method for PageTest tests.
245 Override, override CreateTimelineBasedMeasurementOptions to configure 313 Override, CreateCoreTimelineBasedMeasurementOptions to configure
246 TimelineBasedMeasurement tests. Do not override both methods. 314 TimelineBasedMeasurement tests. Do not override both methods.
247 315
248 Args: 316 Args:
249 options: a browser_options.BrowserFinderOptions instance 317 options: a browser_options.BrowserFinderOptions instance
250 Returns: 318 Returns:
251 |test()| if |test| is a PageTest class. 319 |test()| if |test| is a PageTest class.
252 Otherwise, a TimelineBasedMeasurement instance. 320 Otherwise, a TimelineBasedMeasurement instance.
253 """ 321 """
254 is_page_test = issubclass(self.test, legacy_page_test.LegacyPageTest) 322 is_page_test = issubclass(self.test, legacy_page_test.LegacyPageTest)
255 is_tbm = self.test == timeline_based_measurement.TimelineBasedMeasurement 323 is_tbm = self.test == timeline_based_measurement.TimelineBasedMeasurement
256 if not is_page_test and not is_tbm: 324 if not is_page_test and not is_tbm:
257 raise TypeError('"%s" is not a PageTest or a TimelineBasedMeasurement.' % 325 raise TypeError('"%s" is not a PageTest or a TimelineBasedMeasurement.' %
258 self.test.__name__) 326 self.test.__name__)
259 if is_page_test: 327 if is_page_test:
260 assert self._has_original_tbm_options, ( 328 # TODO: assert that CreateCoreTimelineBasedMeasurementOptions is not
261 'Cannot override CreateTimelineBasedMeasurementOptions ' 329 # defined. That's incorrect for a page test. See
262 'with a PageTest.') 330 # https://github.com/catapult-project/catapult/issues/3708
263 return self.test() # pylint: disable=no-value-for-parameter 331 return self.test() # pylint: disable=no-value-for-parameter
264 332
265 opts = self.CreateTimelineBasedMeasurementOptions() 333 opts = self._GetTimelineBasedMeasurementOptions(options)
266 self.SetupTraceRerunOptions(options, opts) 334 self.SetupTraceRerunOptions(options, opts)
267 return timeline_based_measurement.TimelineBasedMeasurement(opts) 335 return timeline_based_measurement.TimelineBasedMeasurement(opts)
268 336
269 def CreateStorySet(self, options): 337 def CreateStorySet(self, options):
270 """Creates the instance of StorySet used to run the benchmark. 338 """Creates the instance of StorySet used to run the benchmark.
271 339
272 Can be overridden by subclasses. 340 Can be overridden by subclasses.
273 """ 341 """
274 del options # unused 342 del options # unused
275 # TODO(aiolos, nednguyen, eakufner): replace class attribute page_set with 343 # TODO(aiolos, nednguyen, eakufner): replace class attribute page_set with
(...skipping 29 matching lines...) Expand all
305 """ 373 """
306 return expectations.StoryExpectations() 374 return expectations.StoryExpectations()
307 375
308 376
309 def AddCommandLineArgs(parser): 377 def AddCommandLineArgs(parser):
310 story_runner.AddCommandLineArgs(parser) 378 story_runner.AddCommandLineArgs(parser)
311 379
312 380
313 def ProcessCommandLineArgs(parser, args): 381 def ProcessCommandLineArgs(parser, args):
314 story_runner.ProcessCommandLineArgs(parser, args) 382 story_runner.ProcessCommandLineArgs(parser, args)
OLDNEW
« no previous file with comments | « telemetry/examples/benchmarks/tbm_benchmark.py ('k') | telemetry/telemetry/benchmark_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698