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 util | 10 from telemetry.core import util |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 # this, to get the same measures on all platform, we only measure the | 86 # this, to get the same measures on all platform, we only measure the |
87 # foreground tab on all platforms. | 87 # foreground tab on all platforms. |
88 | 88 |
89 RecordTabLoadTime(tab.browser.foreground_tab) | 89 RecordTabLoadTime(tab.browser.foreground_tab) |
90 | 90 |
91 foreground_tab_stats = tab_load_times[0] | 91 foreground_tab_stats = tab_load_times[0] |
92 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + | 92 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + |
93 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) | 93 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) |
94 results.AddValue(scalar.ScalarValue( | 94 results.AddValue(scalar.ScalarValue( |
95 results.current_page, 'foreground_tab_load_complete', 'ms', | 95 results.current_page, 'foreground_tab_load_complete', 'ms', |
96 foreground_tab_load_complete)) | 96 foreground_tab_load_complete, higher_is_better=False)) |
97 if (foreground_tab_stats.request_start_ms > 0): | 97 if (foreground_tab_stats.request_start_ms > 0): |
98 results.AddValue(scalar.ScalarValue( | 98 results.AddValue(scalar.ScalarValue( |
99 results.current_page, 'foreground_tab_request_start', 'ms', | 99 results.current_page, 'foreground_tab_request_start', 'ms', |
100 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms)) | 100 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms, |
| 101 higher_is_better=False)) |
101 | 102 |
102 def AddResults(self, tab, results): | 103 def AddResults(self, tab, results): |
103 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' | 104 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' |
104 | 105 |
105 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): | 106 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): |
106 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) | 107 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) |
107 result = json.loads(result) | 108 result = json.loads(result) |
108 measured_time = 0 | 109 measured_time = 0 |
109 | 110 |
110 if 'sum' in result: | 111 if 'sum' in result: |
111 # For all the histograms logged here, there's a single entry so sum | 112 # For all the histograms logged here, there's a single entry so sum |
112 # is the exact value for that entry. | 113 # is the exact value for that entry. |
113 measured_time = result['sum'] | 114 measured_time = result['sum'] |
114 elif 'buckets' in result: | 115 elif 'buckets' in result: |
115 measured_time = \ | 116 measured_time = \ |
116 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 | 117 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 |
117 | 118 |
118 results.AddValue(scalar.ScalarValue( | 119 results.AddValue(scalar.ScalarValue( |
119 results.current_page, display_name, 'ms', measured_time)) | 120 results.current_page, display_name, 'ms', measured_time, |
| 121 higher_is_better=False)) |
120 | 122 |
121 # Get tab load times. | 123 # Get tab load times. |
122 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) | 124 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) |
123 if (browser_main_entry_time_ms is None): | 125 if (browser_main_entry_time_ms is None): |
124 print "Outdated Chrome version, browser main entry time not supported." | 126 print "Outdated Chrome version, browser main entry time not supported." |
125 return | 127 return |
126 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) | 128 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) |
OLD | NEW |