Home | History | Annotate | Download | only in perf
      1 #!/usr/bin/env python
      2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 import imp
      7 import os
      8 import sys
      9 import urllib2
     10 
     11 
     12 BASE_URL = 'http://src.chromium.org/chrome/trunk/'
     13 DEPS_FILE = 'bootstrap_deps'
     14 
     15 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
     16 # Directory containing src/ in a Chromium checkout.
     17 CHECKOUT_BASE_PATH = os.path.join(SCRIPT_PATH, os.pardir, os.pardir, os.pardir)
     18 # Directory in which to save bootstrap files.
     19 BOOTSTRAP_BASE_PATH = os.path.join(SCRIPT_PATH, 'support', 'bootstrap_files')
     20 
     21 PERF_DIR = os.path.join('src', 'tools', 'perf')
     22 TELEMETRY_DIR = os.path.join('src', 'tools', 'telemetry')
     23 TELEMETRY_TOOLS_DIR = os.path.join('src', 'tools', 'telemetry_tools')
     24 
     25 
     26 def _GetBasePath():
     27   """Find the location of our Chromium or bootstrap checkout.
     28 
     29   It tries to import Telemetry.  If the import succeeds,
     30   we assume that's the correct location.
     31 
     32   Returns:
     33     The path containing the src/ directory, or None if no checkout is found.
     34   """
     35   module_name = 'telemetry'
     36   module_path = TELEMETRY_DIR
     37 
     38   try:
     39     paths = [os.path.join(CHECKOUT_BASE_PATH, module_path)]
     40     imp.find_module(module_name, paths)
     41     return CHECKOUT_BASE_PATH
     42   except ImportError:
     43     pass
     44 
     45   try:
     46     paths = [os.path.join(BOOTSTRAP_BASE_PATH, module_path)]
     47     imp.find_module(module_name, paths)
     48     return BOOTSTRAP_BASE_PATH
     49   except ImportError:
     50     pass
     51 
     52   return None
     53 
     54 
     55 def _Bootstrap(bootstrap_deps_url):
     56   """Grab all the deps listed in the file at bootstrap_deps_url."""
     57   bootstrap_txt = urllib2.urlopen(
     58       BASE_URL + 'src/tools/telemetry_tools/telemetry_bootstrap.py').read()
     59   bootstrap = imp.new_module('bootstrap')
     60   exec bootstrap_txt in bootstrap.__dict__
     61   bootstrap.DownloadDeps(BOOTSTRAP_BASE_PATH, bootstrap_deps_url)
     62 
     63 
     64 def ListBootstrapDeps(base_path):
     65   """List the deps required for telemetry."""
     66   sys.path.append(os.path.join(base_path, TELEMETRY_TOOLS_DIR))
     67   import telemetry_bootstrap
     68 
     69   deps_file = os.path.join(base_path, PERF_DIR, DEPS_FILE)
     70   return telemetry_bootstrap.ListAllDepsPaths(deps_file)
     71 
     72 
     73 def Main():
     74   if not _GetBasePath():
     75     _Bootstrap(BASE_URL + 'src/tools/perf/' + DEPS_FILE)
     76 
     77   new_base_path = _GetBasePath()
     78   new_perf_path = os.path.join(new_base_path, PERF_DIR)
     79   new_telemetry_path = os.path.join(new_base_path, TELEMETRY_DIR)
     80 
     81   if '--print-bootstrap-deps' in sys.argv:
     82     print ListBootstrapDeps(new_base_path)
     83     return 0
     84 
     85   sys.path.append(new_perf_path)
     86   import page_sets
     87   page_set_filenames = page_sets.GetAllPageSetFilenames()
     88 
     89   old_benchmark_names = {
     90     "image_decoding_benchmark": "image_decoding",
     91     "image_decoding_measurement": "image_decoding",
     92     "loading_benchmark": "loading",
     93     "loading_measurement": "loading",
     94     "media_measurement": "media",
     95     "memory_benchmark": "memory",
     96     "memory_measurement": "memory",
     97     "rasterize_and_record_benchmark": "rasterize_and_record",
     98     "rasterize_and_record_measurement": "rasterize_and_record",
     99     "robohornetpro": "robohornet_pro",
    100     "scrolling_benchmark": "smoothness",
    101     "smoothness_benchmark": "smoothness",
    102     "smoothness_measurement": "smoothness",
    103     "startup_benchmark": "startup_warm_blank_page",
    104     "startup_measurement": "startup",
    105     "tab_switching_measurement": "tab_switching",
    106   }
    107 
    108   sys.path.append(new_telemetry_path)
    109   from telemetry.page import page_measurement_runner
    110   # There are bots that are hard-coded to run some specific named tests.
    111   # Convert these to the current naming conventions by overriding them
    112   # in the runner.
    113   class MeasurementRunner(page_measurement_runner.PageMeasurementRunner):
    114     def GetModernizedTestName(self, arg):
    115       if arg not in old_benchmark_names:
    116         return arg
    117       sys.stderr.write(
    118         'An old name %s was given. Please use %s in the future.\n' % (
    119           arg,
    120           old_benchmark_names.get(arg)))
    121       return old_benchmark_names[arg]
    122 
    123   runner = MeasurementRunner()
    124   return runner.Run(new_perf_path, page_set_filenames)
    125 
    126 
    127 if __name__ == '__main__':
    128   sys.exit(Main())
    129