Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/android/loading/tracing.py

Issue 1888343003: Clovis: contentful paint upgrades. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url-rename
Patch Set: Use new frame detection Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 bisect 7 import bisect
8 import itertools 8 import itertools
9 import logging 9 import logging
10 import operator 10 import operator
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 def GetEvents(self): 86 def GetEvents(self):
87 return self._events 87 return self._events
88 88
89 def GetMatchingEvents(self, category, name): 89 def GetMatchingEvents(self, category, name):
90 """Gets events matching |category| and |name|.""" 90 """Gets events matching |category| and |name|."""
91 return [e for e in self.GetEvents() if e.Matches(category, name)] 91 return [e for e in self.GetEvents() if e.Matches(category, name)]
92 92
93 def GetMatchingMainFrameEvents(self, category, name): 93 def GetMatchingMainFrameEvents(self, category, name):
94 """Gets events matching |category| and |name| that occur in the main frame. 94 """Gets events matching |category| and |name| that occur in the main frame.
95 Assumes that the events in question have a 'frame' key in their |args|.""" 95
96 Events without a 'frame' key in their |args| are discarded.
97 """
96 matching_events = self.GetMatchingEvents(category, name) 98 matching_events = self.GetMatchingEvents(category, name)
97 return [e for e in matching_events 99 return [e for e in matching_events
98 if e.args['frame'] == self._GetMainFrameID()] 100 if 'frame' in e.args and e.args['frame'] == self.GetMainFrameID()]
101
102 def GetMainFrameID(self):
103 """Returns the main frame ID."""
104 if not self._main_frame_id:
105 navigation_start_events = [e for e in self.GetEvents()
106 if e.Matches('blink.user_timing', 'navigationStart')]
107 first_event = min(navigation_start_events, key=lambda e: e.start_msec)
108 self._main_frame_id = first_event.args['frame']
109
110 return self._main_frame_id
111
112 def SetMainFrameID(self, frame_id):
113 """Set the main frame ID. Normally this is used only for testing."""
114 self._main_frame_id = frame_id
99 115
100 def EventsAt(self, msec): 116 def EventsAt(self, msec):
101 """Gets events active at a timestamp. 117 """Gets events active at a timestamp.
102 118
103 Args: 119 Args:
104 msec: tracing milliseconds to query. Tracing milliseconds appears to be 120 msec: tracing milliseconds to query. Tracing milliseconds appears to be
105 since chrome startup (ie, arbitrary epoch). 121 since chrome startup (ie, arbitrary epoch).
106 122
107 Returns: 123 Returns:
108 List of events active at that timestamp. Instantaneous (ie, instant, 124 List of events active at that timestamp. Instantaneous (ie, instant,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 self._IndexEvents() 206 self._IndexEvents()
191 assert 'step' in step_event.args and step_event.tracing_event['ph'] == 'T' 207 assert 'step' in step_event.args and step_event.tracing_event['ph'] == 'T'
192 candidates = self._interval_tree.EventsAt(step_event.start_msec) 208 candidates = self._interval_tree.EventsAt(step_event.start_msec)
193 for event in candidates: 209 for event in candidates:
194 # IDs are only unique within a process (often they are pointers). 210 # IDs are only unique within a process (often they are pointers).
195 if (event.pid == step_event.pid and event.tracing_event['ph'] != 'T' 211 if (event.pid == step_event.pid and event.tracing_event['ph'] != 'T'
196 and event.name == step_event.name and event.id == step_event.id): 212 and event.name == step_event.name and event.id == step_event.id):
197 return event 213 return event
198 return None 214 return None
199 215
200 def _GetMainFrameID(self):
201 """Returns the main frame ID."""
202 if not self._main_frame_id:
203 navigation_start_events = [e for e in self.GetEvents()
204 if e.Matches('blink.user_timing', 'navigationStart')]
205 first_event = min(navigation_start_events, key=lambda e: e.start_msec)
206 self._main_frame_id = first_event.args['frame']
207
208 return self._main_frame_id
209
210 def _IndexEvents(self, strict=False): 216 def _IndexEvents(self, strict=False):
211 if self._interval_tree: 217 if self._interval_tree:
212 return 218 return
213 complete_events = [] 219 complete_events = []
214 spanning_events = self._SpanningEvents() 220 spanning_events = self._SpanningEvents()
215 for event in self._events: 221 for event in self._events:
216 if not event.IsIndexable(): 222 if not event.IsIndexable():
217 continue 223 continue
218 if event.IsComplete(): 224 if event.IsComplete():
219 complete_events.append(event) 225 complete_events.append(event)
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 self._left = _IntervalTree(self.start, left_end, left_events) 555 self._left = _IntervalTree(self.start, left_end, left_events)
550 self._right = _IntervalTree(right_start, self.end, right_events) 556 self._right = _IntervalTree(right_start, self.end, right_events)
551 557
552 def _IsLeaf(self): 558 def _IsLeaf(self):
553 return self._left is None 559 return self._left is None
554 560
555 @classmethod 561 @classmethod
556 def _Overlaps(cls, event, start, end): 562 def _Overlaps(cls, event, start, end):
557 return (min(end, event.end_msec) - max(start, event.start_msec) > 0 563 return (min(end, event.end_msec) - max(start, event.start_msec) > 0
558 or start <= event.start_msec < end) # For instant events. 564 or start <= event.start_msec < end) # For instant events.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698