Chromium Code Reviews| 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 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 |
| 11 from telemetry import browser_gone_exception | 11 from telemetry import browser_gone_exception |
| 12 from telemetry import page_test | 12 from telemetry import page_test |
| 13 from telemetry import tab_crash_exception | 13 from telemetry import tab_crash_exception |
| 14 from telemetry import util | 14 from telemetry import util |
| 15 from telemetry import wpr_modes | 15 from telemetry import wpr_modes |
| 16 | 16 |
| 17 class PageState(object): | 17 class PageState(object): |
| 18 def __init__(self): | 18 def __init__(self): |
| 19 self.did_login = False | 19 self.did_login = False |
| 20 | 20 |
| 21 class _RunState(object): | 21 class _RunState(object): |
| 22 def __init__(self): | 22 def __init__(self): |
| 23 self.first_browser = True | 23 self.first_browser = True |
| 24 self.browser = None | 24 self.browser = None |
| 25 self.tab = None | 25 self.tab = None |
| 26 self.trace_tab = None | 26 self.trace_tab = None |
| 27 self.performance_test = False | |
| 27 | 28 |
| 28 def Close(self): | 29 def Close(self): |
| 29 if self.trace_tab: | 30 if self.trace_tab: |
| 30 self.trace_tab.Disconnect() | 31 self.trace_tab.Disconnect() |
| 31 self.trace_tab = None | 32 self.trace_tab = None |
| 32 | 33 |
| 33 if self.tab: | 34 if self.tab: |
| 34 self.tab.Disconnect() | 35 self.tab.Disconnect() |
| 35 self.tab = None | 36 self.tab = None |
| 36 | 37 |
| 37 if self.browser: | 38 if self.browser: |
| 39 if self.performance_test: | |
| 40 self.browser.platform.SetFullPerformanceModeEnabled(False) | |
| 38 self.browser.Close() | 41 self.browser.Close() |
| 39 self.browser = None | 42 self.browser = None |
| 40 | 43 |
| 44 | |
| 41 def _ShufflePageSet(page_set, options): | 45 def _ShufflePageSet(page_set, options): |
| 42 if options.test_shuffle_order_file and not options.test_shuffle: | 46 if options.test_shuffle_order_file and not options.test_shuffle: |
| 43 raise Exception('--test-shuffle-order-file requires --test-shuffle.') | 47 raise Exception('--test-shuffle-order-file requires --test-shuffle.') |
| 44 | 48 |
| 45 if options.test_shuffle_order_file: | 49 if options.test_shuffle_order_file: |
| 46 return page_set.ReorderPageSet(options.test_shuffle_order_file) | 50 return page_set.ReorderPageSet(options.test_shuffle_order_file) |
| 47 | 51 |
| 48 pages = page_set.pages[:] | 52 pages = page_set.pages[:] |
| 49 if options.test_shuffle: | 53 if options.test_shuffle: |
| 50 random.Random().shuffle(pages) | 54 random.Random().shuffle(pages) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 self._RunPage(options, page, state.tab, test, results) | 132 self._RunPage(options, page, state.tab, test, results) |
| 129 except tab_crash_exception.TabCrashException: | 133 except tab_crash_exception.TabCrashException: |
| 130 # Close the crashed tab. We'll open another before the next run. | 134 # Close the crashed tab. We'll open another before the next run. |
| 131 if state.browser.supports_tab_control: | 135 if state.browser.supports_tab_control: |
| 132 state.tab.Close() | 136 state.tab.Close() |
| 133 state.tab = None | 137 state.tab = None |
| 134 # If we don't support tab control, just restart the browser. | 138 # If we don't support tab control, just restart the browser. |
| 135 else: | 139 else: |
| 136 state.Close() | 140 state.Close() |
| 137 | 141 |
| 142 if (state.browser.platform.CanMonitorThermalThrottling() and | |
| 143 state.browser.platform.IsThermallyThrottled()): | |
|
aberent
2013/01/29 14:03:36
See my other comments on thermal throttling. This
bulach
2013/02/22 11:54:25
good point, added a check for "IsThrottled" at the
| |
| 144 raise Exception('Device was thermally throttled during ' | |
| 145 'performance tests.') | |
|
tonyg
2013/02/21 18:07:08
I'm on the fence about whether this should really
bulach
2013/02/22 11:54:25
agree. done as just messages for now.
| |
| 146 | |
| 138 if options.trace_dir and state.trace_tab: | 147 if options.trace_dir and state.trace_tab: |
| 139 self._EndTracing(state, options, page) | 148 self._EndTracing(state, options, page) |
| 140 break | 149 break |
| 141 except browser_gone_exception.BrowserGoneException: | 150 except browser_gone_exception.BrowserGoneException: |
| 142 logging.warning('Lost connection to browser. Retrying.') | 151 logging.warning('Lost connection to browser. Retrying.') |
| 143 state.Close() | 152 state.Close() |
| 144 tries -= 1 | 153 tries -= 1 |
| 145 if not tries: | 154 if not tries: |
| 146 logging.error('Lost connection to browser 3 times. Failing.') | 155 logging.error('Lost connection to browser 3 times. Failing.') |
| 147 raise | 156 raise |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 def IsPageLoaded(): | 221 def IsPageLoaded(): |
| 213 return tab.runtime.Evaluate(expression) | 222 return tab.runtime.Evaluate(expression) |
| 214 | 223 |
| 215 # Wait until the form is submitted and the page completes loading. | 224 # Wait until the form is submitted and the page completes loading. |
| 216 util.WaitFor(IsPageLoaded, 60) | 225 util.WaitFor(IsPageLoaded, 60) |
| 217 | 226 |
| 218 def _SetupBrowser(self, state, test, possible_browser, credentials_path, | 227 def _SetupBrowser(self, state, test, possible_browser, credentials_path, |
| 219 archive_path): | 228 archive_path): |
| 220 assert not state.tab | 229 assert not state.tab |
| 221 state.browser = possible_browser.Create() | 230 state.browser = possible_browser.Create() |
| 231 | |
| 232 if possible_browser.options.performance_test: | |
| 233 state.performance_test = True | |
| 234 state.browser.platform.SetFullPerformanceModeEnabled(True) | |
|
tonyg
2013/02/21 18:07:08
I wonder if it would be more robust to call SetFul
bulach
2013/02/22 11:54:25
Done.
| |
| 235 | |
| 222 state.browser.credentials.credentials_path = credentials_path | 236 state.browser.credentials.credentials_path = credentials_path |
| 223 test.SetUpBrowser(state.browser) | 237 test.SetUpBrowser(state.browser) |
| 224 | 238 |
| 225 if state.first_browser: | 239 if state.first_browser: |
| 226 state.browser.credentials.WarnIfMissingCredentials(self.page_set) | 240 state.browser.credentials.WarnIfMissingCredentials(self.page_set) |
| 227 state.first_browser = False | 241 state.first_browser = False |
| 228 | 242 |
| 229 state.browser.SetReplayArchivePath(archive_path) | 243 state.browser.SetReplayArchivePath(archive_path) |
| 230 | 244 |
| 231 def _SetupTracingTab(self, state): | 245 def _SetupTracingTab(self, state): |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 return True | 325 return True |
| 312 | 326 |
| 313 def _CleanUpPage(self, page, tab, page_state): # pylint: disable=R0201 | 327 def _CleanUpPage(self, page, tab, page_state): # pylint: disable=R0201 |
| 314 if page.credentials and page_state.did_login: | 328 if page.credentials and page_state.did_login: |
| 315 tab.browser.credentials.LoginNoLongerNeeded(tab, page.credentials) | 329 tab.browser.credentials.LoginNoLongerNeeded(tab, page.credentials) |
| 316 try: | 330 try: |
| 317 tab.runtime.Evaluate("""window.chrome && chrome.benchmarking && | 331 tab.runtime.Evaluate("""window.chrome && chrome.benchmarking && |
| 318 chrome.benchmarking.closeConnections()""") | 332 chrome.benchmarking.closeConnections()""") |
| 319 except Exception: | 333 except Exception: |
| 320 pass | 334 pass |
| OLD | NEW |