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        BooleanField(
295            'compress_results',
296            default=True,
297            description='Whether to compress all test results other than '
298            'reports into a tarball to save disk space.'))
299    self.AddField(
300        TextField(
301            'locks_dir',
302            default='',
303            description='An alternate directory to use for '
304            'storing/checking machine file locks for local machines. '
305            'By default the file locks directory is '
306            '/google/data/rw/users/mo/mobiletc-prebuild/locks.\n'
307            'WARNING: If you use your own locks directory, '
308            'there is no guarantee that someone else might not '
309            'hold a lock on the same machine in a different '
310            'locks directory.'))
311    self.AddField(
312        TextField(
313            'chrome_src',
314            description='The path to the source of chrome. '
315            'This is used to run telemetry benchmarks. '
316            'The default one is the src inside chroot.',
317            required=False,
318            default=''))
319    self.AddField(
320        IntegerField(
321            'retries',
322            default=0,
323            description='Number of times to retry a '
324            'benchmark run.'))
325    self.AddField(
326        TextField(
327            'cwp_dso',
328            description='The DSO type that we want to use for '
329            'CWP approximation. This is used to run telemetry '
330            'benchmarks. Valid DSO types can be found from dso_list '
331            'in experiment_factory.py. The default value is set to '
332            'be empty.',
333            required=False,
334            default=''))
335    self.AddField(
336        BooleanField(
337            'enable_aslr',
338            description='Enable ASLR on the machine to run the '
339            'benchmarks. ASLR is disabled by default',
340            required=False,
341            default=False))
342    self.AddField(
343        BooleanField(
344            'ignore_min_max',
345            description='When doing math for the raw results, '
346            'ignore min and max values to reduce noise.',
347            required=False,
348            default=False))
349    self.AddField(
350        TextField(
351            'intel_pstate',
352            description='Intel Pstate mode.\n'
353            'Supported modes: "active", "passive", "no_hwp".\n'
354            'Default is "no_hwp" which disables hardware pstates to avoid '
355            'noise in benchmarks.',
356            required=False,
357            default='no_hwp'))
358    self.AddField(
359        BooleanField(
360            'turbostat',
361            description='Run turbostat process in the background'
362            ' of a benchmark. Enabled by default.',
363            required=False,
364            default=True))
365    self.AddField(
366        FloatField(
367            'top_interval',
368            description='Run top command in the background of a benchmark with'
369            ' interval of sampling specified in seconds.\n'
370            'Recommended values 1-5. Lower number provides more accurate'
371            ' data.\n'
372            'With 0 - do not run top.\n'
373            'NOTE: Running top with interval 1-5 sec has insignificant'
374            ' performance impact (performance degradation does not exceed'
375            ' 0.3%%, measured on x86_64, ARM32, and ARM64). '
376            'The default value is 1.',
377            required=False,
378            default=1))
379    self.AddField(
380        IntegerField(
381            'cooldown_temp',
382            required=False,
383            default=40,
384            description='Wait until CPU temperature goes down below'
385            ' specified temperature in Celsius'
386            ' prior starting a benchmark. '
387            'By default the value is set to 40 degrees.'))
388    self.AddField(
389        IntegerField(
390            'cooldown_time',
391            required=False,
392            default=10,
393            description='Wait specified time in minutes allowing'
394            ' CPU to cool down. Zero value disables cooldown. '
395            'The default value is 10 minutes.'))
396    self.AddField(
397        EnumField(
398            'governor',
399            options=[
400                'performance',
401                'powersave',
402                'userspace',
403                'ondemand',
404                'conservative',
405                'schedutils',
406                'sched',
407                'interactive',
408            ],
409            default='performance',
410            required=False,
411            description='Setup CPU governor for all cores.\n'
412            'For more details refer to:\n'
413            'https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt. '
414            'Default is "performance" governor.'))
415    self.AddField(
416        EnumField(
417            'cpu_usage',
418            options=[
419                'all',
420                'big_only',
421                'little_only',
422                'exclusive_cores',
423            ],
424            default='all',
425            required=False,
426            description='Restrict usage of CPUs to decrease CPU interference.\n'
427            '"all" - no restrictions;\n'
428            '"big-only", "little-only" - enable only big/little cores,'
429            ' applicable only on ARM;\n'
430            '"exclusive-cores" - (for future use)'
431            ' isolate cores for exclusive use of benchmark processes. '
432            'By default use all CPUs.'))
433    self.AddField(
434        IntegerField(
435            'cpu_freq_pct',
436            required=False,
437            default=95,
438            description='Setup CPU frequency to a supported value less than'
439            ' or equal to a percent of max_freq. '
440            'CPU frequency is reduced to 95%% by default to reduce thermal '
441            'throttling.'))
442
443
444class SettingsFactory(object):
445  """Factory class for building different types of Settings objects.
446
447  This factory is currently hardcoded to produce settings for ChromeOS
448  experiment files. The idea is that in the future, other types
449  of settings could be produced.
450  """
451
452  def GetSettings(self, name, settings_type):
453    if settings_type == 'label' or not settings_type:
454      return LabelSettings(name)
455    if settings_type == 'global':
456      return GlobalSettings(name)
457    if settings_type == 'benchmark':
458      return BenchmarkSettings(name)
459
460    raise TypeError("Invalid settings type: '%s'." % settings_type)
461