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 metrics import Metric | 8 from metrics import Metric |
9 | 9 |
10 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
(...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']) |
nednguyen
2015/03/30 21:25:41
What is this renaming about?
cylee1
2015/03/31 10:52:27
load_start_ms + load_duration_ms = load_end_ms
it'
| |
51 | 51 |
52 def RecordTabLoadTime(t): | 52 def RecordTabLoadTime(t): |
53 try: | 53 try: |
54 t.WaitForDocumentReadyStateToBeComplete() | 54 t.WaitForJavaScriptExpression( |
55 | 55 'window.performance.timing["loadEventEnd"] > 0', 10) |
56 result = t.EvaluateJavaScript( | |
57 'statsCollectionController.tabLoadTiming()') | |
58 result = json.loads(result) | |
59 | |
nednguyen
2015/03/30 21:25:41
What are these change about?
cylee1
2015/03/31 10:52:27
Explained in mail.
| |
60 if 'load_start_ms' not in result or 'load_duration_ms' not in result: | |
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 | 56 |
68 perf_timing = t.EvaluateJavaScript('window.performance.timing') | 57 perf_timing = t.EvaluateJavaScript('window.performance.timing') |
69 if 'requestStart' not in perf_timing: | 58 if 'requestStart' not in perf_timing: |
70 perf_timing['requestStart'] = 0 # Exclude from benchmark results | 59 perf_timing['requestStart'] = 0 # Exclude from benchmark results |
71 print 'requestStart is not supported by this browser' | 60 print 'requestStart is not supported by this browser' |
72 | 61 |
73 tab_load_times.append(TabLoadTime( | 62 tab_load_times.append(TabLoadTime( |
74 int(result['load_start_ms']), | 63 int(perf_timing['requestStart']), |
75 int(result['load_duration_ms']), | 64 int(perf_timing['loadEventEnd']))) |
76 int(perf_timing['requestStart']))) | |
77 except exceptions.TimeoutException: | 65 except exceptions.TimeoutException: |
78 # Low memory Android devices may not be able to load more than | 66 # 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 | 67 # one tab at a time, so may timeout when the test attempts to |
80 # access a background tab. Ignore these tabs. | 68 # access a background tab. Ignore these tabs. |
81 logging.error("Tab timed out on JavaScript access") | 69 logging.error("Tab timed out on JavaScript access") |
82 | 70 |
83 # Only measure the foreground tab. We can't measure all tabs on Android | 71 # 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, | 72 # 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 | 73 # 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 | 74 # this, to get the same measures on all platform, we only measure the |
87 # foreground tab on all platforms. | 75 # foreground tab on all platforms. |
88 | 76 |
89 RecordTabLoadTime(tab.browser.foreground_tab) | 77 RecordTabLoadTime(tab.browser.foreground_tab) |
90 | 78 |
91 foreground_tab_stats = tab_load_times[0] | 79 foreground_tab_stats = tab_load_times[0] |
92 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + | 80 foreground_tab_load_complete = ( |
93 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) | 81 foreground_tab_stats.load_end_ms - browser_main_entry_time_ms) |
94 results.AddValue(scalar.ScalarValue( | 82 results.AddValue(scalar.ScalarValue( |
95 results.current_page, 'foreground_tab_load_complete', 'ms', | 83 results.current_page, 'foreground_tab_load_complete', 'ms', |
96 foreground_tab_load_complete)) | 84 foreground_tab_load_complete)) |
97 if (foreground_tab_stats.request_start_ms > 0): | 85 if (foreground_tab_stats.request_start_ms > 0): |
98 results.AddValue(scalar.ScalarValue( | 86 results.AddValue(scalar.ScalarValue( |
99 results.current_page, 'foreground_tab_request_start', 'ms', | 87 results.current_page, 'foreground_tab_request_start', 'ms', |
100 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms)) | 88 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms)) |
101 | 89 |
102 def AddResults(self, tab, results): | 90 def AddResults(self, tab, results): |
103 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' | 91 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' |
(...skipping 13 matching lines...) Expand all Loading... | |
117 | 105 |
118 results.AddValue(scalar.ScalarValue( | 106 results.AddValue(scalar.ScalarValue( |
119 results.current_page, display_name, 'ms', measured_time)) | 107 results.current_page, display_name, 'ms', measured_time)) |
120 | 108 |
121 # Get tab load times. | 109 # Get tab load times. |
122 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) | 110 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) |
123 if (browser_main_entry_time_ms is None): | 111 if (browser_main_entry_time_ms is None): |
124 print "Outdated Chrome version, browser main entry time not supported." | 112 print "Outdated Chrome version, browser main entry time not supported." |
125 return | 113 return |
126 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) | 114 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) |
OLD | NEW |