• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2# Copyright (c) 2013 The Chromium OS 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"""Setting files for global, benchmark and labels."""
7
8from __future__ import print_function
9
10from field import BooleanField
11from field import EnumField
12from field import FloatField
13from field import IntegerField
14from field import ListField
15from field import TextField
16from settings import Settings
17
18
19class BenchmarkSettings(Settings):
20  """Settings used to configure individual benchmarks."""
21
22  def __init__(self, name):
23    super(BenchmarkSettings, self).__init__(name, 'benchmark')
24    self.AddField(
25        TextField(
26            'test_name',
27            description='The name of the test to run. '
28            'Defaults to the name of the benchmark.'))
29    self.AddField(
30        TextField(
31            'test_args', description='Arguments to be passed to the '
32            'test.'))
33    self.AddField(
34        IntegerField(
35            'iterations',
36            required=False,
37            default=0,
38            description='Number of iterations to run the test. '
39            'If not set, will run each benchmark test the optimum number of '
40            'times to get a stable result.'))
41    self.AddField(
42        TextField(
43            'suite',
44            default='test_that',
45            description='The type of the benchmark.'))
46    self.AddField(
47        IntegerField(
48            'retries',
49            default=0,
50            description='Number of times to retry a '
51            'benchmark run.'))
52    self.AddField(
53        BooleanField(
54            'run_local',
55            description='Run benchmark harness on the DUT. '
56            'Currently only compatible with the suite: '
57            'telemetry_Crosperf.',
58            required=False,
59            default=True))
60    self.AddField(
61        FloatField(
62            'weight',
63            default=0.0,
64            description='Weight of the benchmark for CWP approximation'))
65
66
67class LabelSettings(Settings):
68  """Settings for each label."""
69
70  def __init__(self, name):
71    super(LabelSettings, self).__init__(name, 'label')
72    self.AddField(
73        TextField(
74            'chromeos_image',
75            required=False,
76            description='The path to the image to run tests '
77            'on, for local/custom-built images. See the '
78            "'build' option for official or trybot images."))
79    self.AddField(
80        TextField(
81            'autotest_path',
82            required=False,
83            description='Autotest directory path relative to chroot which '
84            'has autotest files for the image to run tests requiring autotest '
85            'files.'))
86    self.AddField(
87        TextField(
88            'debug_path',
89            required=False,
90            description='Debug info directory relative to chroot which has '
91            'symbols and vmlinux that can be used by perf tool.'))
92    self.AddField(
93        TextField(
94            'chromeos_root',
95            description='The path to a chromeos checkout which '
96            'contains a src/scripts directory. Defaults to '
97            'the chromeos checkout which contains the '
98            'chromeos_image.'))
99    self.AddField(
100        ListField(
101            'remote',
102            description='A comma-separated list of IPs of chromeos'
103            'devices to run experiments on.'))
104    self.AddField(
105        TextField(
106            'image_args',
107            required=False,
108            default='',
109            description='Extra arguments to pass to '
110            'image_chromeos.py.'))
111    self.AddField(
112        TextField(
113            'cache_dir',
114            default='',
115            description='The cache dir for this image.'))
116    self.AddField(
117        TextField(
118            'compiler',
119            default='gcc',
120            description='The compiler used to build the '
121            'ChromeOS image (gcc or llvm).'))
122    self.AddField(
123        TextField(
124            'chrome_src',
125            description='The path to the source of chrome. '
126            'This is used to run telemetry benchmarks. '
127            'The default one is the src inside chroot.',
128            required=False,
129            default=''))
130    self.AddField(
131        TextField(
132            'build',
133            description='The xbuddy specification for an '
134            'official or trybot image to use for tests. '
135            "'/remote' is assumed, and the board is given "
136            "elsewhere, so omit the '/remote/<board>/' xbuddy "
137            'prefix.',
138            required=False,
139            default=''))
140
141
142class GlobalSettings(Settings):
143  """Settings that apply per-experiment."""
144
145  def __init__(self, name):
146    super(GlobalSettings, self).__init__(name, 'global')
147    self.AddField(
148        TextField(
149            'name',
150            description='The name of the experiment. Just an '
151            'identifier.'))
152    self.AddField(
153        TextField(
154            'board',
155            description='The target board for running '
156            'experiments on, e.g. x86-alex.'))
157    self.AddField(
158        BooleanField(
159            'skylab',
160            description='Whether to run experiments via skylab.',
161            default=False))
162    self.AddField(
163        ListField(
164            'remote',
165            description='A comma-separated list of IPs of '
166            'chromeos devices to run experiments on.'))
167    self.AddField(
168        BooleanField(
169            'rerun_if_failed',
170            description='Whether to re-run failed test runs '
171            'or not.',
172            default=False))
173    self.AddField(
174        BooleanField(
175            'rm_chroot_tmp',
176            default=False,
177            description='Whether to remove the test_that '
178            'result in the chroot.'))
179    self.AddField(
180        ListField(
181            'email',
182            description='Space-separated list of email '
183            'addresses to send email to.'))
184    self.AddField(
185        BooleanField(
186            'rerun',
187            description='Whether to ignore the cache and '
188            'for tests to be re-run.',
189            default=False))
190    self.AddField(
191        BooleanField(
192            'same_specs',
193            default=True,
194            description='Ensure cached runs are run on the '
195            'same kind of devices which are specified as a '
196            'remote.'))
197    self.AddField(
198        BooleanField(
199            'same_machine',
200            default=False,
201            description='Ensure cached runs are run on the '
202            'same remote.'))
203    self.AddField(
204        BooleanField(
205            'use_file_locks',
206            default=False,
207            description='DEPRECATED: Whether to use the file locks '
208            'or AFE server lock mechanism.'))
209    self.AddField(
210        IntegerField(
211            'iterations',
212            required=False,
213            default=0,
214            description='Number of iterations to run all tests. '
215            'If not set, will run each benchmark test the optimum number of '
216            'times to get a stable result.'))
217    self.AddField(
218        TextField(
219            'chromeos_root',
220            description='The path to a chromeos checkout which '
221            'contains a src/scripts directory. Defaults to '
222            'the chromeos checkout which contains the '
223            'chromeos_image.'))
224    self.AddField(
225        TextField(
226            'logging_level',
227            default='average',
228            description='The level of logging desired. '
229            "Options are 'quiet', 'average', and 'verbose'."))
230    self.AddField(
231        IntegerField(
232            'acquire_timeout',
233            default=0,
234            description='Number of seconds to wait for '
235            'machine before exit if all the machines in '
236            'the experiment file are busy. Default is 0.'))
237    self.AddField(
238        TextField(
239            'perf_args',
240            default='',
241            description='The optional profile command. It '
242            'enables perf commands to record perforamance '
243            'related counters. It must start with perf '
244            'command record or stat followed by arguments.'))
245    self.AddField(
246        BooleanField(
247            'download_debug',
248            default=True,
249            description='Download compressed debug symbols alongwith '
250            'image. This can provide more info matching symbols for'
251            'profiles, but takes larger space. By default, download'
252            'it only when perf_args is specified.'))
253    self.AddField(
254        TextField(
255            'cache_dir',
256            default='',
257            description='The abs path of cache dir. '
258            'Default is /home/$(whoami)/cros_scratch.'))
259    self.AddField(
260        BooleanField(
261            'cache_only',
262            default=False,
263            description='Whether to use only cached '
264            'results (do not rerun failed tests).'))
265    self.AddField(
266        BooleanField(
267            'no_email',
268            default=False,
269            description='Whether to disable the email to '
270            'user after crosperf finishes.'))
271    self.AddField(
272        BooleanField(
273            'json_report',
274            default=False,
275            description='Whether to generate a json version '
276            'of the report, for archiving.'))
277    self.AddField(
278        BooleanField(
279            'show_all_results',
280            default=False,
281            description='When running Telemetry tests, '
282            'whether to all the results, instead of just '
283            'the default (summary) results.'))
284    self.AddField(
285        TextField(
286            'share_cache',
287            default='',
288            description='Path to alternate cache whose data '
289            'you want to use. It accepts multiple directories '
290            'separated by a ",".'))
291    self.AddField(
292        TextField('results_dir', default='', description='The results dir.'))
293    self.AddField(
294        TextField(
295            'locks_dir',
296            default='',
297            description='An alternate directory to use for '
298            'storing/checking machine file locks for local machines. '
299            'By default the file locks directory is '
300            '/google/data/rw/users/mo/mobiletc-prebuild/locks.\n'
301            'WARNING: If you use your own locks directory, '
302            'there is no guarantee that someone else might not '
303            'hold a lock on the same machine in a different '
304            'locks directory.'))
305    self.AddField(
306        TextField(
307            'chrome_src',
308            description='The path to the source of chrome. '
309            'This is used to run telemetry benchmarks. '
310            'The default one is the src inside chroot.',
311            required=False,
312            default=''))
313    self.AddField(
314        IntegerField(
315            'retries',
316            default=0,
317            description='Number of times to retry a '
318            'benchmark run.'))
319    self.AddField(
320        TextField(
321            'cwp_dso',
322            description='The DSO type that we want to use for '
323            'CWP approximation. This is used to run telemetry '
324            'benchmarks. Valid DSO types can be found from dso_list '
325            'in experiment_factory.py. The default value is set to '
326            'be empty.',
327            required=False,
328            default=''))
329    self.AddField(
330        BooleanField(
331            'enable_aslr',
332            description='Enable ASLR on the machine to run the '
333            'benchmarks. ASLR is disabled by default',
334            required=False,
335            default=False))
336    self.AddField(
337        BooleanField(
338            'ignore_min_max',
339            description='When doing math for the raw results, '
340            'ignore min and max values to reduce noise.',
341            required=False,
342            default=False))
343    self.AddField(
344        TextField(
345            'intel_pstate',
346            description='Intel Pstate mode.\n'
347            'Supported modes: passive, no_hwp.\n'
348            'By default kernel works in active HWP mode if HWP is supported'
349            " by CPU. This corresponds to a default intel_pstate=''",
350            required=False,
351            default=''))
352    self.AddField(
353        BooleanField(
354            'turbostat',
355            description='Run turbostat process in the background'
356            ' of a benchmark',
357            required=False,
358            default=True))
359    self.AddField(
360        FloatField(
361            'top_interval',
362            description='Run top command in the background of a benchmark with'
363            ' interval of sampling specified in seconds.\n'
364            'Recommended values 1-5. Lower number provides more accurate'
365            ' data.\n'
366            'With 0 - do not run top.\n'
367            'NOTE: Running top with interval 1-5 sec has insignificant'
368            ' performance impact (performance degradation does not exceed 0.3%,'
369            ' measured on x86_64, ARM32, and ARM64).',
370            required=False,
371            default=0))
372    self.AddField(
373        IntegerField(
374            'cooldown_temp',
375            required=False,
376            default=40,
377            description='Wait until CPU temperature goes down below'
378            ' specified temperature in Celsius'
379            ' prior starting a benchmark.'))
380    self.AddField(
381        IntegerField(
382            'cooldown_time',
383            required=False,
384            default=0,
385            description='Wait specified time in minutes allowing'
386            ' CPU to cool down. Zero value disables cooldown.'))
387    self.AddField(
388        EnumField(
389            'governor',
390            options=[
391                'performance',
392                'powersave',
393                'userspace',
394                'ondemand',
395                'conservative',
396                'schedutils',
397                'sched',
398                'interactive',
399            ],
400            default='performance',
401            required=False,
402            description='Setup CPU governor for all cores.\n'
403            'For more details refer to:\n'
404            'https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt'))
405    self.AddField(
406        EnumField(
407            'cpu_usage',
408            options=[
409                'all',
410                'big_only',
411                'little_only',
412                'exclusive_cores',
413            ],
414            default='all',
415            required=False,
416            description='Restrict usage CPUs to decrease CPU interference.\n'
417            'all - no restrictions;\n'
418            'big-only, little-only - enable only big/little cores,'
419            ' applicable only on ARM;\n'
420            'exclusive-cores - (for future use)'
421            ' isolate cores for exclusive use of benchmark processes.'))
422    self.AddField(
423        IntegerField(
424            'cpu_freq_pct',
425            required=False,
426            default=100,
427            description='Setup CPU frequency to a supported value less than'
428            ' or equal to a percent of max_freq.'))
429
430
431class SettingsFactory(object):
432  """Factory class for building different types of Settings objects.
433
434  This factory is currently hardcoded to produce settings for ChromeOS
435  experiment files. The idea is that in the future, other types
436  of settings could be produced.
437  """
438
439  def GetSettings(self, name, settings_type):
440    if settings_type == 'label' or not settings_type:
441      return LabelSettings(name)
442    if settings_type == 'global':
443      return GlobalSettings(name)
444    if settings_type == 'benchmark':
445      return BenchmarkSettings(name)
446
447    raise TypeError("Invalid settings type: '%s'." % settings_type)
448