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 metrics import timeline as timeline_module | |
6 from metrics import timeline_interaction_record as tir_module | |
7 from telemetry.page import page_measurement | |
8 from telemetry.core.timeline import model as model_module | |
9 | |
10 | |
11 | |
12 # TimelineBasedMeasurement considers all instrumentation as producing a single | |
13 # timeline. But, depending on the amount of instrumentation that is enabled, | |
14 # overhead increases. The user of the measurement must therefore chose between | |
15 # a few levels of instrumentation. | |
16 NO_OVERHEAD_LEVEL = 'no-overhead' | |
17 MINIMAL_OVERHEAD_LEVEL = 'minimal-overhead' | |
18 DEBUG_OVERHEAD_LEVEL = 'debug-overhead' | |
19 | |
20 ALL_OVERHEAD_LEVELS = [ | |
21 NO_OVERHEAD_LEVEL, | |
22 MINIMAL_OVERHEAD_LEVEL, | |
23 DEBUG_OVERHEAD_LEVEL | |
24 ] | |
25 | |
26 | |
27 class _TimelineBasedMetrics(object): | |
28 def __init__(self, model, renderer_thread): | |
29 self._model = model | |
30 self._renderer_thread = renderer_thread | |
31 | |
32 def FindTimelineInteractionRecords(self): | |
33 # TODO(nduca): Add support for page-load interaction record. | |
34 return [tir_module.TimelineInteractionRecord(event) for | |
35 event in self._renderer_thread.IterAllAsyncSlices() | |
36 if tir_module.IsTimelineInteractionRecord(event.name)] | |
37 | |
38 def CreateMetricsForTimelineInteractionRecord(self, interaction): | |
39 res = [] | |
40 if interaction.is_smooth: | |
41 pass # TODO(nduca): res.append smoothness metric instance. | |
42 return res | |
43 | |
44 def AddResults(self, results): | |
45 interactions = self.FindTimelineInteractionRecords() | |
46 if len(interactions) == 0: | |
47 raise Exception('Expected at least one Interaction on the page') | |
48 for interaction in interactions: | |
49 metrics = self.CreateMetricsForTimelineInteractionRecord(interaction) | |
50 for m in metrics: | |
51 m.AddResults(self._model, self._renderer_thread, | |
52 interaction, results) | |
53 | |
54 | |
55 class TimelineBasedMeasurement(page_measurement.PageMeasurement): | |
56 """A timeline measurement shifts the burden of what metrics to collect onto | |
57 the page under test, or the pageset running that page. Instead of the | |
58 measurement having a fixed set of values it collects about the page, the page | |
59 being tested issues a set of standard calls to the user timing API specifying | |
60 time spans of interest during which interactions are running, and for each, a | |
61 standardized set of flags describing the work being done in that time range. | |
62 This measurement object then collects a trace alongside these interaction | |
63 records, and passes the recorded timeline to different TimelineBasedMetrics | |
64 based on those flags. | |
nednguyen
2014/03/04 15:38:47
Add examples of the interaction marker that the pa
| |
65 | |
66 """ | |
67 def __init__(self): | |
68 super(TimelineBasedMeasurement, self).__init__('smoothness') | |
69 | |
70 def AddCommandLineOptions(self, parser): | |
71 parser.add_option( | |
72 '--overhead-level', type='choice', | |
73 choices=ALL_OVERHEAD_LEVELS, | |
74 default=NO_OVERHEAD_LEVEL, | |
75 help='How much overhead to incur during the measurement.') | |
76 | |
77 def CanRunForPage(self, page): | |
78 return hasattr(page, 'smoothness') | |
79 | |
80 def WillNavigateToPage(self, page, tab): | |
81 if not tab.browser.supports_tracing: | |
82 raise Exception('Not supported') | |
83 assert self.options.overhead_level in ALL_OVERHEAD_LEVELS | |
84 if self.options.overhead_level == NO_OVERHEAD_LEVEL: | |
85 categories = timeline_module.MINIMAL_TRACE_CATEGORIES | |
86 elif self.options.overhead_level == \ | |
87 MINIMAL_OVERHEAD_LEVEL: | |
88 categories = '' | |
89 else: | |
90 categories = '*,disabled-by-default-cc.debug' | |
91 tab.browser.StartTracing(categories) | |
92 | |
93 def MeasurePage(self, page, tab, results): | |
94 """ Collect all possible metrics and added them to results. """ | |
95 trace_result = tab.browser.StopTracing() | |
96 model = model_module.TimelineModel(trace_result) | |
97 renderer_thread = model.GetRendererThreadFromTab(tab) | |
98 meta_metrics = _TimelineBasedMetrics(model, renderer_thread) | |
99 meta_metrics.AddResults(results) | |
OLD | NEW |