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 from metrics import histogram_util | 9 from metrics import histogram_util |
10 | 10 |
(...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']) | 50 ['load_start_ms', 'load_duration_ms', 'request_start_ms']) |
51 | 51 |
52 def RecordTabLoadTime(t): | 52 def RecordTabLoadTime(t): |
53 try: | 53 try: |
54 t.WaitForDocumentReadyStateToBeComplete() | 54 t.WaitForDocumentReadyStateToBeComplete() |
55 | 55 |
56 result = t.EvaluateJavaScript( | 56 result = t.EvaluateJavaScript( |
57 'statsCollectionController.tabLoadTiming()') | 57 'statsCollectionController.tabLoadTiming()') |
58 result = json.loads(result) | 58 result = json.loads(result) |
59 | 59 |
60 if 'load_start_ms' not in result or 'load_duration_ms' not in result: | 60 if 'load_start_ms' not in result or 'load_duration_ms' not in result: |
61 raise Exception("Outdated Chrome version, " | 61 raise Exception("Outdated Chrome version, " |
62 "statsCollectionController.tabLoadTiming() not present") | 62 "statsCollectionController.tabLoadTiming() not present") |
63 if result['load_duration_ms'] is None: | 63 if result['load_duration_ms'] is None: |
64 tab_title = t.EvaluateJavaScript('document.title') | 64 tab_title = t.EvaluateJavaScript('document.title') |
65 print "Page: ", tab_title, " didn't finish loading." | 65 print "Page: ", tab_title, " didn't finish loading." |
66 return | 66 return |
67 | 67 |
68 perf_timing = t.EvaluateJavaScript('window.performance.timing') | |
69 if 'requestStart' not in perf_timing: | |
70 raise Exception("requestStart not in window performance timings") | |
pasko
2014/09/17 13:25:08
this would abort execution of all tests. Even if a
azarchs
2014/09/17 13:57:16
Done.
| |
71 | |
68 tab_load_times.append(TabLoadTime( | 72 tab_load_times.append(TabLoadTime( |
69 int(result['load_start_ms']), | 73 int(result['load_start_ms']), |
70 int(result['load_duration_ms']))) | 74 int(result['load_duration_ms']), |
75 int(perf_timing['requestStart']))) | |
71 except util.TimeoutException: | 76 except util.TimeoutException: |
72 # Low memory Android devices may not be able to load more than | 77 # Low memory Android devices may not be able to load more than |
73 # one tab at a time, so may timeout when the test attempts to | 78 # one tab at a time, so may timeout when the test attempts to |
74 # access a background tab. Ignore these tabs. | 79 # access a background tab. Ignore these tabs. |
75 logging.error("Tab timed out on JavaScript access") | 80 logging.error("Tab timed out on JavaScript access") |
76 | 81 |
77 # Only measure the foreground tab. We can't measure all tabs on Android | 82 # Only measure the foreground tab. We can't measure all tabs on Android |
78 # because on Android the data of the background tabs is loaded on demand, | 83 # because on Android the data of the background tabs is loaded on demand, |
79 # when the user switches to them, rather than during startup. In view of | 84 # when the user switches to them, rather than during startup. In view of |
80 # this, to get the same measures on all platform, we only measure the | 85 # this, to get the same measures on all platform, we only measure the |
81 # foreground tab on all platforms. | 86 # foreground tab on all platforms. |
82 | 87 |
83 RecordTabLoadTime(tab.browser.foreground_tab) | 88 RecordTabLoadTime(tab.browser.foreground_tab) |
84 | 89 |
85 foreground_tab_stats = tab_load_times[0] | 90 foreground_tab_stats = tab_load_times[0] |
86 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + | 91 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + |
87 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) | 92 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) |
88 results.AddValue(scalar.ScalarValue( | 93 results.AddValue(scalar.ScalarValue( |
89 results.current_page, 'foreground_tab_load_complete', 'ms', | 94 results.current_page, 'foreground_tab_load_complete', 'ms', |
90 foreground_tab_load_complete)) | 95 foreground_tab_load_complete)) |
96 if (foreground_tab_stats.request_start_ms > 0): | |
97 results.AddValue(scalar.ScalarValue( | |
98 results.current_page, 'foreground_tab_request_start', 'ms', | |
pasko
2014/09/17 13:25:08
why absolute value and not the relative one? Loadi
azarchs
2014/09/17 13:57:16
The value reported here is relative to the process
| |
99 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms)) | |
91 | 100 |
92 def AddResults(self, tab, results): | 101 def AddResults(self, tab, results): |
93 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' | 102 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' |
94 | 103 |
95 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): | 104 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): |
96 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) | 105 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) |
97 result = json.loads(result) | 106 result = json.loads(result) |
98 measured_time = 0 | 107 measured_time = 0 |
99 | 108 |
100 if 'sum' in result: | 109 if 'sum' in result: |
101 # For all the histograms logged here, there's a single entry so sum | 110 # For all the histograms logged here, there's a single entry so sum |
102 # is the exact value for that entry. | 111 # is the exact value for that entry. |
103 measured_time = result['sum'] | 112 measured_time = result['sum'] |
104 elif 'buckets' in result: | 113 elif 'buckets' in result: |
105 measured_time = \ | 114 measured_time = \ |
106 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 | 115 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 |
107 | 116 |
108 results.AddValue(scalar.ScalarValue( | 117 results.AddValue(scalar.ScalarValue( |
109 results.current_page, display_name, 'ms', measured_time)) | 118 results.current_page, display_name, 'ms', measured_time)) |
110 | 119 |
111 # Get tab load times. | 120 # Get tab load times. |
112 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) | 121 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) |
113 if (browser_main_entry_time_ms is None): | 122 if (browser_main_entry_time_ms is None): |
114 print "Outdated Chrome version, browser main entry time not supported." | 123 print "Outdated Chrome version, browser main entry time not supported." |
115 return | 124 return |
116 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) | 125 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) |
OLD | NEW |