Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from telemetry.page import page_measurement | |
|
tonyg
2014/02/26 17:20:04
uber nit: alphabetize
| |
| 6 from metrics import timeline as timeline_module | |
| 7 from metrics import timeline_based_metric_request as tbmr_module | |
| 8 | |
| 9 | |
| 10 SMOOTHNESS_METRIC_TYPE = 'smoothness' | |
| 11 | |
| 12 | |
| 13 # TimelineBasedMeasurement considers all instrumentation as producing a single | |
| 14 # timeline. But, depending on the amount of instrumentation that is enabled, | |
| 15 # overhead increases. The user of the measurement must therefore chose between | |
| 16 # a few levels of instrumentation. | |
| 17 MINIMUM_INSTRUMENTATION_LEVEL = 'minimum' | |
| 18 FIVE_PERCENT_OVERHEAD_INSTRUMENTATION_LEVEL = 'five-percent-overhead' | |
| 19 DEBUG_INSTRUMENTATION_LEVEL = 'debug' | |
| 20 | |
| 21 ALL_INSTRUMENTATION_LEVELS = [ | |
|
tonyg
2014/02/26 17:20:04
These levels are an awesome idea :)
I'm wondering
| |
| 22 MINIMUM_INSTRUMENTATION_LEVEL, | |
| 23 FIVE_PERCENT_OVERHEAD_INSTRUMENTATION_LEVEL, | |
| 24 DEBUG_INSTRUMENTATION_LEVEL | |
| 25 ] | |
| 26 | |
| 27 | |
| 28 class _TimelineBasedMetrics(object): | |
| 29 def __init__(self, model, renderer_thread): | |
| 30 self._model = model | |
| 31 self._renderer_thread = renderer_thread | |
| 32 | |
| 33 def FindTimelineMetricRequests(self): | |
| 34 # TODO(nduca): Add support for page-load metric request. | |
| 35 return [tbmr_module.TimelineBasedMetricRequest(event) for | |
| 36 event in self._renderer_thread.IterAllAsyncSlices() | |
| 37 if tbmr_module.IsTimelineMetricRequest(event.name)] | |
| 38 | |
| 39 def CreateMetricsForTimelineMetricRequest(self, request): | |
| 40 if request.metric_type == SMOOTHNESS_METRIC_TYPE: | |
| 41 return [] # TODO(nduca): Hook up a real metric. | |
| 42 raise Exception('Unrecognized metric type: %s' % request.metric_type) | |
|
nednguyen
2014/02/26 01:00:10
I think eventually we will want this to be configu
| |
| 43 | |
| 44 def AddResults(self, results): | |
| 45 requests = self.FindTimelineMetricRequests() | |
| 46 if len(requests) == 0: | |
| 47 raise Exception('Expected at least one request from the page') | |
| 48 for request in requests: | |
| 49 metrics = self.CreateMetricsForTimelineMetricRequest(request) | |
| 50 for m in metrics: | |
| 51 m.AddResults(self._model, self._renderer_thread, | |
| 52 request, results) | |
| 53 | |
| 54 | |
| 55 class TimelineBasedMeasurement(page_measurement.PageMeasurement): | |
| 56 """ A meta measurement shifts the burden of what metrics to collect onto | |
| 57 the page under test. Instead of the measurement having a fixed set of values | |
| 58 it collects about the page, the page being tested issues a set of standard | |
| 59 calls to the user timing API specifying time spans of interest for which it | |
| 60 wants metrics, and what kind of metrics are requested for that time range. The | |
| 61 meta measurement object collects a trace and these metric requests, then | |
| 62 generates result values based on matching those requests with the appropriate | |
| 63 timeline metrics. """ | |
| 64 def __init__(self): | |
| 65 super(TimelineBasedMeasurement, self).__init__('smoothness') | |
| 66 | |
| 67 def AddCommandLineOptions(self, parser): | |
| 68 parser.add_option( | |
| 69 '--instrumentation-level', type='choice', | |
| 70 choices=ALL_INSTRUMENTATION_LEVELS, | |
| 71 default=MINIMUM_INSTRUMENTATION_LEVEL, | |
| 72 help='How much instrumentation to enable in the measurement.') | |
| 73 | |
| 74 def CanRunForPage(self, page): | |
| 75 return hasattr(page, 'smoothness') | |
| 76 | |
| 77 def WillNavigateToPage(self, page, tab): | |
| 78 if not tab.browser.supports_tracing: | |
| 79 raise Exception('Not supported') | |
| 80 assert self.options.instrumentation_level in ALL_INSTRUMENTATION_LEVELS | |
| 81 if self.options.instrumentation_level == MINIMUM_INSTRUMENTATION_LEVEL: | |
| 82 categories = timeline_module.MINIMAL_TRACE_CATEGORIES | |
| 83 elif self.options.instrumentation_level == \ | |
| 84 FIVE_PERCENT_OVERHEAD_INSTRUMENTATION_LEVEL: | |
| 85 categories = '' | |
| 86 else: | |
| 87 categories = '*,disabled-by-default-cc.debug' | |
| 88 tab.browser.StartTracing(categories) | |
| 89 | |
| 90 def MeasurePage(self, page, tab, results): | |
| 91 """ Collect all possible metrics and added them to results. """ | |
| 92 trace_result = tab.browser.StopTracing() | |
| 93 model = trace_result.AsTimelineModel() | |
| 94 renderer_thread = model.GetRendererThreadFromTab(tab) | |
| 95 meta_metrics = _TimelineBasedMetrics(model, renderer_thread) | |
| 96 meta_metrics.AddResults(results) | |
| OLD | NEW |