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 | 5 |
5 from measurements import smooth_gesture_util | 6 from measurements import smooth_gesture_util |
6 from metrics import smoothness | 7 from metrics import smoothness |
7 from telemetry.core.timeline.model import TimelineModel | 8 from telemetry.core.timeline.model import TimelineModel |
8 from telemetry.page import page_measurement | 9 from telemetry.page import page_measurement |
9 from telemetry.page.actions import action_runner | 10 from telemetry.page.actions import action_runner |
10 from telemetry.web_perf import timeline_interaction_record as tir_module | 11 from telemetry.web_perf import timeline_interaction_record as tir_module |
11 | 12 |
12 | 13 |
13 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' | 14 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' |
14 | 15 |
15 | 16 |
16 class MissingDisplayFrameRateError(page_measurement.MeasurementFailure): | 17 class MissingDisplayFrameRateError(page_measurement.MeasurementFailure): |
17 def __init__(self, name): | 18 def __init__(self, name): |
18 super(MissingDisplayFrameRateError, self).__init__( | 19 super(MissingDisplayFrameRateError, self).__init__( |
19 'Missing display frame rate metrics: ' + name) | 20 'Missing display frame rate metrics: ' + name) |
20 | 21 |
21 class SmoothnessController(object): | 22 class SmoothnessController(object): |
22 def __init__(self): | 23 def __init__(self): |
23 self._timeline_model = None | 24 self._timeline_model = None |
| 25 self._tracing_timeline_data = None |
24 | 26 |
25 def Start(self, page, tab): | 27 def Start(self, page, tab): |
26 custom_categories = ['webkit.console', 'benchmark'] | 28 custom_categories = ['webkit.console', 'benchmark'] |
27 custom_categories += page.GetSyntheticDelayCategories() | 29 custom_categories += page.GetSyntheticDelayCategories() |
28 tab.browser.StartTracing(','.join(custom_categories), 60) | 30 tab.browser.StartTracing(','.join(custom_categories), 60) |
29 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 31 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
30 tab.browser.platform.StartRawDisplayFrameRateMeasurement() | 32 tab.browser.platform.StartRawDisplayFrameRateMeasurement() |
31 # Start the smooth marker for all smooth actions. | 33 # Start the smooth marker for all smooth actions. |
32 runner = action_runner.ActionRunner(None, tab) | 34 runner = action_runner.ActionRunner(None, tab) |
33 runner.BeginInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH]) | 35 runner.BeginInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH]) |
34 | 36 |
35 def Stop(self, tab): | 37 def Stop(self, tab): |
36 # End the smooth marker for all smooth actions. | 38 # End the smooth marker for all smooth actions. |
37 runner = action_runner.ActionRunner(None, tab) | 39 runner = action_runner.ActionRunner(None, tab) |
38 runner.EndInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH]) | 40 runner.EndInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH]) |
39 # Stop tracing for smoothness metric. | 41 # Stop tracing for smoothness metric. |
40 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 42 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
41 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 43 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
42 tracing_timeline_data = tab.browser.StopTracing() | 44 self._tracing_timeline_data = tab.browser.StopTracing() |
43 self._timeline_model = TimelineModel(timeline_data=tracing_timeline_data) | 45 self._timeline_model = TimelineModel( |
| 46 timeline_data=self._tracing_timeline_data) |
44 | 47 |
45 def AddResults(self, tab, results): | 48 def AddResults(self, tab, results): |
46 # Add results of smoothness metric. This computes the smoothness metric for | 49 # Add results of smoothness metric. This computes the smoothness metric for |
47 # the time ranges of gestures, if there is at least one, else the the time | 50 # the time ranges of gestures, if there is at least one, else the the time |
48 # ranges from the first action to the last action. | 51 # ranges from the first action to the last action. |
49 | 52 |
50 renderer_thread = self._timeline_model.GetRendererThreadFromTab(tab) | 53 renderer_thread = self._timeline_model.GetRendererThreadFromTab(tab) |
51 run_smooth_actions_record = None | 54 run_smooth_actions_record = None |
52 smooth_records = [] | 55 smooth_records = [] |
53 for event in renderer_thread.async_slices: | 56 for event in renderer_thread.async_slices: |
54 if not tir_module.IsTimelineInteractionRecord(event.name): | 57 if not tir_module.IsTimelineInteractionRecord(event.name): |
55 continue | 58 continue |
56 r = tir_module.TimelineInteractionRecord.FromEvent(event) | 59 r = tir_module.TimelineInteractionRecord.FromEvent(event) |
57 if r.logical_name == RUN_SMOOTH_ACTIONS: | 60 if r.logical_name == RUN_SMOOTH_ACTIONS: |
58 assert run_smooth_actions_record is None, ( | 61 assert run_smooth_actions_record is None, ( |
59 'SmoothnessController cannot issue more than 1 %s record' % | 62 'SmoothnessController cannot issue more than 1 %s record' % |
60 RUN_SMOOTH_ACTIONS) | 63 RUN_SMOOTH_ACTIONS) |
61 run_smooth_actions_record = r | 64 run_smooth_actions_record = r |
62 elif r.is_smooth: | 65 elif r.is_smooth: |
63 smooth_records.append( | 66 smooth_records.append( |
64 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( | 67 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( |
65 self._timeline_model, r)) | 68 self._timeline_model, r)) |
66 | 69 |
67 # If there is no other smooth records, we make measurements on time range | 70 # If there is no other smooth records, we make measurements on time range |
68 # marked smoothness_controller itself. | 71 # marked smoothness_controller itself. |
69 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that | 72 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that |
70 # page sets are responsible for issueing the markers themselves. | 73 # page sets are responsible for issueing the markers themselves. |
71 if len(smooth_records) == 0: | 74 if len(smooth_records) == 0: |
72 assert run_smooth_actions_record, ( | 75 if run_smooth_actions_record is None: |
73 'SmoothnessController fails to issue markers for the whole ' | 76 sys.stderr.write('Raw tracing data:\n') |
74 'interaction.') | 77 sys.stderr.write(repr(self._tracing_timeline_data.EventData())) |
75 smooth_records = [run_smooth_actions_record] | 78 sys.stderr.write('\n') |
| 79 raise Exception('SmoothnessController failed to issue markers for the ' |
| 80 'whole interaction.') |
| 81 else: |
| 82 smooth_records = [run_smooth_actions_record] |
76 | 83 |
77 # Create an interaction_record for this legacy measurement. Since we don't | 84 # Create an interaction_record for this legacy measurement. Since we don't |
78 # wrap the results that is sent to smoothnes metric, the logical_name will | 85 # wrap the results that is sent to smoothnes metric, the logical_name will |
79 # not be used. | 86 # not be used. |
80 smoothness_metric = smoothness.SmoothnessMetric() | 87 smoothness_metric = smoothness.SmoothnessMetric() |
81 smoothness_metric.AddResults( | 88 smoothness_metric.AddResults( |
82 self._timeline_model, renderer_thread, smooth_records, results) | 89 self._timeline_model, renderer_thread, smooth_records, results) |
83 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 90 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
84 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): | 91 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): |
85 if r.value is None: | 92 if r.value is None: |
86 raise MissingDisplayFrameRateError(r.name) | 93 raise MissingDisplayFrameRateError(r.name) |
87 results.Add(r.name, r.unit, r.value) | 94 results.Add(r.name, r.unit, r.value) |
88 | 95 |
89 def CleanUp(self, tab): | 96 def CleanUp(self, tab): |
90 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 97 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
91 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 98 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
92 if tab.browser.is_tracing_running: | 99 if tab.browser.is_tracing_running: |
93 tab.browser.StopTracing() | 100 tab.browser.StopTracing() |
OLD | NEW |