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
3 # found in the LICENSE file.
7 from telemetry
.page
import page_measurement
9 class Startup(page_measurement
.PageMeasurement
):
10 """Performs a measurement of Chromium's startup performance.
12 This test must be invoked with either --warm or --cold on the command line. A
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.
18 HISTOGRAMS_TO_RECORD
= {
19 'messageloop_start_time' :
20 'Startup.BrowserMessageLoopStartTimeFromMainEntry',
21 'window_display_time' : 'Startup.BrowserWindowDisplay',
22 'open_tabs_time' : 'Startup.BrowserOpenTabs'}
25 super(Startup
, self
).__init
__(needs_browser_restart_after_each_run
=True)
27 def AddCommandLineOptions(self
, parser
):
28 parser
.add_option('--cold', action
='store_true',
29 help='Clear the OS disk cache before performing the test')
30 parser
.add_option('--warm', action
='store_true',
31 help='Start up with everything already cached')
33 def CustomizeBrowserOptions(self
, options
):
34 # TODO: Once the bots start running benchmarks, enforce that either --warm
35 # or --cold is explicitly specified.
36 # assert options.warm != options.cold, \
37 # "You must specify either --warm or --cold"
39 browser_options
= options
.browser_options
40 browser_options
.clear_sytem_cache_for_browser_and_profile_on_start
= True
42 self
.discard_first_result
= True
44 options
.AppendExtraBrowserArgs([
45 '--enable-stats-collection-bindings'
48 def MeasurePage(self
, page
, tab
, results
):
49 get_histogram_js
= 'statsCollectionController.getBrowserHistogram("%s")'
51 for display_name
, histogram_name
in self
.HISTOGRAMS_TO_RECORD
.iteritems():
52 result
= tab
.EvaluateJavaScript(get_histogram_js
% histogram_name
)
53 result
= json
.loads(result
)
57 # For all the histograms logged here, there's a single entry so sum
58 # is the exact value for that entry.
59 measured_time
= result
['sum']
60 elif 'buckets' in result
:
62 (result
['buckets'][0]['high'] + result
['buckets'][0]['low']) / 2
64 results
.Add(display_name
, 'ms', measured_time
)