| 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) |
| 21 | 32 |
| 22 class SmoothnessController(object): | 33 class SmoothnessController(object): |
| 23 def __init__(self): | 34 def __init__(self): |
| 24 self._timeline_model = None | 35 self._timeline_model = None |
| 25 self._tracing_timeline_data = None | 36 self._tracing_timeline_data = None |
| 26 self._interaction = None | 37 self._interaction = None |
| 27 self._surface_flinger_timeline_data = None | |
| 28 | 38 |
| 29 def SetUp(self, page, tab): | 39 def SetUp(self, page, tab): |
| 30 # FIXME: Remove webkit.console when blink.console lands in chromium and | 40 # FIXME: Remove webkit.console when blink.console lands in chromium and |
| 31 # the ref builds are updated. crbug.com/386847 | 41 # the ref builds are updated. crbug.com/386847 |
| 32 custom_categories = ['webkit.console', 'blink.console', 'benchmark'] | 42 custom_categories = ['webkit.console', 'blink.console', 'benchmark'] |
| 33 custom_categories += page.GetSyntheticDelayCategories() | 43 custom_categories += page.GetSyntheticDelayCategories() |
| 34 category_filter = tracing_category_filter.TracingCategoryFilter() | 44 category_filter = tracing_category_filter.TracingCategoryFilter() |
| 35 for c in custom_categories: | 45 for c in custom_categories: |
| 36 category_filter.AddIncludedCategory(c) | 46 category_filter.AddIncludedCategory(c) |
| 37 options = tracing_options.TracingOptions() | 47 options = tracing_options.TracingOptions() |
| 38 options.enable_chrome_trace = True | 48 options.enable_chrome_trace = True |
| 39 tab.browser.platform.tracing_controller.Start(options, category_filter, 60) | 49 tab.browser.platform.tracing_controller.Start(options, category_filter, 60) |
| 40 if tab.browser.platform.IsDisplayTracingSupported(): | 50 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 41 tab.browser.platform.StartDisplayTracing(); | 51 tab.browser.platform.StartRawDisplayFrameRateMeasurement() |
| 42 | 52 |
| 43 def Start(self, tab): | 53 def Start(self, tab): |
| 44 # Start the smooth marker for all smooth actions. | 54 # Start the smooth marker for all smooth actions. |
| 45 runner = action_runner.ActionRunner(tab) | 55 runner = action_runner.ActionRunner(tab) |
| 46 self._interaction = runner.BeginInteraction( | 56 self._interaction = runner.BeginInteraction( |
| 47 RUN_SMOOTH_ACTIONS, is_smooth=True) | 57 RUN_SMOOTH_ACTIONS, is_smooth=True) |
| 48 | 58 |
| 49 def Stop(self, tab): | 59 def Stop(self, tab): |
| 50 # End the smooth marker for all smooth actions. | 60 # End the smooth marker for all smooth actions. |
| 51 self._interaction.End() | 61 self._interaction.End() |
| 52 # Stop tracing for smoothness metric. | 62 # Stop tracing for smoothness metric. |
| 53 if tab.browser.platform.IsDisplayTracingSupported(): | 63 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 54 self._surface_flinger_timeline_data = \ | 64 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
| 55 tab.browser.platform.StopDisplayTracing() | |
| 56 self._tracing_timeline_data = tab.browser.platform.tracing_controller.Stop() | 65 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) | |
| 60 self._timeline_model = TimelineModel( | 66 self._timeline_model = TimelineModel( |
| 61 timeline_data=timeline_data) | 67 timeline_data=self._tracing_timeline_data) |
| 62 | 68 |
| 63 def AddResults(self, tab, results): | 69 def AddResults(self, tab, results): |
| 64 # Add results of smoothness metric. This computes the smoothness metric for | 70 # Add results of smoothness metric. This computes the smoothness metric for |
| 65 # the time ranges of gestures, if there is at least one, else the the time | 71 # the time ranges of gestures, if there is at least one, else the the time |
| 66 # ranges from the first action to the last action. | 72 # ranges from the first action to the last action. |
| 67 results.AddValue(trace.TraceValue( | 73 results.AddValue(trace.TraceValue( |
| 68 results.current_page, self._tracing_timeline_data)) | 74 results.current_page, self._tracing_timeline_data)) |
| 69 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( | 75 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( |
| 70 tab.id) | 76 tab.id) |
| 71 run_smooth_actions_record = None | 77 run_smooth_actions_record = None |
| (...skipping 24 matching lines...) Expand all Loading... |
| 96 raise Exception('SmoothnessController failed to issue markers for the ' | 102 raise Exception('SmoothnessController failed to issue markers for the ' |
| 97 'whole interaction.') | 103 'whole interaction.') |
| 98 else: | 104 else: |
| 99 smooth_records = [run_smooth_actions_record] | 105 smooth_records = [run_smooth_actions_record] |
| 100 | 106 |
| 101 # Create an interaction_record for this legacy measurement. Since we don't | 107 # Create an interaction_record for this legacy measurement. Since we don't |
| 102 # wrap the results that are sent to smoothness metric, the label will | 108 # wrap the results that are sent to smoothness metric, the label will |
| 103 # not be used. | 109 # not be used. |
| 104 smoothness_metric = smoothness.SmoothnessMetric() | 110 smoothness_metric = smoothness.SmoothnessMetric() |
| 105 smoothness_metric.AddResults( | 111 smoothness_metric.AddResults( |
| 106 self._timeline_model, renderer_thread, smooth_records, results) | 112 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))) |
| 107 | 125 |
| 108 def CleanUp(self, tab): | 126 def CleanUp(self, tab): |
| 109 if tab.browser.platform.IsDisplayTracingSupported(): | 127 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 110 tab.browser.platform.StopDisplayTracing() | 128 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
| 111 if tab.browser.platform.tracing_controller.is_tracing_running: | 129 if tab.browser.platform.tracing_controller.is_tracing_running: |
| 112 tab.browser.platform.tracing_controller.Stop() | 130 tab.browser.platform.tracing_controller.Stop() |
| OLD | NEW |