summaryrefslogtreecommitdiffstats
path: root/tools/perf/run_measurement
blob: d2f9e92cff9e2e0c67891d9b4f824238c69ebd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import imp
import os
import sys
import urllib2


BASE_URL = 'http://src.chromium.org/chrome/trunk/'
DEPS_FILE = 'bootstrap_deps'

SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
# Directory containing src/ in a Chromium checkout.
CHECKOUT_BASE_PATH = os.path.join(SCRIPT_PATH, os.pardir, os.pardir, os.pardir)
# Directory in which to save bootstrap files.
BOOTSTRAP_BASE_PATH = os.path.join(SCRIPT_PATH, 'support', 'bootstrap_files')

CROS_DIR = os.path.join('src', 'tools', 'cros')
PERF_DIR = os.path.join('src', 'tools', 'perf')
TELEMETRY_DIR = os.path.join('src', 'tools', 'telemetry')
TELEMETRY_TOOLS_DIR = os.path.join('src', 'tools', 'telemetry_tools')


def _GetBasePath():
  """Find the location of our Chromium or bootstrap checkout.

  It tries to import Telemetry.  If the import succeeds,
  we assume that's the correct location.

  Returns:
    The path containing the src/ directory, or None if no checkout is found.
  """
  module_name = 'telemetry'
  module_path = TELEMETRY_DIR

  try:
    paths = [os.path.join(CHECKOUT_BASE_PATH, module_path)]
    imp.find_module(module_name, paths)
    return CHECKOUT_BASE_PATH
  except ImportError:
    pass

  try:
    paths = [os.path.join(BOOTSTRAP_BASE_PATH, module_path)]
    imp.find_module(module_name, paths)
    return BOOTSTRAP_BASE_PATH
  except ImportError:
    pass

  return None


def _Bootstrap(bootstrap_deps_url):
  """Grab all the deps listed in the file at bootstrap_deps_url."""
  bootstrap_txt = urllib2.urlopen(
      BASE_URL + 'src/tools/telemetry_tools/telemetry_bootstrap.py').read()
  bootstrap = imp.new_module('bootstrap')
  exec bootstrap_txt in bootstrap.__dict__
  bootstrap.DownloadDeps(BOOTSTRAP_BASE_PATH, bootstrap_deps_url)


def ListBootstrapDeps(base_path, subdir):
  """List the deps required for telemetry."""
  sys.path.append(os.path.join(base_path, TELEMETRY_TOOLS_DIR))
  import telemetry_bootstrap

  deps_file = os.path.join(base_path, subdir, DEPS_FILE)
  return telemetry_bootstrap.ListAllDepsPaths(deps_file)


def Main():
  if not _GetBasePath():
    _Bootstrap(BASE_URL + 'src/tools/perf/' + DEPS_FILE)

  new_base_path = _GetBasePath()
  new_perf_path = os.path.join(new_base_path, PERF_DIR)
  new_telemetry_path = os.path.join(new_base_path, TELEMETRY_DIR)

  if '--print-bootstrap-deps-cros' in sys.argv:
    print ListBootstrapDeps(new_base_path, CROS_DIR)
    return 0

  if '--print-bootstrap-deps' in sys.argv:
    print ListBootstrapDeps(new_base_path, PERF_DIR)
    return 0

  sys.path.append(new_perf_path)
  import page_sets
  page_set_filenames = page_sets.GetAllPageSetFilenames()

  old_benchmark_names = {
    "image_decoding_benchmark": "image_decoding",
    "image_decoding_measurement": "image_decoding",
    "loading_benchmark": "loading",
    "loading_measurement": "loading",
    "media_measurement": "media",
    "memory_benchmark": "memory",
    "memory_measurement": "memory",
    "rasterize_and_record_benchmark": "rasterize_and_record",
    "rasterize_and_record_measurement": "rasterize_and_record",
    "robohornetpro": "robohornet_pro",
    "scrolling_benchmark": "smoothness",
    "smoothness_benchmark": "smoothness",
    "smoothness_measurement": "smoothness",
    "startup_benchmark": "startup_warm_blank_page",
    "startup_measurement": "startup",
    "tab_switching_measurement": "tab_switching",
  }

  sys.path.append(new_telemetry_path)
  from telemetry.page import page_measurement_runner
  # There are bots that are hard-coded to run some specific named tests.
  # Convert these to the current naming conventions by overriding them
  # in the runner.
  class MeasurementRunner(page_measurement_runner.PageMeasurementRunner):
    def GetModernizedTestName(self, arg):
      if arg not in old_benchmark_names:
        return arg
      sys.stderr.write(
        'An old name %s was given. Please use %s in the future.\n' % (
          arg,
          old_benchmark_names.get(arg)))
      return old_benchmark_names[arg]

  runner = MeasurementRunner()
  return runner.Run(new_perf_path, page_set_filenames)


if __name__ == '__main__':
  sys.exit(Main())