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 from measurements import smooth_gesture_util | 4 from measurements import smooth_gesture_util |
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.timeline.model import TimelineModel | 8 from telemetry.timeline.model import TimelineModel |
8 from telemetry.page.actions import action_runner | 9 from telemetry.page.actions import action_runner |
9 from telemetry.web_perf import timeline_interaction_record as tir_module | 10 from telemetry.web_perf import timeline_interaction_record as tir_module |
10 | 11 |
11 | 12 |
12 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' | 13 RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions' |
13 | 14 |
14 | 15 |
15 class TimelineController(object): | 16 class TimelineController(object): |
16 def __init__(self): | 17 def __init__(self): |
17 super(TimelineController, self).__init__() | 18 super(TimelineController, self).__init__() |
18 self.trace_categories = None | 19 self.trace_categories = None |
19 self._model = None | 20 self._model = None |
20 self._renderer_process = None | 21 self._renderer_process = None |
21 self._smooth_records = [] | 22 self._smooth_records = [] |
22 self._interaction = None | 23 self._interaction = None |
23 | 24 |
24 def SetUp(self, page, tab): | 25 def SetUp(self, page, tab): |
25 """Starts gathering timeline data. | 26 """Starts gathering timeline data. |
26 | 27 |
27 """ | 28 """ |
28 # Resets these member variables incase this object is reused. | 29 # Resets these member variables incase this object is reused. |
29 self._model = None | 30 self._model = None |
30 self._renderer_process = None | 31 self._renderer_process = None |
31 if not tab.browser.supports_tracing: | 32 if not tab.browser.platform.tracing_controller.IsChromeTracingSupported( |
| 33 tab.browser): |
32 raise Exception('Not supported') | 34 raise Exception('Not supported') |
33 category_filter = tracing_category_filter.TracingCategoryFilter( | 35 category_filter = tracing_category_filter.TracingCategoryFilter( |
34 filter_string=self.trace_categories) | 36 filter_string=self.trace_categories) |
35 for delay in page.GetSyntheticDelayCategories(): | 37 for delay in page.GetSyntheticDelayCategories(): |
36 category_filter.AddSyntheticDelay(delay) | 38 category_filter.AddSyntheticDelay(delay) |
37 tab.browser.StartTracing(category_filter) | 39 options = tracing_options.TracingOptions() |
| 40 options.enable_chrome_trace = True |
| 41 tab.browser.platform.tracing_controller.Start(options, category_filter) |
38 | 42 |
39 def Start(self, tab): | 43 def Start(self, tab): |
40 # Start the smooth marker for all actions. | 44 # Start the smooth marker for all actions. |
41 runner = action_runner.ActionRunner(tab) | 45 runner = action_runner.ActionRunner(tab) |
42 self._interaction = runner.BeginInteraction( | 46 self._interaction = runner.BeginInteraction( |
43 RUN_SMOOTH_ACTIONS, is_smooth=True) | 47 RUN_SMOOTH_ACTIONS, is_smooth=True) |
44 | 48 |
45 def Stop(self, tab): | 49 def Stop(self, tab): |
46 # End the smooth marker for all actions. | 50 # End the smooth marker for all actions. |
47 self._interaction.End() | 51 self._interaction.End() |
48 # Stop tracing. | 52 # Stop tracing. |
49 timeline_data = tab.browser.StopTracing() | 53 timeline_data = tab.browser.platform.tracing_controller.Stop() |
50 self._model = TimelineModel(timeline_data) | 54 self._model = TimelineModel(timeline_data) |
51 self._renderer_process = self._model.GetRendererProcessFromTabId(tab.id) | 55 self._renderer_process = self._model.GetRendererProcessFromTabId(tab.id) |
52 renderer_thread = self.model.GetRendererThreadFromTabId(tab.id) | 56 renderer_thread = self.model.GetRendererThreadFromTabId(tab.id) |
53 | 57 |
54 run_smooth_actions_record = None | 58 run_smooth_actions_record = None |
55 self._smooth_records = [] | 59 self._smooth_records = [] |
56 for event in renderer_thread.async_slices: | 60 for event in renderer_thread.async_slices: |
57 if not tir_module.IsTimelineInteractionRecord(event.name): | 61 if not tir_module.IsTimelineInteractionRecord(event.name): |
58 continue | 62 continue |
59 r = tir_module.TimelineInteractionRecord.FromAsyncEvent(event) | 63 r = tir_module.TimelineInteractionRecord.FromAsyncEvent(event) |
60 if r.label == RUN_SMOOTH_ACTIONS: | 64 if r.label == RUN_SMOOTH_ACTIONS: |
61 assert run_smooth_actions_record is None, ( | 65 assert run_smooth_actions_record is None, ( |
62 'TimelineController cannot issue more than 1 %s record' % | 66 'TimelineController cannot issue more than 1 %s record' % |
63 RUN_SMOOTH_ACTIONS) | 67 RUN_SMOOTH_ACTIONS) |
64 run_smooth_actions_record = r | 68 run_smooth_actions_record = r |
65 elif r.is_smooth: | 69 elif r.is_smooth: |
66 self._smooth_records.append( | 70 self._smooth_records.append( |
67 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( | 71 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( |
68 self.model, r)) | 72 self.model, r)) |
69 | 73 |
70 # If there is no other smooth records, we make measurements on time range | 74 # If there is no other smooth records, we make measurements on time range |
71 # marked by timeline_controller itself. | 75 # marked by timeline_controller itself. |
72 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that | 76 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that |
73 # page sets are responsible for issueing the markers themselves. | 77 # page sets are responsible for issueing the markers themselves. |
74 if len(self._smooth_records) == 0 and run_smooth_actions_record: | 78 if len(self._smooth_records) == 0 and run_smooth_actions_record: |
75 self._smooth_records = [run_smooth_actions_record] | 79 self._smooth_records = [run_smooth_actions_record] |
76 | 80 |
77 | 81 |
78 def CleanUp(self, tab): | 82 def CleanUp(self, tab): |
79 if tab.browser.is_tracing_running: | 83 if tab.browser.platform.tracing_controller.is_tracing_running: |
80 tab.browser.StopTracing() | 84 tab.browser.platform.tracing_controller.Stop() |
81 | 85 |
82 @property | 86 @property |
83 def model(self): | 87 def model(self): |
84 return self._model | 88 return self._model |
85 | 89 |
86 @property | 90 @property |
87 def renderer_process(self): | 91 def renderer_process(self): |
88 return self._renderer_process | 92 return self._renderer_process |
89 | 93 |
90 @property | 94 @property |
91 def smooth_records(self): | 95 def smooth_records(self): |
92 return self._smooth_records | 96 return self._smooth_records |
OLD | NEW |