Gallery: replace paper-input of rename field with HTMLInputElement.
[chromium-blink-merge.git] / tools / perf / core / perf_benchmark.py
blob34898fef7ed143df3c744656c48d1208be49a40c
1 # Copyright 2015 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.
5 import os
6 import sys
8 from telemetry import benchmark
9 from telemetry.internal.browser import browser_finder
11 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir,
12 os.pardir, 'variations'))
13 import fieldtrial_util # pylint: disable=import-error
16 class PerfBenchmark(benchmark.Benchmark):
17 """ Super class for all benchmarks in src/tools/perf/benchmarks directory.
18 All the perf benchmarks must subclass from this one to to make sure that
19 the field trial configs are activated for the browser during benchmark runs.
20 For more info, see: https://goo.gl/4uvaVM
21 """
23 def SetExtraBrowserOptions(self, options):
24 """ To be overridden by perf benchmarks. """
25 pass
27 def CustomizeBrowserOptions(self, options):
28 # Subclass of PerfBenchmark should override SetExtraBrowserOptions to add
29 # more browser options rather than overriding CustomizeBrowserOptions.
30 super(PerfBenchmark, self).CustomizeBrowserOptions(options)
31 # The current field trial config is used for an older build in the case of
32 # reference. This is a problem because we are then subjecting older builds
33 # to newer configurations that may crash. To work around this problem,
34 # don't add the field trials to reference builds.
35 if options.browser_type != 'reference':
36 variations = self._GetVariationsBrowserArgs(options.finder_options)
37 options.AppendExtraBrowserArgs(variations)
38 self.SetExtraBrowserOptions(options)
40 @staticmethod
41 def _FixupTargetOS(target_os):
42 if target_os == 'darwin':
43 return 'mac'
44 if target_os.startswith('win'):
45 return 'win'
46 if target_os.startswith('linux'):
47 return 'linux'
48 return target_os
50 def _GetVariationsBrowserArgs(self, finder_options):
51 variations_dir = os.path.join(os.path.dirname(__file__), os.pardir,
52 os.pardir, os.pardir, 'testing', 'variations')
53 target_os = browser_finder.FindBrowser(finder_options).target_os
54 return fieldtrial_util.GenerateArgs(
55 os.path.join(variations_dir,
56 'fieldtrial_testing_config_%s.json' % self._FixupTargetOS(target_os)))