Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 collections | 4 import collections |
| 5 import json | 5 import json |
| 6 import logging | 6 import logging |
| 7 | 7 |
| 8 from telemetry.core import exceptions | 8 from telemetry.core import exceptions |
| 9 from telemetry.value import histogram_util | 9 from telemetry.value import histogram_util |
| 10 from telemetry.value import scalar | 10 from telemetry.value import scalar |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 tab) | 40 tab) |
| 41 if high_bytes == 0 and low_bytes == 0: | 41 if high_bytes == 0 and low_bytes == 0: |
| 42 return None | 42 return None |
| 43 return (int(high_bytes) << 32) | (int(low_bytes) << 1) | 43 return (int(high_bytes) << 32) | (int(low_bytes) << 1) |
| 44 | 44 |
| 45 def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results): | 45 def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results): |
| 46 """Records the tab load times for the browser. """ | 46 """Records the tab load times for the browser. """ |
| 47 tab_load_times = [] | 47 tab_load_times = [] |
| 48 TabLoadTime = collections.namedtuple( | 48 TabLoadTime = collections.namedtuple( |
| 49 'TabLoadTime', | 49 'TabLoadTime', |
| 50 ['load_start_ms', 'load_duration_ms', 'request_start_ms']) | 50 ['request_start_ms', 'load_end_ms']) |
| 51 | 51 |
| 52 def RecordTabLoadTime(t): | 52 def RecordTabLoadTime(t): |
| 53 def EvaluateInt(exp): | |
| 54 val = t.EvaluateJavaScript(exp) | |
| 55 if not val: | |
| 56 logging.warn('%s undefined' % exp) | |
| 57 return 0 | |
| 58 return int(val) | |
| 59 | |
| 53 try: | 60 try: |
| 54 t.WaitForDocumentReadyStateToBeComplete() | 61 t.WaitForJavaScriptExpression( |
| 62 'window.performance.timing["loadEventEnd"] > 0', 10) | |
| 55 | 63 |
| 56 result = t.EvaluateJavaScript( | 64 # EvaluateJavaScript(window.performance.timing) doesn't guarantee to |
| 57 'statsCollectionController.tabLoadTiming()') | 65 # return the desired javascript object (crbug/472603). It may return an |
| 58 result = json.loads(result) | 66 # empty object. However getting individual field works. |
| 67 # The behavior depends on Webkit implementation on different platforms. | |
| 68 load_event_end = EvaluateInt( | |
| 69 'window.performance.timing["loadEventEnd"]') | |
| 70 request_start = EvaluateInt( | |
| 71 'window.performance.timing["requestStart"]') | |
| 59 | 72 |
| 60 if 'load_start_ms' not in result or 'load_duration_ms' not in result: | 73 tab_load_times.append(TabLoadTime(request_start, load_event_end)) |
|
nednguyen
2015/04/03 21:24:59
Why do we need to use a list here? Seems like this
cylee1
2015/04/03 21:26:57
I dont' know. It's how it was originally.
Do you s
nednguyen
2015/04/03 21:28:36
I prefer refactoring work to be done in a differen
| |
| 61 raise Exception("Outdated Chrome version, " | |
| 62 "statsCollectionController.tabLoadTiming() not present") | |
| 63 if result['load_duration_ms'] is None: | |
| 64 tab_title = t.EvaluateJavaScript('document.title') | |
| 65 print "Page: ", tab_title, " didn't finish loading." | |
| 66 return | |
| 67 | 74 |
| 68 perf_timing = t.EvaluateJavaScript('window.performance.timing') | |
| 69 if 'requestStart' not in perf_timing: | |
| 70 perf_timing['requestStart'] = 0 # Exclude from benchmark results | |
| 71 print 'requestStart is not supported by this browser' | |
| 72 | |
| 73 tab_load_times.append(TabLoadTime( | |
| 74 int(result['load_start_ms']), | |
| 75 int(result['load_duration_ms']), | |
| 76 int(perf_timing['requestStart']))) | |
| 77 except exceptions.TimeoutException: | 75 except exceptions.TimeoutException: |
| 78 # Low memory Android devices may not be able to load more than | 76 # Low memory Android devices may not be able to load more than |
| 79 # one tab at a time, so may timeout when the test attempts to | 77 # one tab at a time, so may timeout when the test attempts to |
| 80 # access a background tab. Ignore these tabs. | 78 # access a background tab. Ignore these tabs. |
| 81 logging.error("Tab timed out on JavaScript access") | 79 logging.error("Tab timed out on JavaScript access") |
| 82 | 80 |
| 83 # Only measure the foreground tab. We can't measure all tabs on Android | 81 # Only measure the foreground tab. We can't measure all tabs on Android |
| 84 # because on Android the data of the background tabs is loaded on demand, | 82 # because on Android the data of the background tabs is loaded on demand, |
| 85 # when the user switches to them, rather than during startup. In view of | 83 # when the user switches to them, rather than during startup. In view of |
| 86 # this, to get the same measures on all platform, we only measure the | 84 # this, to get the same measures on all platform, we only measure the |
| 87 # foreground tab on all platforms. | 85 # foreground tab on all platforms. |
| 88 | 86 |
| 89 RecordTabLoadTime(tab.browser.foreground_tab) | 87 RecordTabLoadTime(tab.browser.foreground_tab) |
| 90 | 88 |
| 91 foreground_tab_stats = tab_load_times[0] | 89 foreground_tab_stats = tab_load_times[0] |
|
nednguyen
2015/04/03 22:07:08
If the TimeoutExceptions is thrown above, wouldn't
cylee1
2015/04/07 09:37:50
True, it was a legacy issue.
Did a tiny refactori
| |
| 92 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + | 90 foreground_tab_load_complete = ( |
| 93 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) | 91 foreground_tab_stats.load_end_ms - browser_main_entry_time_ms) |
| 94 results.AddValue(scalar.ScalarValue( | 92 results.AddValue(scalar.ScalarValue( |
| 95 results.current_page, 'foreground_tab_load_complete', 'ms', | 93 results.current_page, 'foreground_tab_load_complete', 'ms', |
| 96 foreground_tab_load_complete)) | 94 foreground_tab_load_complete)) |
| 97 if (foreground_tab_stats.request_start_ms > 0): | 95 if (foreground_tab_stats.request_start_ms > 0): |
| 98 results.AddValue(scalar.ScalarValue( | 96 results.AddValue(scalar.ScalarValue( |
| 99 results.current_page, 'foreground_tab_request_start', 'ms', | 97 results.current_page, 'foreground_tab_request_start', 'ms', |
| 100 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms)) | 98 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms)) |
| 101 | 99 |
| 102 def AddResults(self, tab, results): | 100 def AddResults(self, tab, results): |
| 103 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' | 101 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 117 | 115 |
| 118 results.AddValue(scalar.ScalarValue( | 116 results.AddValue(scalar.ScalarValue( |
| 119 results.current_page, display_name, 'ms', measured_time)) | 117 results.current_page, display_name, 'ms', measured_time)) |
| 120 | 118 |
| 121 # Get tab load times. | 119 # Get tab load times. |
| 122 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) | 120 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) |
| 123 if (browser_main_entry_time_ms is None): | 121 if (browser_main_entry_time_ms is None): |
| 124 print "Outdated Chrome version, browser main entry time not supported." | 122 print "Outdated Chrome version, browser main entry time not supported." |
| 125 return | 123 return |
| 126 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) | 124 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) |
| OLD | NEW |