| 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 | 4 |
| 5 from telemetry.core.platform import tracing_category_filter | 5 from telemetry.core.platform import tracing_category_filter |
| 6 from telemetry.core.platform import tracing_options | 6 from telemetry.core.platform import tracing_options |
| 7 from telemetry.page import action_runner | 7 from telemetry.page import action_runner |
| 8 from telemetry.page import page_test | |
| 9 from telemetry.timeline.model import TimelineModel | 8 from telemetry.timeline.model import TimelineModel |
| 10 from telemetry.value import trace | 9 from telemetry.value import trace |
| 11 from telemetry.web_perf import smooth_gesture_util | 10 from telemetry.web_perf import smooth_gesture_util |
| 12 from telemetry.web_perf import timeline_interaction_record as tir_module | 11 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 13 | 12 |
| 14 | 13 |
| 15 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' | 14 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' |
| 16 | 15 |
| 17 | 16 |
| 18 class TimelineController(object): | 17 class TimelineController(object): |
| 19 def __init__(self, enable_auto_issuing_record=True): | 18 def __init__(self): |
| 20 super(TimelineController, self).__init__() | 19 super(TimelineController, self).__init__() |
| 21 self.trace_categories = None | 20 self.trace_categories = None |
| 22 self._model = None | 21 self._model = None |
| 23 self._renderer_process = None | 22 self._renderer_process = None |
| 24 self._smooth_records = [] | 23 self._smooth_records = [] |
| 25 self._interaction = None | 24 self._interaction = None |
| 26 self._enable_auto_issuing_record = enable_auto_issuing_record | |
| 27 | 25 |
| 28 def SetUp(self, page, tab): | 26 def SetUp(self, page, tab): |
| 29 """Starts gathering timeline data. | 27 """Starts gathering timeline data. |
| 30 | 28 |
| 31 """ | 29 """ |
| 32 # Resets these member variables incase this object is reused. | 30 # Resets these member variables incase this object is reused. |
| 33 self._model = None | 31 self._model = None |
| 34 self._renderer_process = None | 32 self._renderer_process = None |
| 35 if not tab.browser.platform.tracing_controller.IsChromeTracingSupported(): | 33 if not tab.browser.platform.tracing_controller.IsChromeTracingSupported(): |
| 36 raise Exception('Not supported') | 34 raise Exception('Not supported') |
| 37 category_filter = tracing_category_filter.TracingCategoryFilter( | 35 category_filter = tracing_category_filter.TracingCategoryFilter( |
| 38 filter_string=self.trace_categories) | 36 filter_string=self.trace_categories) |
| 39 for delay in page.GetSyntheticDelayCategories(): | 37 for delay in page.GetSyntheticDelayCategories(): |
| 40 category_filter.AddSyntheticDelay(delay) | 38 category_filter.AddSyntheticDelay(delay) |
| 41 options = tracing_options.TracingOptions() | 39 options = tracing_options.TracingOptions() |
| 42 options.enable_chrome_trace = True | 40 options.enable_chrome_trace = True |
| 43 tab.browser.platform.tracing_controller.Start(options, category_filter) | 41 tab.browser.platform.tracing_controller.Start(options, category_filter) |
| 44 | 42 |
| 45 def Start(self, tab): | 43 def Start(self, tab): |
| 46 # Start the smooth marker for all actions. | 44 # Start the smooth marker for all actions. |
| 47 runner = action_runner.ActionRunner(tab) | 45 runner = action_runner.ActionRunner(tab) |
| 48 if self._enable_auto_issuing_record: | 46 self._interaction = runner.CreateInteraction( |
| 49 self._interaction = runner.CreateInteraction( | 47 RUN_SMOOTH_ACTIONS) |
| 50 RUN_SMOOTH_ACTIONS) | 48 self._interaction.Begin() |
| 51 self._interaction.Begin() | |
| 52 | 49 |
| 53 def Stop(self, tab, results): | 50 def Stop(self, tab, results): |
| 54 # End the smooth marker for all actions. | 51 # End the smooth marker for all actions. |
| 55 if self._enable_auto_issuing_record: | 52 self._interaction.End() |
| 56 self._interaction.End() | |
| 57 # Stop tracing. | 53 # Stop tracing. |
| 58 timeline_data = tab.browser.platform.tracing_controller.Stop() | 54 timeline_data = tab.browser.platform.tracing_controller.Stop() |
| 59 results.AddValue(trace.TraceValue( | 55 results.AddValue(trace.TraceValue( |
| 60 results.current_page, timeline_data)) | 56 results.current_page, timeline_data)) |
| 61 self._model = TimelineModel(timeline_data) | 57 self._model = TimelineModel(timeline_data) |
| 62 self._renderer_process = self._model.GetRendererProcessFromTabId(tab.id) | 58 self._renderer_process = self._model.GetRendererProcessFromTabId(tab.id) |
| 63 renderer_thread = self.model.GetRendererThreadFromTabId(tab.id) | 59 renderer_thread = self.model.GetRendererThreadFromTabId(tab.id) |
| 64 | 60 |
| 65 run_smooth_actions_record = None | 61 run_smooth_actions_record = None |
| 66 self._smooth_records = [] | 62 self._smooth_records = [] |
| (...skipping 11 matching lines...) Expand all Loading... |
| 78 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( | 74 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( |
| 79 self.model, r)) | 75 self.model, r)) |
| 80 | 76 |
| 81 # If there is no other smooth records, we make measurements on time range | 77 # If there is no other smooth records, we make measurements on time range |
| 82 # marked by timeline_controller itself. | 78 # marked by timeline_controller itself. |
| 83 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that | 79 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that |
| 84 # page sets are responsible for issueing the markers themselves. | 80 # page sets are responsible for issueing the markers themselves. |
| 85 if len(self._smooth_records) == 0 and run_smooth_actions_record: | 81 if len(self._smooth_records) == 0 and run_smooth_actions_record: |
| 86 self._smooth_records = [run_smooth_actions_record] | 82 self._smooth_records = [run_smooth_actions_record] |
| 87 | 83 |
| 88 if len(self._smooth_records) == 0: | |
| 89 raise page_test.Failure('No interaction record was created.') | |
| 90 | |
| 91 | 84 |
| 92 def CleanUp(self, tab): | 85 def CleanUp(self, tab): |
| 93 if tab.browser.platform.tracing_controller.is_tracing_running: | 86 if tab.browser.platform.tracing_controller.is_tracing_running: |
| 94 tab.browser.platform.tracing_controller.Stop() | 87 tab.browser.platform.tracing_controller.Stop() |
| 95 | 88 |
| 96 @property | 89 @property |
| 97 def model(self): | 90 def model(self): |
| 98 return self._model | 91 return self._model |
| 99 | 92 |
| 100 @property | 93 @property |
| 101 def renderer_process(self): | 94 def renderer_process(self): |
| 102 return self._renderer_process | 95 return self._renderer_process |
| 103 | 96 |
| 104 @property | 97 @property |
| 105 def smooth_records(self): | 98 def smooth_records(self): |
| 106 return self._smooth_records | 99 return self._smooth_records |
| OLD | NEW |