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 class Startup(page_measurement.PageMeasurement): |
| 10 """Performs a measurement of Chromium's startup performance. |
9 | 11 |
10 class StartupWarm(page_measurement.PageMeasurement): | 12 This test must be invoked with either --warm or --cold on the command line. A |
11 """Test how long Chrome takes to load when warm.""" | 13 cold start means none of the Chromium files are in the disk cache. A warm |
| 14 start assumes the OS has already cached much of Chromium's content. For warm |
| 15 tests, you should repeat the page set to ensure it's cached. |
| 16 """ |
| 17 |
12 HISTOGRAMS_TO_RECORD = { | 18 HISTOGRAMS_TO_RECORD = { |
13 'messageloop_start_time' : | 19 'messageloop_start_time' : |
14 'Startup.BrowserMessageLoopStartTimeFromMainEntry', | 20 'Startup.BrowserMessageLoopStartTimeFromMainEntry', |
15 'window_display_time' : 'Startup.BrowserWindowDisplay', | 21 'window_display_time' : 'Startup.BrowserWindowDisplay', |
16 'open_tabs_time' : 'Startup.BrowserOpenTabs'} | 22 'open_tabs_time' : 'Startup.BrowserOpenTabs'} |
17 | 23 |
18 def __init__(self): | 24 def __init__(self): |
19 super(StartupWarm, self).__init__(needs_browser_restart_after_each_run=True, | 25 super(Startup, self).__init__(needs_browser_restart_after_each_run=True) |
20 discard_first_result=True) | 26 self._cold = False |
| 27 |
| 28 def AddCommandLineOptions(self, parser): |
| 29 parser.add_option('--cold', action='store_true', |
| 30 help='Clear the OS disk cache before performing the test') |
| 31 parser.add_option('--warm', action='store_true', |
| 32 help='Start up with everything already cached') |
21 | 33 |
22 def CustomizeBrowserOptions(self, options): | 34 def CustomizeBrowserOptions(self, options): |
| 35 # TODO: Once the bots start running benchmarks, enforce that either --warm |
| 36 # or --cold is explicitly specified. |
| 37 # assert options.warm != options.cold, \ |
| 38 # "You must specify either --warm or --cold" |
| 39 self._cold = options.cold |
| 40 |
| 41 if self._cold: |
| 42 options.clear_sytem_cache_for_browser_and_profile_on_start = True |
| 43 else: |
| 44 self.discard_first_result = True |
| 45 |
23 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') | 46 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') |
24 | 47 |
25 # Old commandline flags used for reference builds. | 48 # Old commandline flags used for reference builds. |
26 options.AppendExtraBrowserArg('--dom-automation') | 49 options.AppendExtraBrowserArg('--dom-automation') |
27 options.AppendExtraBrowserArg( | 50 options.AppendExtraBrowserArg( |
28 '--reduce-security-for-dom-automation-tests') | 51 '--reduce-security-for-dom-automation-tests') |
29 | 52 |
30 def MeasurePage(self, page, tab, results): | 53 def MeasurePage(self, page, tab, results): |
31 # TODO(jeremy): Remove references to | 54 # TODO(jeremy): Remove references to |
32 # domAutomationController.getBrowserHistogram when we update the reference | 55 # domAutomationController.getBrowserHistogram when we update the reference |
33 # builds. | 56 # builds. |
34 get_histogram_js = ('(window.statsCollectionController ?' | 57 get_histogram_js = ('(window.statsCollectionController ?' |
35 'statsCollectionController :' | 58 'statsCollectionController :' |
36 'domAutomationController).getBrowserHistogram("%s")') | 59 'domAutomationController).getBrowserHistogram("%s")') |
37 | 60 |
38 | |
39 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): | 61 for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems(): |
40 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) | 62 result = tab.EvaluateJavaScript(get_histogram_js % histogram_name) |
41 result = json.loads(result) | 63 result = json.loads(result) |
42 measured_time = 0 | 64 measured_time = 0 |
43 | 65 |
44 if 'sum' in result: | 66 if 'sum' in result: |
45 # For all the histograms logged here, there's a single entry so sum | 67 # For all the histograms logged here, there's a single entry so sum |
46 # is the exact value for that entry. | 68 # is the exact value for that entry. |
47 measured_time = result['sum'] | 69 measured_time = result['sum'] |
48 elif 'buckets' in result: | 70 elif 'buckets' in result: |
49 measured_time = \ | 71 measured_time = \ |
50 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 | 72 (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2 |
51 | 73 |
52 results.Add(display_name, 'ms', measured_time) | 74 results.Add(display_name, 'ms', measured_time) |
OLD | NEW |