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