Home | History | Annotate | Download | only in measurements
      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.
      4 
      5 import json
      6 
      7 from telemetry.page import page_measurement
      8 
      9 class Startup(page_measurement.PageMeasurement):
     10   """Performs a measurement of Chromium's startup performance.
     11 
     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.
     16   """
     17 
     18   HISTOGRAMS_TO_RECORD = {
     19     'messageloop_start_time' :
     20         'Startup.BrowserMessageLoopStartTimeFromMainEntry',
     21     'window_display_time' : 'Startup.BrowserWindowDisplay',
     22     'open_tabs_time' : 'Startup.BrowserOpenTabs'}
     23 
     24   def __init__(self):
     25     super(Startup, self).__init__(needs_browser_restart_after_each_run=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')
     33 
     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 
     46     options.AppendExtraBrowserArg('--enable-stats-collection-bindings')
     47 
     48     # Old commandline flags used for reference builds.
     49     options.AppendExtraBrowserArg('--dom-automation')
     50     options.AppendExtraBrowserArg(
     51           '--reduce-security-for-dom-automation-tests')
     52 
     53   def MeasurePage(self, page, tab, results):
     54     # TODO(jeremy): Remove references to
     55     # domAutomationController.getBrowserHistogram when we update the reference
     56     # builds.
     57     get_histogram_js = ('(window.statsCollectionController ?'
     58         'statsCollectionController :'
     59         'domAutomationController).getBrowserHistogram("%s")')
     60 
     61     for display_name, histogram_name in self.HISTOGRAMS_TO_RECORD.iteritems():
     62       result = tab.EvaluateJavaScript(get_histogram_js % histogram_name)
     63       result = json.loads(result)
     64       measured_time = 0
     65 
     66       if 'sum' in result:
     67         # For all the histograms logged here, there's a single entry so sum
     68         # is the exact value for that entry.
     69         measured_time = result['sum']
     70       elif 'buckets' in result:
     71         measured_time = \
     72             (result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2
     73 
     74       results.Add(display_name, 'ms', measured_time)
     75