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

Side by Side Diff: tools/telemetry/telemetry/page_runner.py

Issue 11434040: [telemetry] Number the trace .json files in trace-dir. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 logging 4 import logging
5 import os 5 import os
6 import time 6 import time
7 import traceback 7 import traceback
8 import urlparse 8 import urlparse
9 import random 9 import random
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 if options.test_shuffle_order_file and not options.test_shuffle: 42 if options.test_shuffle_order_file and not options.test_shuffle:
43 raise Exception('--test-shuffle-order-file requires --test-shuffle.') 43 raise Exception('--test-shuffle-order-file requires --test-shuffle.')
44 44
45 if options.test_shuffle_order_file: 45 if options.test_shuffle_order_file:
46 return page_set.ReorderPageSet(options.test_shuffle_order_file) 46 return page_set.ReorderPageSet(options.test_shuffle_order_file)
47 47
48 pages = page_set.pages[:] 48 pages = page_set.pages[:]
49 if options.test_shuffle: 49 if options.test_shuffle:
50 random.Random().shuffle(pages) 50 random.Random().shuffle(pages)
51 return [page 51 return [page
52 for _ in xrange(options.pageset_repeat) 52 for _ in xrange(int(options.pageset_repeat))
53 for page in pages 53 for page in pages
54 for _ in xrange(options.page_repeat)] 54 for _ in xrange(int(options.page_repeat))]
55 55
56 class PageRunner(object): 56 class PageRunner(object):
57 """Runs a given test against a given test.""" 57 """Runs a given test against a given test."""
58 def __init__(self, page_set): 58 def __init__(self, page_set):
59 self.page_set = page_set 59 self.page_set = page_set
60 60
61 def __enter__(self): 61 def __enter__(self):
62 return self 62 return self
63 63
64 def __exit__(self, *args): 64 def __exit__(self, *args):
(...skipping 26 matching lines...) Expand all
91 credentials_path = None 91 credentials_path = None
92 92
93 # Set up user agent. 93 # Set up user agent.
94 if self.page_set.user_agent_type: 94 if self.page_set.user_agent_type:
95 options.browser_user_agent_type = self.page_set.user_agent_type 95 options.browser_user_agent_type = self.page_set.user_agent_type
96 96
97 for page in self.page_set: 97 for page in self.page_set:
98 test.CustomizeBrowserOptionsForPage(page, possible_browser.options) 98 test.CustomizeBrowserOptionsForPage(page, possible_browser.options)
99 99
100 # Check tracing directory. 100 # Check tracing directory.
101 if options.trace_dir and not os.path.isdir(options.trace_dir): 101 if options.trace_dir:
102 raise Exception('Trace directory doesn\'t exist: %s' % options.trace_dir) 102 if not os.path.isdir(options.trace_dir):
103 raise Exception('Trace directory doesn\'t exist: %s' %
104 options.trace_dir)
105 elif os.listdir(options.trace_dir):
106 raise Exception('Trace directory isn\'t empty: %s' % options.trace_dir)
103 107
104 # Reorder page set based on options. 108 # Reorder page set based on options.
105 pages = _ShufflePageSet(self.page_set, options) 109 pages = _ShufflePageSet(self.page_set, options)
106 110
107 state = _RunState() 111 state = _RunState()
108 try: 112 try:
109 for page in pages: 113 for page in pages:
110 # Set up browser. 114 # Set up browser.
111 if not state.browser: 115 if not state.browser:
112 assert not state.tab 116 assert not state.tab
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if options.trace_dir and state.trace_tab: 157 if options.trace_dir and state.trace_tab:
154 def IsTracingRunning(): 158 def IsTracingRunning():
155 return state.trace_tab.runtime.Evaluate( 159 return state.trace_tab.runtime.Evaluate(
156 'tracingController.isTracingEnabled') 160 'tracingController.isTracingEnabled')
157 # Tracing might have ended already if the buffer filled up. 161 # Tracing might have ended already if the buffer filled up.
158 if IsTracingRunning(): 162 if IsTracingRunning():
159 state.trace_tab.runtime.Execute('tracingController.endTracing()') 163 state.trace_tab.runtime.Execute('tracingController.endTracing()')
160 util.WaitFor(lambda: not IsTracingRunning(), 10) 164 util.WaitFor(lambda: not IsTracingRunning(), 10)
161 165
162 logging.info('Processing trace...') 166 logging.info('Processing trace...')
163 with open(os.path.join(options.trace_dir, page.url_as_file_safe_name + 167
164 '.json'), 'w') as trace_file: 168 trace_file_base = os.path.join(
169 options.trace_dir, page.url_as_file_safe_name)
170
171 if options.page_repeat != 1 or options.pageset_repeat != 1:
172 trace_file_index = 0
173
174 while True:
175 trace_file = "%s_%03d.json" % (trace_file_base, trace_file_index)
dtu 2012/12/01 01:22:14 Single quotes. Below too.
176 if not os.path.exists(trace_file):
177 break
178 trace_file_index = trace_file_index + 1
179 else:
180 trace_file = "%s.json" % trace_file_base
181
182 with open(trace_file, 'w') as trace_file:
165 trace_file.write(state.trace_tab.runtime.Evaluate(""" 183 trace_file.write(state.trace_tab.runtime.Evaluate("""
166 JSON.stringify({ 184 JSON.stringify({
167 traceEvents: tracingController.traceEvents, 185 traceEvents: tracingController.traceEvents,
168 systemTraceEvents: tracingController.systemTraceEvents, 186 systemTraceEvents: tracingController.systemTraceEvents,
169 clientInfo: tracingController.clientInfo_, 187 clientInfo: tracingController.clientInfo_,
170 gpuInfo: tracingController.gpuInfo_ 188 gpuInfo: tracingController.gpuInfo_
171 }); 189 });
172 """)) 190 """))
173 logging.info('Trace saved.') 191 logging.info('Trace saved.')
174 finally: 192 finally:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 self.WaitForPageToLoad(page.wait_for_javascript_expression, tab) 284 self.WaitForPageToLoad(page.wait_for_javascript_expression, tab)
267 285
268 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() 286 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
269 return True 287 return True
270 288
271 def _CleanUpPage(self, page, tab, page_state): # pylint: disable=R0201 289 def _CleanUpPage(self, page, tab, page_state): # pylint: disable=R0201
272 if page.credentials and page_state.did_login: 290 if page.credentials and page_state.did_login:
273 tab.browser.credentials.LoginNoLongerNeeded(tab, page.credentials) 291 tab.browser.credentials.LoginNoLongerNeeded(tab, page.credentials)
274 tab.runtime.Evaluate("""window.chrome && chrome.benchmarking && 292 tab.runtime.Evaluate("""window.chrome && chrome.benchmarking &&
275 chrome.benchmarking.closeConnections()""") 293 chrome.benchmarking.closeConnections()""")
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698