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.timeline.model import TimelineModel | 7 from telemetry.timeline import model |
8 from telemetry.page import page_measurement | 8 from telemetry.page import page_measurement |
9 from telemetry.page.actions import action_runner | 9 from telemetry.page.actions import action_runner |
10 from telemetry.value import list_of_scalar_values | 10 from telemetry.value import list_of_scalar_values |
11 from telemetry.value import scalar | 11 from telemetry.value import scalar |
12 from telemetry.web_perf import timeline_interaction_record as tir_module | 12 from telemetry.web_perf import timeline_interaction_record as tir_module |
13 from telemetry.web_perf.metrics import smoothness | 13 from telemetry.web_perf.metrics import smoothness |
14 | 14 |
15 | 15 |
16 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' | 16 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' |
17 | 17 |
(...skipping 30 matching lines...) Expand all Loading... |
48 self._interaction = runner.BeginInteraction( | 48 self._interaction = runner.BeginInteraction( |
49 RUN_SMOOTH_ACTIONS, is_smooth=True) | 49 RUN_SMOOTH_ACTIONS, is_smooth=True) |
50 | 50 |
51 def Stop(self, tab): | 51 def Stop(self, tab): |
52 # End the smooth marker for all smooth actions. | 52 # End the smooth marker for all smooth actions. |
53 self._interaction.End() | 53 self._interaction.End() |
54 # Stop tracing for smoothness metric. | 54 # Stop tracing for smoothness metric. |
55 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 55 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
56 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 56 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
57 self._tracing_timeline_data = tab.browser.StopTracing() | 57 self._tracing_timeline_data = tab.browser.StopTracing() |
58 self._timeline_model = TimelineModel( | 58 self._timeline_model = model.TimelineModel( |
59 timeline_data=self._tracing_timeline_data) | 59 timeline_data=self._tracing_timeline_data) |
60 | 60 |
61 def AddResults(self, tab, results): | 61 def AddResults(self, tab, results): |
62 # Add results of smoothness metric. This computes the smoothness metric for | 62 # Add results of smoothness metric. This computes the smoothness metric for |
63 # the time ranges of gestures, if there is at least one, else the the time | 63 # the time ranges of gestures, if there is at least one, else the the time |
64 # ranges from the first action to the last action. | 64 # ranges from the first action to the last action. |
65 | 65 |
66 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( | 66 threads_to_records_map = ( |
67 tab.id) | 67 tir_module.GetThreadToInteractionRecordsMapsFromModel( |
| 68 self._timeline_model)) |
| 69 assert len(threads_to_records_map) == 1, ( |
| 70 'Smoothness test only support records issued from single thread') |
| 71 interaction_records = threads_to_records_map.values()[0] |
68 run_smooth_actions_record = None | 72 run_smooth_actions_record = None |
69 smooth_records = [] | 73 smooth_records = [] |
70 for event in renderer_thread.async_slices: | 74 for r in interaction_records: |
71 if not tir_module.IsTimelineInteractionRecord(event.name): | |
72 continue | |
73 r = tir_module.TimelineInteractionRecord.FromAsyncEvent(event) | |
74 if r.label == RUN_SMOOTH_ACTIONS: | 75 if r.label == RUN_SMOOTH_ACTIONS: |
75 assert run_smooth_actions_record is None, ( | 76 assert run_smooth_actions_record is None, ( |
76 'SmoothnessController cannot issue more than 1 %s record' % | 77 'SmoothnessController cannot issue more than 1 %s record' % |
77 RUN_SMOOTH_ACTIONS) | 78 RUN_SMOOTH_ACTIONS) |
78 run_smooth_actions_record = r | 79 run_smooth_actions_record = r |
79 elif r.is_smooth: | 80 elif r.is_smooth: |
80 smooth_records.append( | 81 smooth_records.append( |
81 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( | 82 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( |
82 self._timeline_model, r)) | 83 self._timeline_model, r)) |
83 | 84 |
84 # If there is no other smooth records, we make measurements on time range | 85 # If there is no other smooth records, we make measurements on time range |
85 # marked smoothness_controller itself. | 86 # marked smoothness_controller itself. |
86 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that | 87 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that |
87 # page sets are responsible for issueing the markers themselves. | 88 # page sets are responsible for issueing the markers themselves. |
88 if len(smooth_records) == 0: | 89 if len(smooth_records) == 0: |
89 if run_smooth_actions_record is None: | 90 if run_smooth_actions_record is None: |
90 sys.stderr.write('Raw tracing data:\n') | 91 sys.stderr.write('Raw tracing data:\n') |
91 sys.stderr.write(repr(self._tracing_timeline_data.EventData())) | 92 sys.stderr.write(repr(self._tracing_timeline_data.EventData())) |
92 sys.stderr.write('\n') | 93 sys.stderr.write('\n') |
93 raise Exception('SmoothnessController failed to issue markers for the ' | 94 raise Exception('SmoothnessController failed to issue markers for the ' |
94 'whole interaction.') | 95 'whole interaction.') |
95 else: | 96 else: |
96 smooth_records = [run_smooth_actions_record] | 97 smooth_records = [run_smooth_actions_record] |
97 | 98 |
98 # Create an interaction_record for this legacy measurement. Since we don't | 99 # Create an interaction_record for this legacy measurement. Since we don't |
99 # wrap the results that are sent to smoothness metric, the label will | 100 # wrap the results that are sent to smoothness metric, the label will |
100 # not be used. | 101 # not be used. |
101 smoothness_metric = smoothness.SmoothnessMetric() | 102 smoothness_metric = smoothness.SmoothnessMetric() |
102 smoothness_metric.AddResults( | 103 smoothness_metric.AddResults( |
103 self._timeline_model, renderer_thread, smooth_records, results) | 104 self._timeline_model, smooth_records, results) |
104 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 105 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
105 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): | 106 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): |
106 if r.value is None: | 107 if r.value is None: |
107 raise MissingDisplayFrameRateError(r.name) | 108 raise MissingDisplayFrameRateError(r.name) |
108 if isinstance(r.value, list): | 109 if isinstance(r.value, list): |
109 results.AddValue(list_of_scalar_values.ListOfScalarValues( | 110 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
110 results.current_page, r.name, r.unit, r.value, | 111 results.current_page, r.name, r.unit, r.value, |
111 description=DESCRIPTIONS.get(r.name))) | 112 description=DESCRIPTIONS.get(r.name))) |
112 else: | 113 else: |
113 results.AddValue(scalar.ScalarValue( | 114 results.AddValue(scalar.ScalarValue( |
114 results.current_page, r.name, r.unit, r.value, | 115 results.current_page, r.name, r.unit, r.value, |
115 description=DESCRIPTIONS.get(r.name))) | 116 description=DESCRIPTIONS.get(r.name))) |
116 | 117 |
117 def CleanUp(self, tab): | 118 def CleanUp(self, tab): |
118 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 119 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
119 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 120 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
120 if tab.browser.is_tracing_running: | 121 if tab.browser.is_tracing_running: |
121 tab.browser.StopTracing() | 122 tab.browser.StopTracing() |
OLD | NEW |