OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import codecs | 4 import codecs |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import time | 7 import time |
8 import traceback | 8 import traceback |
9 import urlparse | 9 import urlparse |
10 import random | 10 import random |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 def _SetupTracingTab(self, state): | 241 def _SetupTracingTab(self, state): |
242 if state.browser.supports_tracing: | 242 if state.browser.supports_tracing: |
243 state.is_tracing = True | 243 state.is_tracing = True |
244 state.browser.StartTracing() | 244 state.browser.StartTracing() |
245 | 245 |
246 def _EndTracing(self, state, options, page): | 246 def _EndTracing(self, state, options, page): |
247 if state.is_tracing: | 247 if state.is_tracing: |
248 assert state.browser | 248 assert state.browser |
249 state.is_tracing = False | 249 state.is_tracing = False |
250 state.browser.StopTracing() | 250 state.browser.StopTracing() |
251 trace = state.browser.GetTrace() | 251 trace_result = state.browser.GetTraceResultAndReset() |
252 logging.info('Processing trace...') | 252 logging.info('Processing trace...') |
253 | 253 |
254 trace_file_base = os.path.join( | 254 trace_file_base = os.path.join( |
255 options.trace_dir, page.url_as_file_safe_name) | 255 options.trace_dir, page.url_as_file_safe_name) |
256 | 256 |
257 if options.page_repeat != 1 or options.pageset_repeat != 1: | 257 if options.page_repeat != 1 or options.pageset_repeat != 1: |
258 trace_file_index = 0 | 258 trace_file_index = 0 |
259 | 259 |
260 while True: | 260 while True: |
261 trace_file = '%s_%03d.json' % (trace_file_base, trace_file_index) | 261 trace_file = '%s_%03d.json' % (trace_file_base, trace_file_index) |
262 if not os.path.exists(trace_file): | 262 if not os.path.exists(trace_file): |
263 break | 263 break |
264 trace_file_index = trace_file_index + 1 | 264 trace_file_index = trace_file_index + 1 |
265 else: | 265 else: |
266 trace_file = '%s.json' % trace_file_base | 266 trace_file = '%s.json' % trace_file_base |
267 with codecs.open(trace_file, 'w', | 267 with codecs.open(trace_file, 'w', |
268 encoding='utf-8') as trace_file: | 268 encoding='utf-8') as trace_file: |
269 trace_file.write(trace) | 269 trace_result.WriteToFile(trace_file) |
270 logging.info('Trace saved.') | 270 logging.info('Trace saved.') |
271 | 271 |
272 def _PreparePage(self, page, tab, page_state, test, results): | 272 def _PreparePage(self, page, tab, page_state, test, results): |
273 parsed_url = urlparse.urlparse(page.url) | 273 parsed_url = urlparse.urlparse(page.url) |
274 if parsed_url[0] == 'file': | 274 if parsed_url[0] == 'file': |
275 dirname, filename = page.url_base_dir_and_file | 275 dirname, filename = page.url_base_dir_and_file |
276 tab.browser.SetHTTPServerDirectory(dirname) | 276 tab.browser.SetHTTPServerDirectory(dirname) |
277 target_side_url = tab.browser.http_server.UrlOf(filename) | 277 target_side_url = tab.browser.http_server.UrlOf(filename) |
278 else: | 278 else: |
279 target_side_url = page.url | 279 target_side_url = page.url |
(...skipping 25 matching lines...) Expand all Loading... |
305 tab.browser.credentials.LoginNoLongerNeeded(tab, page.credentials) | 305 tab.browser.credentials.LoginNoLongerNeeded(tab, page.credentials) |
306 try: | 306 try: |
307 tab.EvaluateJavaScript("""window.chrome && chrome.benchmarking && | 307 tab.EvaluateJavaScript("""window.chrome && chrome.benchmarking && |
308 chrome.benchmarking.closeConnections()""") | 308 chrome.benchmarking.closeConnections()""") |
309 except Exception: | 309 except Exception: |
310 pass | 310 pass |
311 | 311 |
312 @staticmethod | 312 @staticmethod |
313 def AddCommandLineOptions(parser): | 313 def AddCommandLineOptions(parser): |
314 page_filter_module.PageFilter.AddCommandLineOptions(parser) | 314 page_filter_module.PageFilter.AddCommandLineOptions(parser) |
OLD | NEW |