OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 telemetry.timeline_event import TimelineEvent | 4 from telemetry.core.chrome import timeline_event |
5 from telemetry.timeline_model import TimelineModel | 5 from telemetry.core.chrome import timeline_model |
6 | 6 |
7 class TabBackendException(Exception): | 7 class TabBackendException(Exception): |
8 pass | 8 pass |
9 | 9 |
10 class InspectorTimeline(object): | 10 class InspectorTimeline(object): |
11 """Implementation of dev tools timeline.""" | 11 """Implementation of dev tools timeline.""" |
12 class Recorder(object): | 12 class Recorder(object): |
13 """Utility class to Start / Stop recording timeline.""" | 13 """Utility class to Start / Stop recording timeline.""" |
14 def __init__(self, tab): | 14 def __init__(self, tab): |
15 self._tab = tab | 15 self._tab = tab |
(...skipping 10 matching lines...) Expand all Loading... |
26 self._timeline_model = None | 26 self._timeline_model = None |
27 | 27 |
28 @property | 28 @property |
29 def timeline_model(self): | 29 def timeline_model(self): |
30 return self._timeline_model | 30 return self._timeline_model |
31 | 31 |
32 def Start(self): | 32 def Start(self): |
33 if self._is_recording: | 33 if self._is_recording: |
34 return | 34 return |
35 self._is_recording = True | 35 self._is_recording = True |
36 self._timeline_model = TimelineModel() | 36 self._timeline_model = timeline_model.TimelineModel() |
37 self._inspector_backend.RegisterDomain('Timeline', | 37 self._inspector_backend.RegisterDomain('Timeline', |
38 self._OnNotification, self._OnClose) | 38 self._OnNotification, self._OnClose) |
39 req = {'method': 'Timeline.start'} | 39 req = {'method': 'Timeline.start'} |
40 self._SendSyncRequest(req) | 40 self._SendSyncRequest(req) |
41 | 41 |
42 def Stop(self): | 42 def Stop(self): |
43 if not self._is_recording: | 43 if not self._is_recording: |
44 raise TabBackendException('Stop() called but not started') | 44 raise TabBackendException('Stop() called but not started') |
45 self._is_recording = False | 45 self._is_recording = False |
46 self._timeline_model.DidFinishRecording() | 46 self._timeline_model.DidFinishRecording() |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 # events with start-time and end-time get imported. | 89 # events with start-time and end-time get imported. |
90 if ('startTime' in raw_inspector_event and | 90 if ('startTime' in raw_inspector_event and |
91 'endTime' in raw_inspector_event): | 91 'endTime' in raw_inspector_event): |
92 args = {} | 92 args = {} |
93 for x in raw_inspector_event: | 93 for x in raw_inspector_event: |
94 if x in ('startTime', 'endTime', 'children'): | 94 if x in ('startTime', 'endTime', 'children'): |
95 continue | 95 continue |
96 args[x] = raw_inspector_event[x] | 96 args[x] = raw_inspector_event[x] |
97 if len(args) == 0: | 97 if len(args) == 0: |
98 args = None | 98 args = None |
99 newly_created_event = TimelineEvent( | 99 newly_created_event = timeline_event.TimelineEvent( |
100 name=raw_inspector_event['type'], | 100 name=raw_inspector_event['type'], |
101 start_time_ms=raw_inspector_event['startTime'], | 101 start_time_ms=raw_inspector_event['startTime'], |
102 duration_ms=(raw_inspector_event['endTime'] - | 102 duration_ms=(raw_inspector_event['endTime'] - |
103 raw_inspector_event['startTime']), | 103 raw_inspector_event['startTime']), |
104 args=args) | 104 args=args) |
105 if parent_for_created_events: | 105 if parent_for_created_events: |
106 parent_for_created_events.children.append(newly_created_event) | 106 parent_for_created_events.children.append(newly_created_event) |
107 else: | 107 else: |
108 newly_created_event = None | 108 newly_created_event = None |
109 | 109 |
110 # Process any children events, creating TimelineEvents for them as well. | 110 # Process any children events, creating TimelineEvents for them as well. |
111 if newly_created_event: | 111 if newly_created_event: |
112 parent_for_children = newly_created_event | 112 parent_for_children = newly_created_event |
113 else: | 113 else: |
114 parent_for_children = parent_for_created_events | 114 parent_for_children = parent_for_created_events |
115 for child in raw_inspector_event.get('children', []): | 115 for child in raw_inspector_event.get('children', []): |
116 InspectorTimeline._RawEventToTimelineEventRecursive( | 116 InspectorTimeline._RawEventToTimelineEventRecursive( |
117 parent_for_children, child) | 117 parent_for_children, child) |
118 return newly_created_event | 118 return newly_created_event |
119 | 119 |
120 def _OnClose(self): | 120 def _OnClose(self): |
121 pass | 121 pass |
OLD | NEW |