Chromium Code Reviews| 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 | 4 |
| 5 import logging | 5 import logging |
| 6 import re | 6 import re |
| 7 import socket | 7 import socket |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 self._devtools_port = devtools_port | 97 self._devtools_port = devtools_port |
| 98 self._remote_devtools_port = remote_devtools_port | 98 self._remote_devtools_port = remote_devtools_port |
| 99 self._devtools_http = devtools_http.DevToolsHttp(devtools_port) | 99 self._devtools_http = devtools_http.DevToolsHttp(devtools_port) |
| 100 self._browser_inspector_websocket = None | 100 self._browser_inspector_websocket = None |
| 101 self._tracing_backend = None | 101 self._tracing_backend = None |
| 102 self._memory_backend = None | 102 self._memory_backend = None |
| 103 self._app_backend = app_backend | 103 self._app_backend = app_backend |
| 104 self._devtools_context_map_backend = _DevToolsContextMapBackend( | 104 self._devtools_context_map_backend = _DevToolsContextMapBackend( |
| 105 self._app_backend, self) | 105 self._app_backend, self) |
| 106 | 106 |
| 107 self._tab_ids = None | |
|
Zhen Wang
2016/07/21 19:45:19
Does this tab id thing come from rebase?
rnephew (Reviews Here)
2016/07/21 19:55:20
No, it was required to fix a failing test this CL
| |
| 108 | |
| 107 if not self.supports_tracing: | 109 if not self.supports_tracing: |
| 108 return | 110 return |
| 109 chrome_tracing_devtools_manager.RegisterDevToolsClient( | 111 chrome_tracing_devtools_manager.RegisterDevToolsClient( |
| 110 self, self._app_backend.platform_backend) | 112 self, self._app_backend.platform_backend) |
| 111 | 113 |
| 112 # Telemetry has started Chrome tracing if there is trace config, so start | 114 # Telemetry has started Chrome tracing if there is trace config, so start |
| 113 # tracing on this newly created devtools client if needed. | 115 # tracing on this newly created devtools client if needed. |
| 114 trace_config = (self._app_backend.platform_backend | 116 trace_config = (self._app_backend.platform_backend |
| 115 .tracing_controller_backend.GetChromeTraceConfig()) | 117 .tracing_controller_backend.GetChromeTraceConfig()) |
| 116 if not trace_config: | 118 if not trace_config: |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 """ | 334 """ |
| 333 assert trace_config and trace_config.enable_chrome_trace | 335 assert trace_config and trace_config.enable_chrome_trace |
| 334 self._CreateTracingBackendIfNeeded() | 336 self._CreateTracingBackendIfNeeded() |
| 335 return self._tracing_backend.StartTracing( | 337 return self._tracing_backend.StartTracing( |
| 336 trace_config.chrome_trace_config, timeout) | 338 trace_config.chrome_trace_config, timeout) |
| 337 | 339 |
| 338 def RecordChromeClockSyncMarker(self, sync_id): | 340 def RecordChromeClockSyncMarker(self, sync_id): |
| 339 assert self.is_tracing_running, 'Tracing must be running to clock sync.' | 341 assert self.is_tracing_running, 'Tracing must be running to clock sync.' |
| 340 self._tracing_backend.RecordClockSyncMarker(sync_id) | 342 self._tracing_backend.RecordClockSyncMarker(sync_id) |
| 341 | 343 |
| 342 def StopChromeTracing(self, trace_data_builder, timeout=30): | 344 def StopChromeTracing(self): |
| 343 assert self.is_tracing_running | 345 assert self.is_tracing_running |
| 346 self._tab_ids = [] | |
| 344 try: | 347 try: |
| 345 context_map = self.GetUpdatedInspectableContexts() | 348 context_map = self.GetUpdatedInspectableContexts() |
| 346 for context in context_map.contexts: | 349 for context in context_map.contexts: |
| 347 if context['type'] not in ['iframe', 'page', 'webview']: | 350 if context['type'] not in ['iframe', 'page', 'webview']: |
| 348 continue | 351 continue |
| 349 context_id = context['id'] | 352 context_id = context['id'] |
| 350 backend = context_map.GetInspectorBackend(context_id) | 353 backend = context_map.GetInspectorBackend(context_id) |
| 351 backend.EvaluateJavaScript( | 354 backend.EvaluateJavaScript( |
| 352 "console.time('" + backend.id + "');" + | 355 "console.time('" + backend.id + "');" + |
| 353 "console.timeEnd('" + backend.id + "');" + | 356 "console.timeEnd('" + backend.id + "');" + |
| 354 "console.time.toString().indexOf('[native code]') != -1;") | 357 "console.time.toString().indexOf('[native code]') != -1;") |
| 358 self._tab_ids.append(backend.id) | |
| 359 finally: | |
| 360 self._tracing_backend.StopTracing() | |
| 361 | |
| 362 def CollectChromeTracingData(self, trace_data_builder, timeout=30): | |
| 363 try: | |
| 364 for tab_id in self._tab_ids: | |
| 355 trace_data_builder.AddEventsTo( | 365 trace_data_builder.AddEventsTo( |
| 356 trace_data_module.TAB_ID_PART, [backend.id]) | 366 trace_data_module.TAB_ID_PART, [tab_id]) |
| 367 self._tab_ids = None | |
| 357 finally: | 368 finally: |
| 358 self._tracing_backend.StopTracing(trace_data_builder, timeout) | 369 self._tracing_backend.CollectTraceData(trace_data_builder, timeout) |
| 359 | 370 |
| 360 def DumpMemory(self, timeout=30): | 371 def DumpMemory(self, timeout=30): |
| 361 """Dumps memory. | 372 """Dumps memory. |
| 362 | 373 |
| 363 Returns: | 374 Returns: |
| 364 GUID of the generated dump if successful, None otherwise. | 375 GUID of the generated dump if successful, None otherwise. |
| 365 | 376 |
| 366 Raises: | 377 Raises: |
| 367 TracingTimeoutException: If more than |timeout| seconds has passed | 378 TracingTimeoutException: If more than |timeout| seconds has passed |
| 368 since the last time any data is received. | 379 since the last time any data is received. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 % context_id) | 481 % context_id) |
| 471 continue | 482 continue |
| 472 valid_contexts.append(context) | 483 valid_contexts.append(context) |
| 473 self._contexts = valid_contexts | 484 self._contexts = valid_contexts |
| 474 | 485 |
| 475 def Clear(self): | 486 def Clear(self): |
| 476 for backend in self._inspector_backends_dict.values(): | 487 for backend in self._inspector_backends_dict.values(): |
| 477 backend.Disconnect() | 488 backend.Disconnect() |
| 478 self._inspector_backends_dict = {} | 489 self._inspector_backends_dict = {} |
| 479 self._contexts = None | 490 self._contexts = None |
| OLD | NEW |