| 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 |
| 11 from telemetry.value import histogram_util | 11 from telemetry.value import histogram_util |
| 12 from telemetry.value import improvement_direction |
| 12 from telemetry.value import scalar | 13 from telemetry.value import scalar |
| 13 | 14 |
| 14 | 15 |
| 15 class StartupMetric(Metric): | 16 class StartupMetric(Metric): |
| 16 "A metric for browser startup time." | 17 "A metric for browser startup time." |
| 17 | 18 |
| 18 HISTOGRAMS_TO_RECORD = { | 19 HISTOGRAMS_TO_RECORD = { |
| 19 'messageloop_start_time' : | 20 'messageloop_start_time' : |
| 20 'Startup.BrowserMessageLoopStartTimeFromMainEntry', | 21 'Startup.BrowserMessageLoopStartTimeFromMainEntry', |
| 21 'window_display_time' : 'Startup.BrowserWindowDisplay', | 22 'window_display_time' : 'Startup.BrowserWindowDisplay', |
| (...skipping 64 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 | 87 # this, to get the same measures on all platform, we only measure the |
| 87 # foreground tab on all platforms. | 88 # foreground tab on all platforms. |
| 88 | 89 |
| 89 RecordTabLoadTime(tab.browser.foreground_tab) | 90 RecordTabLoadTime(tab.browser.foreground_tab) |
| 90 | 91 |
| 91 foreground_tab_stats = tab_load_times[0] | 92 foreground_tab_stats = tab_load_times[0] |
| 92 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + | 93 foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + |
| 93 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) | 94 foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) |
| 94 results.AddValue(scalar.ScalarValue( | 95 results.AddValue(scalar.ScalarValue( |
| 95 results.current_page, 'foreground_tab_load_complete', 'ms', | 96 results.current_page, 'foreground_tab_load_complete', 'ms', |
| 96 foreground_tab_load_complete)) | 97 foreground_tab_load_complete, |
| 98 improvement_direction=improvement_direction.DOWN)) |
| 97 if (foreground_tab_stats.request_start_ms > 0): | 99 if (foreground_tab_stats.request_start_ms > 0): |
| 98 results.AddValue(scalar.ScalarValue( | 100 results.AddValue(scalar.ScalarValue( |
| 99 results.current_page, 'foreground_tab_request_start', 'ms', | 101 results.current_page, 'foreground_tab_request_start', 'ms', |
| 100 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms)) | 102 foreground_tab_stats.request_start_ms - browser_main_entry_time_ms, |
| 103 improvement_direction=improvement_direction.DOWN)) |
| 101 | 104 |
| 102 def AddResults(self, tab, results): | 105 def AddResults(self, tab, results): |
| 103 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' | 106 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' |
| 104 | 107 |
| 105 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): | 108 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): |
| 106 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) | 109 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) |
| 107 result = json.loads(result) | 110 result = json.loads(result) |
| 108 measured_time = 0 | 111 measured_time = 0 |
| 109 | 112 |
| 110 if 'sum' in result: | 113 if 'sum' in result: |
| 111 # For all the histograms logged here, there's a single entry so sum | 114 # For all the histograms logged here, there's a single entry so sum |
| 112 # is the exact value for that entry. | 115 # is the exact value for that entry. |
| 113 measured_time = result['sum'] | 116 measured_time = result['sum'] |
| 114 elif 'buckets' in result: | 117 elif 'buckets' in result: |
| 115 measured_time = \ | 118 measured_time = \ |
| 116 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 | 119 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 |
| 117 | 120 |
| 118 results.AddValue(scalar.ScalarValue( | 121 results.AddValue(scalar.ScalarValue( |
| 119 results.current_page, display_name, 'ms', measured_time)) | 122 results.current_page, display_name, 'ms', measured_time, |
| 123 improvement_direction=improvement_direction.DOWN)) |
| 120 | 124 |
| 121 # Get tab load times. | 125 # Get tab load times. |
| 122 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) | 126 browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab) |
| 123 if (browser_main_entry_time_ms is None): | 127 if (browser_main_entry_time_ms is None): |
| 124 print "Outdated Chrome version, browser main entry time not supported." | 128 print "Outdated Chrome version, browser main entry time not supported." |
| 125 return | 129 return |
| 126 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) | 130 self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results) |
| OLD | NEW |