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 import sys | 4 import sys |
5 | 5 |
6 from measurements import smooth_gesture_util | 6 from measurements import smooth_gesture_util |
7 from telemetry.core.platform import tracing_category_filter | 7 from telemetry.core.platform import tracing_category_filter |
8 from telemetry.core.platform import tracing_options | 8 from telemetry.core.platform import tracing_options |
9 from telemetry.timeline.model import TimelineModel | 9 from telemetry.timeline.model import TimelineModel |
10 from telemetry.page import page_test | 10 from telemetry.page import page_test |
11 from telemetry.page.actions import action_runner | 11 from telemetry.page.actions import action_runner |
12 from telemetry.value import list_of_scalar_values | 12 from telemetry.value import list_of_scalar_values |
13 from telemetry.value import scalar | 13 from telemetry.value import scalar |
14 from telemetry.value import trace | 14 from telemetry.value import trace |
15 from telemetry.web_perf import timeline_interaction_record as tir_module | 15 from telemetry.web_perf import timeline_interaction_record as tir_module |
16 from telemetry.web_perf.metrics import smoothness | 16 from telemetry.web_perf.metrics import smoothness |
17 | 17 |
18 | 18 |
19 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' | 19 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' |
20 | 20 |
21 # Descriptions for results from platform.GetRawDisplayFrameRateMeasurements(). | |
22 DESCRIPTIONS = { | |
23 'avg_surface_fps': 'Average frames per second as measured by the ' | |
24 'platform\'s SurfaceFlinger.' | |
25 } | |
26 | |
27 | |
28 class MissingDisplayFrameRateError(page_test.MeasurementFailure): | |
29 def __init__(self, name): | |
30 super(MissingDisplayFrameRateError, self).__init__( | |
31 'Missing display frame rate metrics: ' + name) | |
32 | 21 |
33 class SmoothnessController(object): | 22 class SmoothnessController(object): |
34 def __init__(self): | 23 def __init__(self): |
35 self._timeline_model = None | 24 self._timeline_model = None |
36 self._tracing_timeline_data = None | 25 self._tracing_timeline_data = None |
37 self._interaction = None | 26 self._interaction = None |
| 27 self._surface_flinger_timeline_data = None |
38 | 28 |
39 def SetUp(self, page, tab): | 29 def SetUp(self, page, tab): |
40 # FIXME: Remove webkit.console when blink.console lands in chromium and | 30 # FIXME: Remove webkit.console when blink.console lands in chromium and |
41 # the ref builds are updated. crbug.com/386847 | 31 # the ref builds are updated. crbug.com/386847 |
42 custom_categories = ['webkit.console', 'blink.console', 'benchmark'] | 32 custom_categories = ['webkit.console', 'blink.console', 'benchmark'] |
43 custom_categories += page.GetSyntheticDelayCategories() | 33 custom_categories += page.GetSyntheticDelayCategories() |
44 category_filter = tracing_category_filter.TracingCategoryFilter() | 34 category_filter = tracing_category_filter.TracingCategoryFilter() |
45 for c in custom_categories: | 35 for c in custom_categories: |
46 category_filter.AddIncludedCategory(c) | 36 category_filter.AddIncludedCategory(c) |
47 options = tracing_options.TracingOptions() | 37 options = tracing_options.TracingOptions() |
48 options.enable_chrome_trace = True | 38 options.enable_chrome_trace = True |
49 tab.browser.platform.tracing_controller.Start(options, category_filter, 60) | 39 tab.browser.platform.tracing_controller.Start(options, category_filter, 60) |
50 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 40 if tab.browser.platform.IsDisplayTracingSupported(): |
51 tab.browser.platform.StartRawDisplayFrameRateMeasurement() | 41 tab.browser.platform.StartDisplayTracing(); |
52 | 42 |
53 def Start(self, tab): | 43 def Start(self, tab): |
54 # Start the smooth marker for all smooth actions. | 44 # Start the smooth marker for all smooth actions. |
55 runner = action_runner.ActionRunner(tab) | 45 runner = action_runner.ActionRunner(tab) |
56 self._interaction = runner.BeginInteraction( | 46 self._interaction = runner.BeginInteraction( |
57 RUN_SMOOTH_ACTIONS, is_smooth=True) | 47 RUN_SMOOTH_ACTIONS, is_smooth=True) |
58 | 48 |
59 def Stop(self, tab): | 49 def Stop(self, tab): |
60 # End the smooth marker for all smooth actions. | 50 # End the smooth marker for all smooth actions. |
61 self._interaction.End() | 51 self._interaction.End() |
62 # Stop tracing for smoothness metric. | 52 # Stop tracing for smoothness metric. |
63 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 53 if tab.browser.platform.IsDisplayTracingSupported(): |
64 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 54 self._surface_flinger_timeline_data = \ |
| 55 tab.browser.platform.StopDisplayTracing() |
65 self._tracing_timeline_data = tab.browser.platform.tracing_controller.Stop() | 56 self._tracing_timeline_data = tab.browser.platform.tracing_controller.Stop() |
| 57 timeline_data = [self._tracing_timeline_data] |
| 58 if self._surface_flinger_timeline_data: |
| 59 timeline_data.append(self._surface_flinger_timeline_data) |
66 self._timeline_model = TimelineModel( | 60 self._timeline_model = TimelineModel( |
67 timeline_data=self._tracing_timeline_data) | 61 timeline_data=timeline_data) |
68 | 62 |
69 def AddResults(self, tab, results): | 63 def AddResults(self, tab, results): |
70 # Add results of smoothness metric. This computes the smoothness metric for | 64 # Add results of smoothness metric. This computes the smoothness metric for |
71 # the time ranges of gestures, if there is at least one, else the the time | 65 # the time ranges of gestures, if there is at least one, else the the time |
72 # ranges from the first action to the last action. | 66 # ranges from the first action to the last action. |
73 results.AddValue(trace.TraceValue( | 67 results.AddValue(trace.TraceValue( |
74 results.current_page, self._tracing_timeline_data)) | 68 results.current_page, self._tracing_timeline_data)) |
75 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( | 69 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( |
76 tab.id) | 70 tab.id) |
77 run_smooth_actions_record = None | 71 run_smooth_actions_record = None |
(...skipping 24 matching lines...) Expand all Loading... |
102 raise Exception('SmoothnessController failed to issue markers for the ' | 96 raise Exception('SmoothnessController failed to issue markers for the ' |
103 'whole interaction.') | 97 'whole interaction.') |
104 else: | 98 else: |
105 smooth_records = [run_smooth_actions_record] | 99 smooth_records = [run_smooth_actions_record] |
106 | 100 |
107 # Create an interaction_record for this legacy measurement. Since we don't | 101 # Create an interaction_record for this legacy measurement. Since we don't |
108 # wrap the results that are sent to smoothness metric, the label will | 102 # wrap the results that are sent to smoothness metric, the label will |
109 # not be used. | 103 # not be used. |
110 smoothness_metric = smoothness.SmoothnessMetric() | 104 smoothness_metric = smoothness.SmoothnessMetric() |
111 smoothness_metric.AddResults( | 105 smoothness_metric.AddResults( |
112 self._timeline_model, renderer_thread, smooth_records, results) | 106 self._timeline_model, renderer_thread, smooth_records, results) |
113 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | |
114 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): | |
115 if r.value is None: | |
116 raise MissingDisplayFrameRateError(r.name) | |
117 if isinstance(r.value, list): | |
118 results.AddValue(list_of_scalar_values.ListOfScalarValues( | |
119 results.current_page, r.name, r.unit, r.value, | |
120 description=DESCRIPTIONS.get(r.name))) | |
121 else: | |
122 results.AddValue(scalar.ScalarValue( | |
123 results.current_page, r.name, r.unit, r.value, | |
124 description=DESCRIPTIONS.get(r.name))) | |
125 | 107 |
126 def CleanUp(self, tab): | 108 def CleanUp(self, tab): |
127 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 109 if tab.browser.platform.IsDisplayTracingSupported(): |
128 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 110 tab.browser.platform.StopDisplayTracing() |
129 if tab.browser.platform.tracing_controller.is_tracing_running: | 111 if tab.browser.platform.tracing_controller.is_tracing_running: |
130 tab.browser.platform.tracing_controller.Stop() | 112 tab.browser.platform.tracing_controller.Stop() |
OLD | NEW |