| 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 telemetry.core.platform import tracing_category_filter | 6 from telemetry.core.platform import tracing_category_filter |
| 7 from telemetry.core.platform import tracing_options | 7 from telemetry.core.platform import tracing_options |
| 8 from telemetry.page import action_runner | 8 from telemetry.page import action_runner |
| 9 from telemetry.page import page_test | 9 from telemetry.page import page_test |
| 10 from telemetry.timeline.model import TimelineModel | 10 from telemetry.timeline.model import TimelineModel |
| 11 from telemetry.timeline import trace_data as trace_data_module | 11 from telemetry.timeline import trace_data as trace_data_module |
| 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.metrics import smoothness | 15 from telemetry.web_perf.metrics import smoothness |
| 16 from telemetry.web_perf import smooth_gesture_util | 16 from telemetry.web_perf import smooth_gesture_util |
| 17 from telemetry.web_perf import timeline_interaction_record as tir_module | 17 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 18 | 18 |
| 19 | 19 |
| 20 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' | 20 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' |
| 21 | 21 |
| 22 | 22 |
| 23 class SmoothnessController(object): | 23 class SmoothnessController(object): |
| 24 def __init__(self): | 24 def __init__(self, auto_issuing_marker=True): |
| 25 self._timeline_model = None | 25 self._timeline_model = None |
| 26 self._trace_data = None | 26 self._trace_data = None |
| 27 self._interaction = None | 27 self._interaction = None |
| 28 self._surface_flinger_trace_data = None | 28 self._surface_flinger_trace_data = None |
| 29 self._auto_issuing_marker = auto_issuing_marker |
| 29 | 30 |
| 30 def SetUp(self, page, tab): | 31 def SetUp(self, page, tab): |
| 31 # FIXME: Remove webkit.console when blink.console lands in chromium and | 32 # FIXME: Remove webkit.console when blink.console lands in chromium and |
| 32 # the ref builds are updated. crbug.com/386847 | 33 # the ref builds are updated. crbug.com/386847 |
| 33 custom_categories = ['webkit.console', 'blink.console', 'benchmark'] | 34 custom_categories = ['webkit.console', 'blink.console', 'benchmark'] |
| 34 custom_categories += page.GetSyntheticDelayCategories() | 35 custom_categories += page.GetSyntheticDelayCategories() |
| 35 category_filter = tracing_category_filter.TracingCategoryFilter() | 36 category_filter = tracing_category_filter.TracingCategoryFilter() |
| 36 for c in custom_categories: | 37 for c in custom_categories: |
| 37 category_filter.AddIncludedCategory(c) | 38 category_filter.AddIncludedCategory(c) |
| 38 options = tracing_options.TracingOptions() | 39 options = tracing_options.TracingOptions() |
| 39 options.enable_chrome_trace = True | 40 options.enable_chrome_trace = True |
| 40 options.enable_platform_display_trace = True | 41 options.enable_platform_display_trace = True |
| 41 tab.browser.platform.tracing_controller.Start(options, category_filter, 60) | 42 tab.browser.platform.tracing_controller.Start(options, category_filter, 60) |
| 42 | 43 |
| 43 def Start(self, tab): | 44 def Start(self, tab): |
| 44 # Start the smooth marker for all smooth actions. | 45 # Start the smooth marker for all smooth actions. |
| 45 runner = action_runner.ActionRunner(tab) | 46 runner = action_runner.ActionRunner(tab) |
| 46 self._interaction = runner.CreateInteraction( | 47 if self._auto_issuing_marker: |
| 47 RUN_SMOOTH_ACTIONS) | 48 self._interaction = runner.CreateInteraction( |
| 48 self._interaction.Begin() | 49 RUN_SMOOTH_ACTIONS) |
| 50 self._interaction.Begin() |
| 49 | 51 |
| 50 def Stop(self, tab): | 52 def Stop(self, tab): |
| 51 # End the smooth marker for all smooth actions. | 53 # End the smooth marker for all smooth actions. |
| 52 self._interaction.End() | 54 if self._auto_issuing_marker: |
| 55 self._interaction.End() |
| 53 self._trace_data = tab.browser.platform.tracing_controller.Stop() | 56 self._trace_data = tab.browser.platform.tracing_controller.Stop() |
| 54 self._timeline_model = TimelineModel(self._trace_data) | 57 self._timeline_model = TimelineModel(self._trace_data) |
| 55 | 58 |
| 56 def AddResults(self, tab, results): | 59 def AddResults(self, tab, results): |
| 57 # Add results of smoothness metric. This computes the smoothness metric for | 60 # Add results of smoothness metric. This computes the smoothness metric for |
| 58 # the time ranges of gestures, if there is at least one, else the the time | 61 # the time ranges of gestures, if there is at least one, else the the time |
| 59 # ranges from the first action to the last action. | 62 # ranges from the first action to the last action. |
| 60 results.AddValue(trace.TraceValue( | 63 results.AddValue(trace.TraceValue( |
| 61 results.current_page, self._trace_data)) | 64 results.current_page, self._trace_data)) |
| 62 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( | 65 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 # 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 |
| 95 # 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 |
| 96 # not be used. | 99 # not be used. |
| 97 smoothness_metric = smoothness.SmoothnessMetric() | 100 smoothness_metric = smoothness.SmoothnessMetric() |
| 98 smoothness_metric.AddResults( | 101 smoothness_metric.AddResults( |
| 99 self._timeline_model, renderer_thread, smooth_records, results) | 102 self._timeline_model, renderer_thread, smooth_records, results) |
| 100 | 103 |
| 101 def CleanUp(self, tab): | 104 def CleanUp(self, tab): |
| 102 if tab.browser.platform.tracing_controller.is_tracing_running: | 105 if tab.browser.platform.tracing_controller.is_tracing_running: |
| 103 tab.browser.platform.tracing_controller.Stop() | 106 tab.browser.platform.tracing_controller.Stop() |
| OLD | NEW |