OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 | 4 |
5 import json | 5 import json |
6 | 6 |
7 from telemetry.page import page_measurement | 7 from telemetry.page import page_measurement |
8 | 8 |
9 # Test how long Chrome takes to load when warm. | 9 # Test how long Chrome takes to load when warm. |
10 class PerfWarm(page_measurement.PageMeasurement): | 10 class PerfWarm(page_measurement.PageMeasurement): |
11 HISTOGRAMS_TO_RECORD = { | 11 HISTOGRAMS_TO_RECORD = { |
12 'messageloop_start_time' : | 12 'messageloop_start_time' : |
13 'Startup.BrowserMessageLoopStartTimeFromMainEntry', | 13 'Startup.BrowserMessageLoopStartTimeFromMainEntry', |
14 'window_display_time' : 'Startup.BrowserWindowDisplay', | 14 'window_display_time' : 'Startup.BrowserWindowDisplay', |
15 'open_tabs_time' : 'Startup.BrowserOpenTabs'} | 15 'open_tabs_time' : 'Startup.BrowserOpenTabs'} |
16 | 16 |
17 def __init__(self): | 17 def __init__(self): |
18 super(PerfWarm, self).__init__(needs_browser_restart_after_each_run=True, | 18 super(PerfWarm, self).__init__(needs_browser_restart_after_each_run=True, |
19 discard_first_result=True) | 19 discard_first_result=True) |
20 | 20 |
21 def CustomizeBrowserOptions(self, options): | 21 def CustomizeBrowserOptions(self, options): |
22 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') | 22 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') |
23 options.AppendExtraBrowserArg( | |
24 '--reduce-security-for-stats-collection-tests') | |
25 | 23 |
26 # Old commandline flags used for reference builds. | 24 # Old commandline flags used for reference builds. |
27 options.AppendExtraBrowserArg('--dom-automation') | 25 options.AppendExtraBrowserArg('--dom-automation') |
28 options.AppendExtraBrowserArg( | 26 options.AppendExtraBrowserArg( |
29 '--reduce-security-for-dom-automation-tests') | 27 '--reduce-security-for-dom-automation-tests') |
30 | 28 |
31 def MeasurePage(self, page, tab, results): | 29 def MeasurePage(self, page, tab, results): |
32 # TODO(jeremy): Remove references to | 30 # TODO(jeremy): Remove references to |
33 # domAutomationController.getBrowserHistogram when we update the reference | 31 # domAutomationController.getBrowserHistogram when we update the reference |
34 # builds. | 32 # builds. |
35 get_histogram_js = ('(window.statsCollectionController ?' | 33 get_histogram_js = ('(window.statsCollectionController ?' |
36 'statsCollectionController :' | 34 'statsCollectionController :' |
37 'domAutomationController).getBrowserHistogram("%s")') | 35 'domAutomationController).getBrowserHistogram("%s")') |
38 | 36 |
39 | 37 |
40 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): | 38 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): |
41 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) | 39 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) |
42 result = json.loads(result) | 40 result = json.loads(result) |
43 measured_time = 0 | 41 measured_time = 0 |
44 | 42 |
45 if 'sum' in result: | 43 if 'sum' in result: |
46 # For all the histograms logged here, there's a single entry so sum | 44 # For all the histograms logged here, there's a single entry so sum |
47 # is the exact value for that entry. | 45 # is the exact value for that entry. |
48 measured_time = result['sum'] | 46 measured_time = result['sum'] |
49 elif 'buckets' in result: | 47 elif 'buckets' in result: |
50 measured_time = \ | 48 measured_time = \ |
51 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 | 49 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 |
52 | 50 |
53 results.Add(display_name, 'ms', measured_time) | 51 results.Add(display_name, 'ms', measured_time) |
OLD | NEW |