1c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch# Copyright 2013 The Chromium Authors. All rights reserved. 2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be 3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# found in the LICENSE file. 4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)from metrics import startup_metric 66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)from telemetry.page import page_test 7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class Startup(page_test.PageTest): 10c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch """Performs a measurement of Chromium's startup performance. 11c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 12c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch This test must be invoked with either --warm or --cold on the command line. A 13c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch cold start means none of the Chromium files are in the disk cache. A warm 14c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch start assumes the OS has already cached much of Chromium's content. For warm 15c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch tests, you should repeat the page set to ensure it's cached. 16c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch """ 179ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) def __init__(self, action_name_to_run = ''): 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) super(Startup, self).__init__(needs_browser_restart_after_each_page=True, 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) action_name_to_run=action_name_to_run) 21c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) @classmethod 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) def AddCommandLineArgs(cls, parser): 24c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch parser.add_option('--cold', action='store_true', 25c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch help='Clear the OS disk cache before performing the test') 26c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch parser.add_option('--warm', action='store_true', 27c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch help='Start up with everything already cached') 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) @classmethod 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) def ProcessCommandLineArgs(cls, parser, args): 31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) cls._cold = args.cold 32c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch # TODO: Once the bots start running benchmarks, enforce that either --warm 33c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch # or --cold is explicitly specified. 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) # if args.warm == args.cold: 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) # parser.error('You must specify either --warm or --cold') 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) def CustomizeBrowserOptions(self, options): 38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if self._cold: 39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) options.clear_sytem_cache_for_browser_and_profile_on_start = True 40c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch else: 41c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch self.discard_first_result = True 42c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) options.AppendExtraBrowserArgs([ 44d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) '--enable-stats-collection-bindings' 4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) ]) 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) def RunNavigateSteps(self, page, tab): 48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) # Overriden so that no page navigation occurs - startup to the NTP. 49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) pass 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) def ValidateAndMeasurePage(self, page, tab, results): 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) startup_metric.StartupMetric().AddResults(tab, results) 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class StartWithUrl(Startup): 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """Performs a measurement of Chromium's performance starting with a URL. 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) This test must be invoked with either --warm or --cold on the command line. A 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cold start means none of the Chromium files are in the disk cache. A warm 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) start assumes the OS has already cached much of Chromium's content. For warm 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) tests, you should repeat the page set to ensure it's cached. 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) The startup URL is taken from the page set's startup_url. This 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) allows the testing of multiple different URLs in a single benchmark. 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) """ 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) def __init__(self): 6823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) super(StartWithUrl, self).__init__(action_name_to_run='RunNavigateSteps') 69