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 bisect | 7 import bisect |
8 import itertools | 8 import itertools |
9 import logging | 9 import logging |
10 import operator | 10 import operator |
11 | 11 |
12 import devtools_monitor | 12 import devtools_monitor |
13 | 13 |
14 | 14 |
| 15 DEFAULT_CATEGORIES = None |
| 16 |
| 17 |
15 class TracingTrack(devtools_monitor.Track): | 18 class TracingTrack(devtools_monitor.Track): |
16 """Grabs and processes trace event messages. | 19 """Grabs and processes trace event messages. |
17 | 20 |
18 See https://goo.gl/Qabkqk for details on the protocol. | 21 See https://goo.gl/Qabkqk for details on the protocol. |
19 """ | 22 """ |
20 def __init__(self, connection, categories=None, fetch_stream=False): | 23 def __init__(self, connection, |
| 24 categories=DEFAULT_CATEGORIES, |
| 25 fetch_stream=False): |
21 """Initialize this TracingTrack. | 26 """Initialize this TracingTrack. |
22 | 27 |
23 Args: | 28 Args: |
24 connection: a DevToolsConnection. | 29 connection: a DevToolsConnection. |
25 categories: None, or a string, or list of strings, of tracing categories | 30 categories: None, or a string, or list of strings, of tracing categories |
26 to filter. | 31 to filter. |
27 | 32 |
28 fetch_stream: if true, use a websocket stream to fetch tracing data rather | 33 fetch_stream: if true, use a websocket stream to fetch tracing data rather |
29 than dataCollected events. It appears based on very limited testing that | 34 than dataCollected events. It appears based on very limited testing that |
30 a stream is slower than the default reporting as dataCollected events. | 35 a stream is slower than the default reporting as dataCollected events. |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 if 'dur' in tracing_event else tracing_event['tdur']) | 302 if 'dur' in tracing_event else tracing_event['tdur']) |
298 self.end_msec = self.start_msec + duration / 1000.0 | 303 self.end_msec = self.start_msec + duration / 1000.0 |
299 | 304 |
300 @property | 305 @property |
301 def type(self): | 306 def type(self): |
302 if self._synthetic: | 307 if self._synthetic: |
303 return None | 308 return None |
304 return self._tracing_event['ph'] | 309 return self._tracing_event['ph'] |
305 | 310 |
306 @property | 311 @property |
| 312 def category(self): |
| 313 return self._tracing_event['cat'] |
| 314 |
| 315 @property |
| 316 def pid(self): |
| 317 return self._tracing_event['pid'] |
| 318 |
| 319 @property |
307 def args(self): | 320 def args(self): |
308 return self._tracing_event.get('args', {}) | 321 return self._tracing_event.get('args', {}) |
309 | 322 |
310 @property | 323 @property |
311 def id(self): | 324 def id(self): |
312 return self._tracing_event.get('id') | 325 return self._tracing_event.get('id') |
313 | 326 |
314 @property | 327 @property |
315 def name(self): | 328 def name(self): |
316 return self._tracing_event['name'] | 329 return self._tracing_event['name'] |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 self._left = _IntervalTree(self.start, left_end, left_events) | 468 self._left = _IntervalTree(self.start, left_end, left_events) |
456 self._right = _IntervalTree(right_start, self.end, right_events) | 469 self._right = _IntervalTree(right_start, self.end, right_events) |
457 | 470 |
458 def _IsLeaf(self): | 471 def _IsLeaf(self): |
459 return self._left is None | 472 return self._left is None |
460 | 473 |
461 @classmethod | 474 @classmethod |
462 def _Overlaps(cls, event, start, end): | 475 def _Overlaps(cls, event, start, end): |
463 return (min(end, event.end_msec) - max(start, event.start_msec) > 0 | 476 return (min(end, event.end_msec) - max(start, event.start_msec) > 0 |
464 or start <= event.start_msec < end) # For instant events. | 477 or start <= event.start_msec < end) # For instant events. |
OLD | NEW |