| 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 |
| 11 from telemetry.core import util | 11 from telemetry.core import util |
| 12 from telemetry.value import scalar |
| 12 | 13 |
| 13 | 14 |
| 14 class StartupMetric(Metric): | 15 class StartupMetric(Metric): |
| 15 "A metric for browser startup time." | 16 "A metric for browser startup time." |
| 16 | 17 |
| 17 HISTOGRAMS_TO_RECORD = { | 18 HISTOGRAMS_TO_RECORD = { |
| 18 'messageloop_start_time' : | 19 'messageloop_start_time' : |
| 19 'Startup.BrowserMessageLoopStartTimeFromMainEntry', | 20 'Startup.BrowserMessageLoopStartTimeFromMainEntry', |
| 20 'window_display_time' : 'Startup.BrowserWindowDisplay', | 21 'window_display_time' : 'Startup.BrowserWindowDisplay', |
| 21 'open_tabs_time' : 'Startup.BrowserOpenTabs'} | 22 'open_tabs_time' : 'Startup.BrowserOpenTabs'} |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 # because on Android the data of the background tabs is loaded on demand, | 78 # because on Android the data of the background tabs is loaded on demand, |
| 78 # when the user switches to them, rather than during startup. In view of | 79 # when the user switches to them, rather than during startup. In view of |
| 79 # this, to get the same measures on all platform, we only measure the | 80 # this, to get the same measures on all platform, we only measure the |
| 80 # foreground tab on all platforms. | 81 # foreground tab on all platforms. |
| 81 | 82 |
| 82 RecordTabLoadTime(tab.browser.foreground_tab) | 83 RecordTabLoadTime(tab.browser.foreground_tab) |
| 83 | 84 |
| 84 foreground_tab_stats = tab_load_times[0] | 85 foreground_tab_stats = tab_load_times[0] |
| 85 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + | 86 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + |
| 86 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) | 87 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) |
| 87 results.Add( | 88 results.AddValue(scalar.ScalarValue( |
| 88 'foreground_tab_load_complete', 'ms', foreground_tab_load_complete) | 89 results.current_page, 'foreground_tab_load_complete', 'ms', |
| 90 foreground_tab_load_complete)) |
| 89 | 91 |
| 90 def AddResults(self, tab, results): | 92 def AddResults(self, tab, results): |
| 91 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' | 93 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' |
| 92 | 94 |
| 93 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): | 95 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): |
| 94 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) | 96 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) |
| 95 result = json.loads(result) | 97 result = json.loads(result) |
| 96 measured_time = 0 | 98 measured_time = 0 |
| 97 | 99 |
| 98 if 'sum' in result: | 100 if 'sum' in result: |
| 99 # 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 |
| 100 # is the exact value for that entry. | 102 # is the exact value for that entry. |
| 101 measured_time = result['sum'] | 103 measured_time = result['sum'] |
| 102 elif 'buckets' in result: | 104 elif 'buckets' in result: |
| 103 measured_time = \ | 105 measured_time = \ |
| 104 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 | 106 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 |
| 105 | 107 |
| 106 results.Add(display_name, 'ms', measured_time) | 108 results.AddValue(scalar.ScalarValue( |
| 109 results.current_page, display_name, 'ms', measured_time)) |
| 107 | 110 |
| 108 # Get tab load times. | 111 # Get tab load times. |
| 109 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) | 112 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) |
| 110 if (browser_main_entry_time_ms is None): | 113 if (browser_main_entry_time_ms is None): |
| 111 print "Outdated Chrome version, browser main entry time not supported." | 114 print "Outdated Chrome version, browser main entry time not supported." |
| 112 return | 115 return |
| 113 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) | 116 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) |
| OLD | NEW |