Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 """Monitor tracing events on chrome via chrome remote debugging.""" | 5 """Monitor tracing events on chrome via chrome remote debugging.""" |
| 6 | 6 |
| 7 import itertools | 7 import itertools |
| 8 import logging | 8 import logging |
| 9 import operator | 9 import operator |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 | 79 |
| 80 def GetMatchingMainFrameEvents(self, category, name): | 80 def GetMatchingMainFrameEvents(self, category, name): |
| 81 """Gets events matching |category| and |name| that occur in the main frame. | 81 """Gets events matching |category| and |name| that occur in the main frame. |
| 82 | 82 |
| 83 Events without a 'frame' key in their |args| are discarded. | 83 Events without a 'frame' key in their |args| are discarded. |
| 84 """ | 84 """ |
| 85 matching_events = self.GetMatchingEvents(category, name) | 85 matching_events = self.GetMatchingEvents(category, name) |
| 86 return [e for e in matching_events | 86 return [e for e in matching_events |
| 87 if 'frame' in e.args and e.args['frame'] == self.GetMainFrameID()] | 87 if 'frame' in e.args and e.args['frame'] == self.GetMainFrameID()] |
| 88 | 88 |
| 89 def GetMainFrameRoutingID(self): | |
| 90 """Returns the main frame routing ID.""" | |
| 91 for event in self.GetMatchingEvents( | |
| 92 'navigation', 'RenderFrameImpl::OnNavigate'): | |
| 93 return event.args['id'] | |
| 94 assert False | |
| 95 | |
| 89 def GetMainFrameID(self): | 96 def GetMainFrameID(self): |
| 90 """Returns the main frame ID.""" | 97 """Returns the main frame ID.""" |
| 91 if not self._main_frame_id: | 98 if not self._main_frame_id: |
| 92 navigation_start_events = self.GetMatchingEvents( | 99 navigation_start_events = self.GetMatchingEvents( |
| 93 'blink.user_timing', 'navigationStart') | 100 'blink.user_timing', 'navigationStart') |
| 94 first_event = min(navigation_start_events, key=lambda e: e.start_msec) | 101 first_event = min(navigation_start_events, key=lambda e: e.start_msec) |
| 95 self._main_frame_id = first_event.args['frame'] | 102 self._main_frame_id = first_event.args['frame'] |
| 96 | 103 |
| 97 return self._main_frame_id | 104 return self._main_frame_id |
| 98 | 105 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 225 |
| 219 if strict and spanning_events.HasPending(): | 226 if strict and spanning_events.HasPending(): |
| 220 raise devtools_monitor.DevToolsConnectionException( | 227 raise devtools_monitor.DevToolsConnectionException( |
| 221 'Pending spanning events: %s' % | 228 'Pending spanning events: %s' % |
| 222 '\n'.join([str(e) for e in spanning_events.PendingEvents()])) | 229 '\n'.join([str(e) for e in spanning_events.PendingEvents()])) |
| 223 | 230 |
| 224 def _GetEvents(self): | 231 def _GetEvents(self): |
| 225 self._IndexEvents() | 232 self._IndexEvents() |
| 226 return self._interval_tree.GetEvents() | 233 return self._interval_tree.GetEvents() |
| 227 | 234 |
| 235 def HasLoadingSucceed(self): | |
|
blundell
2016/06/28 13:53:01
nit: HasLoadingSucceeded
gabadie
2016/06/28 14:29:53
Done.
| |
| 236 """Returns whether the loading has succeed at recording time.""" | |
| 237 main_frame_id = self.GetMainFrameRoutingID() | |
| 238 for event in self.GetMatchingEvents( | |
| 239 'navigation', 'RenderFrameImpl::didFailProvisionalLoad'): | |
| 240 if event.args['id'] == main_frame_id: | |
| 241 return False | |
| 242 for event in self.GetMatchingEvents( | |
| 243 'navigation', 'RenderFrameImpl::didFailLoad'): | |
| 244 if event.args['id'] == main_frame_id: | |
| 245 return False | |
| 246 return True | |
| 247 | |
| 228 class _SpanningEvents(object): | 248 class _SpanningEvents(object): |
| 229 def __init__(self): | 249 def __init__(self): |
| 230 self._duration_stack = [] | 250 self._duration_stack = [] |
| 231 self._async_stacks = {} | 251 self._async_stacks = {} |
| 232 self._objects = {} | 252 self._objects = {} |
| 233 self._MATCH_HANDLER = { | 253 self._MATCH_HANDLER = { |
| 234 'B': self._DurationBegin, | 254 'B': self._DurationBegin, |
| 235 'E': self._DurationEnd, | 255 'E': self._DurationEnd, |
| 236 'b': self._AsyncStart, | 256 'b': self._AsyncStart, |
| 237 'e': self._AsyncEnd, | 257 'e': self._AsyncEnd, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 self._left = _IntervalTree(self.start, left_end, left_events) | 562 self._left = _IntervalTree(self.start, left_end, left_events) |
| 543 self._right = _IntervalTree(right_start, self.end, right_events) | 563 self._right = _IntervalTree(right_start, self.end, right_events) |
| 544 | 564 |
| 545 def _IsLeaf(self): | 565 def _IsLeaf(self): |
| 546 return self._left is None | 566 return self._left is None |
| 547 | 567 |
| 548 @classmethod | 568 @classmethod |
| 549 def _Overlaps(cls, event, start, end): | 569 def _Overlaps(cls, event, start, end): |
| 550 return (min(end, event.end_msec) - max(start, event.start_msec) > 0 | 570 return (min(end, event.end_msec) - max(start, event.start_msec) > 0 |
| 551 or start <= event.start_msec < end) # For instant events. | 571 or start <= event.start_msec < end) # For instant events. |
| OLD | NEW |