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

Unified Diff: tools/telemetry/telemetry/page_runner.py

Issue 11548032: Telemetry / Devtools TraceHandler: exposes tracing via dev tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Error handling and comments Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/page_runner.py
diff --git a/tools/telemetry/telemetry/page_runner.py b/tools/telemetry/telemetry/page_runner.py
index ffe2251e646814328e68f592bcbc5e6753d37708..c19d74a503f8d2a1b5c14483af7341bdd36ab680 100644
--- a/tools/telemetry/telemetry/page_runner.py
+++ b/tools/telemetry/telemetry/page_runner.py
@@ -23,13 +23,9 @@ class _RunState(object):
self.first_browser = True
self.browser = None
self.tab = None
- self.trace_tab = None
+ self.is_tracing = False
def Close(self):
- if self.trace_tab:
- self.trace_tab.Disconnect()
- self.trace_tab = None
-
if self.tab:
self.tab.Disconnect()
self.tab = None
@@ -136,7 +132,7 @@ http://goto/read-src-internal, or create a new archive using record_wpr.
logging.warning('Tab crashed: %s%s', page.url, stdout)
state.Close()
- if options.trace_dir and state.trace_tab:
+ if options.trace_dir:
self._EndTracing(state, options, page)
break
except browser_gone_exception.BrowserGoneException:
@@ -228,56 +224,33 @@ http://goto/read-src-internal, or create a new archive using record_wpr.
state.browser.SetReplayArchivePath(archive_path)
def _SetupTracingTab(self, state):
- if not state.trace_tab:
- # Swap the two tabs because new tabs open to about:blank, and we
- # can't navigate across protocols to chrome://tracing. The initial
- # tab starts at chrome://newtab, so it works for that tab.
- # TODO(dtu): If the trace_tab crashes, we're hosed.
- state.trace_tab = state.tab
- state.tab = state.browser.tabs.New()
+ if state.browser.supports_tracing:
+ state.is_tracing = True
+ state.browser.StartTracing()
- state.trace_tab.page.Navigate('chrome://tracing')
- state.trace_tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
+ def _EndTracing(self, state, options, page):
+ if state.is_tracing:
+ state.is_tracing = False
+ state.browser.StopTracing()
+ trace = state.browser.GetTrace()
+ logging.info('Processing trace...')
- # Start tracing.
- state.trace_tab.runtime.Execute('tracingController.beginTracing('
- 'tracingController.supportsSystemTracing);')
+ trace_file_base = os.path.join(
+ options.trace_dir, page.url_as_file_safe_name)
- def _EndTracing(self, state, options, page):
- def IsTracingRunning():
- return state.trace_tab.runtime.Evaluate(
- 'tracingController.isTracingEnabled')
- # Tracing might have ended already if the buffer filled up.
- if IsTracingRunning():
- state.trace_tab.runtime.Execute('tracingController.endTracing()')
- util.WaitFor(lambda: not IsTracingRunning(), 10)
-
- logging.info('Processing trace...')
-
- trace_file_base = os.path.join(
- options.trace_dir, page.url_as_file_safe_name)
-
- if options.page_repeat != 1 or options.pageset_repeat != 1:
- trace_file_index = 0
-
- while True:
- trace_file = '%s_%03d.json' % (trace_file_base, trace_file_index)
- if not os.path.exists(trace_file):
- break
- trace_file_index = trace_file_index + 1
- else:
- trace_file = '%s.json' % trace_file_base
-
- with open(trace_file, 'w') as trace_file:
- trace_file.write(state.trace_tab.runtime.Evaluate("""
- JSON.stringify({
- traceEvents: tracingController.traceEvents,
- systemTraceEvents: tracingController.systemTraceEvents,
- clientInfo: tracingController.clientInfo_,
- gpuInfo: tracingController.gpuInfo_
- });
- """))
- logging.info('Trace saved.')
+ if options.page_repeat != 1 or options.pageset_repeat != 1:
+ trace_file_index = 0
+
+ while True:
+ trace_file = '%s_%03d.json' % (trace_file_base, trace_file_index)
+ if not os.path.exists(trace_file):
+ break
+ trace_file_index = trace_file_index + 1
+ else:
+ trace_file = '%s.json' % trace_file_base
+ with open(trace_file, 'w') as trace_file:
+ trace_file.write(trace)
+ logging.info('Trace saved.')
def _PreparePage(self, page, tab, page_state, results):
parsed_url = urlparse.urlparse(page.url)

Powered by Google App Engine
This is Rietveld 408576698