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 23 matching lines...) Expand all Loading... | |
34 'Startup.BrowserMainEntryTimeAbsoluteHighWord', | 34 'Startup.BrowserMainEntryTimeAbsoluteHighWord', |
35 tab) | 35 tab) |
36 low_bytes = histogram_util.GetHistogramSum( | 36 low_bytes = histogram_util.GetHistogramSum( |
37 histogram_type, | 37 histogram_type, |
38 'Startup.BrowserMainEntryTimeAbsoluteLowWord', | 38 'Startup.BrowserMainEntryTimeAbsoluteLowWord', |
39 tab) | 39 tab) |
40 if high_bytes == 0 and low_bytes == 0: | 40 if high_bytes == 0 and low_bytes == 0: |
41 return None | 41 return None |
42 return (int(high_bytes) << 32) | (int(low_bytes) << 1) | 42 return (int(high_bytes) << 32) | (int(low_bytes) << 1) |
43 | 43 |
44 # pylint: disable=W0101 | 44 # pylint: disable=W0101 |
jeremy
2014/02/13 13:35:26
nit:Why change the indent here?
aberent
2014/02/13 15:59:30
Accidental. Will check whether we still need this
| |
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', 'is_foreground_tab']) | 50 ['load_start_ms', 'load_duration_ms', 'is_foreground_tab']) |
51 num_open_tabs = len(tab.browser.tabs) | 51 |
52 for i in xrange(num_open_tabs): | 52 def RecordTabLoadTime(t): |
53 try: | 53 try: |
54 t = tab.browser.tabs[i] | |
55 t.WaitForDocumentReadyStateToBeComplete() | 54 t.WaitForDocumentReadyStateToBeComplete() |
56 | 55 |
57 result = t.EvaluateJavaScript( | 56 result = t.EvaluateJavaScript( |
58 'statsCollectionController.tabLoadTiming()') | 57 'statsCollectionController.tabLoadTiming()') |
59 result = json.loads(result) | 58 result = json.loads(result) |
60 | 59 |
61 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: |
62 raise Exception("Outdated Chrome version, " | 61 raise Exception("Outdated Chrome version, " |
63 "statsCollectionController.tabLoadTiming() not present") | 62 "statsCollectionController.tabLoadTiming() not present") |
64 return | |
65 if result['load_duration_ms'] is None: | 63 if result['load_duration_ms'] is None: |
66 tab_title = t.EvaluateJavaScript('document.title') | 64 tab_title = t.EvaluateJavaScript('document.title') |
67 print "Page: ", tab_title, " didn't finish loading." | 65 print "Page: ", tab_title, " didn't finish loading." |
68 continue | 66 return |
69 | 67 |
70 is_foreground_tab = t.EvaluateJavaScript('!document.hidden') | 68 is_foreground_tab = t.EvaluateJavaScript('!document.hidden') |
jeremy
2014/02/13 13:35:26
You can remove this since we don't use it
aberent
2014/02/13 15:59:30
Done.
| |
71 tab_load_times.append(TabLoadTime( | 69 tab_load_times.append(TabLoadTime( |
72 int(result['load_start_ms']), | 70 int(result['load_start_ms']), |
73 int(result['load_duration_ms']), | 71 int(result['load_duration_ms']), |
74 is_foreground_tab)) | 72 is_foreground_tab)) |
75 except util.TimeoutException: | 73 except util.TimeoutException: |
76 # Low memory Android devices may not be able to load more than | 74 # Low memory Android devices may not be able to load more than |
77 # one tab at a time, so may timeout when the test attempts to | 75 # one tab at a time, so may timeout when the test attempts to |
78 # access a background tab. Ignore these tabs. | 76 # access a background tab. Ignore these tabs. |
79 logging.error("Tab number: %d timed out on JavaScript access" % i) | 77 logging.error("Tab timed out on JavaScript access") |
80 continue | |
81 | 78 |
82 # Postprocess results | 79 # Only measure the foreground tab. We can't measure all tabs on Android |
83 load_complete_times = ( | 80 # because on Android the data of the background tabs is loaded on demand, |
84 [t.load_start_ms + t.load_duration_ms for t in tab_load_times]) | 81 # when the user switches to them, rather than during startup. In view of |
85 load_complete_times.sort() | 82 # this, to get the same measures on all platform, we only measure the |
83 # foreground tab on all platforms. | |
84 RecordTabLoadTime(tab.browser.tabs[0]) | |
86 | 85 |
87 if 'android' in tab.browser.browser_type: | 86 foreground_tab_stats = tab_load_times[0] |
88 # document.hidden is broken on Android - crbug.com/322544. | |
89 foreground_tab_stats = [tab_load_times[0]] | |
90 else: | |
91 foreground_tab_stats = ( | |
92 [t for t in tab_load_times if t.is_foreground_tab == True]) | |
93 if (len(foreground_tab_stats) != 1): | |
94 raise Exception ("More than one foreground tab? ", foreground_tab_stats) | |
95 foreground_tab_stats = foreground_tab_stats[0] | |
96 | |
97 # Report load stats. | |
98 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + | 87 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + |
99 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) | 88 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) |
100 | |
101 results.Add( | 89 results.Add( |
102 'foreground_tab_load_complete', 'ms', foreground_tab_load_complete) | 90 'foreground_tab_load_complete', 'ms', foreground_tab_load_complete) |
103 | 91 |
104 if num_open_tabs > 1: | |
105 last_tab_load_complete = ( | |
106 load_complete_times[-1] - browser_main_entry_time_ms) | |
107 results.Add('last_tab_load_complete', 'ms', last_tab_load_complete) | |
108 | |
109 def AddResults(self, tab, results): | 92 def AddResults(self, tab, results): |
110 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' | 93 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' |
111 | 94 |
112 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): | 95 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): |
113 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) | 96 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) |
114 result = json.loads(result) | 97 result = json.loads(result) |
115 measured_time = 0 | 98 measured_time = 0 |
116 | 99 |
117 if 'sum' in result: | 100 if 'sum' in result: |
118 # For all the histograms logged here, there's a single entry so sum | 101 # For all the histograms logged here, there's a single entry so sum |
119 # is the exact value for that entry. | 102 # is the exact value for that entry. |
120 measured_time = result['sum'] | 103 measured_time = result['sum'] |
121 elif 'buckets' in result: | 104 elif 'buckets' in result: |
122 measured_time = \ | 105 measured_time = \ |
123 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 | 106 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 |
124 | 107 |
125 results.Add(display_name, 'ms', measured_time) | 108 results.Add(display_name, 'ms', measured_time) |
126 | 109 |
127 # Get tab load times. | 110 # Get tab load times. |
128 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) | 111 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) |
129 if (browser_main_entry_time_ms is None): | 112 if (browser_main_entry_time_ms is None): |
130 print "Outdated Chrome version, browser main entry time not supported." | 113 print "Outdated Chrome version, browser main entry time not supported." |
131 return | 114 return |
132 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) | 115 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) |
OLD | NEW |