| 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.model import TimelineModel |
| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 | 24 |
| 25 class MissingDisplayFrameRateError(page_measurement.MeasurementFailure): | 25 class MissingDisplayFrameRateError(page_measurement.MeasurementFailure): |
| 26 def __init__(self, name): | 26 def __init__(self, name): |
| 27 super(MissingDisplayFrameRateError, self).__init__( | 27 super(MissingDisplayFrameRateError, self).__init__( |
| 28 'Missing display frame rate metrics: ' + name) | 28 'Missing display frame rate metrics: ' + name) |
| 29 | 29 |
| 30 class SmoothnessController(object): | 30 class SmoothnessController(object): |
| 31 def __init__(self): | 31 def __init__(self): |
| 32 self._timeline_model = None | 32 self._timeline_model = None |
| 33 self._tracing_timeline_data = None | 33 self._trace_value = None |
| 34 self._interaction = None | 34 self._interaction = None |
| 35 | 35 |
| 36 def SetUp(self, page, tab): | 36 def SetUp(self, page, tab): |
| 37 # FIXME: Remove webkit.console when blink.console lands in chromium and | 37 # FIXME: Remove webkit.console when blink.console lands in chromium and |
| 38 # the ref builds are updated. crbug.com/386847 | 38 # the ref builds are updated. crbug.com/386847 |
| 39 custom_categories = ['webkit.console', 'blink.console', 'benchmark'] | 39 custom_categories = ['webkit.console', 'blink.console', 'benchmark'] |
| 40 custom_categories += page.GetSyntheticDelayCategories() | 40 custom_categories += page.GetSyntheticDelayCategories() |
| 41 tab.browser.StartTracing(','.join(custom_categories), 60) | 41 tab.browser.StartTracing(','.join(custom_categories), 60) |
| 42 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 42 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 43 tab.browser.platform.StartRawDisplayFrameRateMeasurement() | 43 tab.browser.platform.StartRawDisplayFrameRateMeasurement() |
| 44 | 44 |
| 45 def Start(self, tab): | 45 def Start(self, tab): |
| 46 # Start the smooth marker for all smooth actions. | 46 # Start the smooth marker for all smooth actions. |
| 47 runner = action_runner.ActionRunner(tab) | 47 runner = action_runner.ActionRunner(tab) |
| 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._trace_value = tab.browser.StopTracing() |
| 58 self._timeline_model = TimelineModel( | 58 self._timeline_model = TimelineModel(self._trace_value) |
| 59 timeline_data=self._tracing_timeline_data) | |
| 60 | 59 |
| 61 def AddResults(self, tab, results): | 60 def AddResults(self, tab, results): |
| 62 # Add results of smoothness metric. This computes the smoothness metric for | 61 # 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 | 62 # 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. | 63 # ranges from the first action to the last action. |
| 65 | 64 |
| 66 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( | 65 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( |
| 67 tab.id) | 66 tab.id) |
| 68 run_smooth_actions_record = None | 67 run_smooth_actions_record = None |
| 69 smooth_records = [] | 68 smooth_records = [] |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( | 80 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( |
| 82 self._timeline_model, r)) | 81 self._timeline_model, r)) |
| 83 | 82 |
| 84 # If there is no other smooth records, we make measurements on time range | 83 # If there is no other smooth records, we make measurements on time range |
| 85 # marked smoothness_controller itself. | 84 # marked smoothness_controller itself. |
| 86 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that | 85 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that |
| 87 # page sets are responsible for issueing the markers themselves. | 86 # page sets are responsible for issueing the markers themselves. |
| 88 if len(smooth_records) == 0: | 87 if len(smooth_records) == 0: |
| 89 if run_smooth_actions_record is None: | 88 if run_smooth_actions_record is None: |
| 90 sys.stderr.write('Raw tracing data:\n') | 89 sys.stderr.write('Raw tracing data:\n') |
| 91 sys.stderr.write(repr(self._tracing_timeline_data.EventData())) | 90 self._trace_value.Serialize(sys.stderr) |
| 92 sys.stderr.write('\n') | 91 sys.stderr.write('\n') |
| 93 raise Exception('SmoothnessController failed to issue markers for the ' | 92 raise Exception('SmoothnessController failed to issue markers for the ' |
| 94 'whole interaction.') | 93 'whole interaction.') |
| 95 else: | 94 else: |
| 96 smooth_records = [run_smooth_actions_record] | 95 smooth_records = [run_smooth_actions_record] |
| 97 | 96 |
| 98 # Create an interaction_record for this legacy measurement. Since we don't | 97 # 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 | 98 # wrap the results that are sent to smoothness metric, the label will |
| 100 # not be used. | 99 # not be used. |
| 101 smoothness_metric = smoothness.SmoothnessMetric() | 100 smoothness_metric = smoothness.SmoothnessMetric() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 112 else: | 111 else: |
| 113 results.AddValue(scalar.ScalarValue( | 112 results.AddValue(scalar.ScalarValue( |
| 114 results.current_page, r.name, r.unit, r.value, | 113 results.current_page, r.name, r.unit, r.value, |
| 115 description=DESCRIPTIONS.get(r.name))) | 114 description=DESCRIPTIONS.get(r.name))) |
| 116 | 115 |
| 117 def CleanUp(self, tab): | 116 def CleanUp(self, tab): |
| 118 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 117 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 119 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 118 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
| 120 if tab.browser.is_tracing_running: | 119 if tab.browser.is_tracing_running: |
| 121 tab.browser.StopTracing() | 120 tab.browser.StopTracing() |
| OLD | NEW |