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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
This transform passes options from `mach perftest` to the corresponding task.
"""
from datetime import date, timedelta
from taskgraph.transforms.base import TransformSequence
from taskgraph.util import json
from taskgraph.util.copy import deepcopy
from taskgraph.util.schema import Schema, optionally_keyed_by, resolve_keyed_by
from taskgraph.util.treeherder import join_symbol, split_symbol
from voluptuous import Any, Extra, Optional
transforms = TransformSequence()
perftest_description_schema = Schema(
{
# The test names and the symbols to use for them: [test-symbol, test-path]
Optional("perftest"): [[str]],
# Metrics to gather for the test. These will be merged
# with options specified through perftest-perfherder-global
Optional("perftest-metrics"): optionally_keyed_by(
"perftest",
Any(
[str],
{str: Any(None, {str: Any(None, str, [str])})},
),
),
# Perfherder data options that will be applied to
# all metrics gathered.
Optional("perftest-perfherder-global"): optionally_keyed_by(
"perftest", {str: Any(None, str, [str])}
),
# Extra options to add to the test's command
Optional("perftest-extra-options"): optionally_keyed_by("perftest", [str]),
# Variants of the test to make based on extra browsertime
# arguments. Expecting:
# [variant-suffix, options-to-use]
# If variant-suffix is `null` then the options will be added
# to the existing task. Otherwise, a new variant is created
# with the given suffix and with its options replaced.
Optional("perftest-btime-variants"): optionally_keyed_by(
"perftest", [[Any(None, str)]]
),
# These options will be parsed in the next schemas
Extra: object,
}
)
transforms.add_validate(perftest_description_schema)
@transforms.add
def split_tests(config, jobs):
for job in jobs:
if job.get("perftest") is None:
yield job
continue
for test_symbol, test_name in job.pop("perftest"):
job_new = deepcopy(job)
job_new["perftest"] = test_symbol
job_new["name"] += "-" + test_symbol
job_new["treeherder"]["symbol"] = job["treeherder"]["symbol"].format(
symbol=test_symbol
)
job_new["run"]["command"] = job["run"]["command"].replace(
"{perftest_testname}", test_name
)
yield job_new
@transforms.add
def handle_keyed_by_perftest(config, jobs):
fields = ["perftest-metrics", "perftest-extra-options", "perftest-btime-variants"]
for job in jobs:
if job.get("perftest") is None:
yield job
continue
for field in fields:
resolve_keyed_by(job, field, item_name=job["name"])
job.pop("perftest")
yield job
@transforms.add
def parse_perftest_metrics(config, jobs):
"""Parse the metrics into a dictionary immediately.
This way we can modify the extraOptions field (and others) entry through the
transforms that come later. The metrics aren't formatted until the end of the
transforms.
"""
for job in jobs:
if job.get("perftest-metrics") is None:
yield job
continue
perftest_metrics = job.pop("perftest-metrics")
# If perftest metrics is a string, split it up first
if isinstance(perftest_metrics, list):
new_metrics_info = [{"name": metric} for metric in perftest_metrics]
else:
new_metrics_info = []
for metric, options in perftest_metrics.items():
entry = {"name": metric}
entry.update(options)
new_metrics_info.append(entry)
job["perftest-metrics"] = new_metrics_info
yield job
@transforms.add
def split_perftest_variants(config, jobs):
for job in jobs:
if job.get("variants") is None:
yield job
continue
for variant in job.pop("variants"):
job_new = deepcopy(job)
group, symbol = split_symbol(job_new["treeherder"]["symbol"])
group += "-" + variant
job_new["treeherder"]["symbol"] = join_symbol(group, symbol)
job_new["name"] += "-" + variant
job_new.setdefault("perftest-perfherder-global", {}).setdefault(
"extraOptions", []
).append(variant)
job_new[variant] = True
yield job_new
yield job
@transforms.add
def split_btime_variants(config, jobs):
for job in jobs:
if job.get("perftest-btime-variants") is None:
yield job
continue
variants = job.pop("perftest-btime-variants")
if not variants:
yield job
continue
yield_existing = False
for suffix, options in variants:
if suffix is None:
# Append options to the existing job
job.setdefault("perftest-btime-variants", []).append(options)
yield_existing = True
else:
job_new = deepcopy(job)
group, symbol = split_symbol(job_new["treeherder"]["symbol"])
symbol += "-" + suffix
job_new["treeherder"]["symbol"] = join_symbol(group, symbol)
job_new["name"] += "-" + suffix
job_new.setdefault("perftest-perfherder-global", {}).setdefault(
"extraOptions", []
).append(suffix)
# Replace the existing options with the new ones
job_new["perftest-btime-variants"] = [options]
yield job_new
# The existing job has been modified so we should also return it
if yield_existing:
yield job
@transforms.add
def setup_http3_tests(config, jobs):
for job in jobs:
if job.get("http3") is None or not job.pop("http3"):
yield job
continue
job.setdefault("perftest-btime-variants", []).append(
"firefox.preference=network.http.http3.enable:true"
)
yield job
@transforms.add
def setup_perftest_metrics(config, jobs):
for job in jobs:
if job.get("perftest-metrics") is None:
yield job
continue
perftest_metrics = job.pop("perftest-metrics")
# Options to apply to each metric
global_options = job.pop("perftest-perfherder-global", {})
for metric_info in perftest_metrics:
for opt, val in global_options.items():
if isinstance(val, list) and opt in metric_info:
metric_info[opt].extend(val)
elif not (isinstance(val, list) and len(val) == 0):
metric_info[opt] = val
quote_escape = '\\"'
if "win" in job.get("platform", ""):
# Escaping is a bit different on windows platforms
quote_escape = '\\\\\\"'
job["run"]["command"] = job["run"]["command"].replace(
"{perftest_metrics}",
" ".join(
[
",".join(
[
":".join(
[
option,
str(value)
.replace(" ", "")
.replace("'", quote_escape),
]
)
for option, value in metric_info.items()
]
)
for metric_info in perftest_metrics
]
),
)
yield job
@transforms.add
def setup_perftest_browsertime_variants(config, jobs):
for job in jobs:
if job.get("perftest-btime-variants") is None:
yield job
continue
job["run"]["command"] += " --browsertime-extra-options %s" % ",".join(
[opt.strip() for opt in job.pop("perftest-btime-variants")]
)
yield job
@transforms.add
def setup_perftest_extra_options(config, jobs):
for job in jobs:
if job.get("perftest-extra-options") is None:
yield job
continue
job["run"]["command"] += " " + " ".join(job.pop("perftest-extra-options"))
yield job
@transforms.add
def create_duplicate_simpleperf_jobs(config, jobs):
for job in jobs:
if (
"startup" in job["name"]
and "cold" not in job["name"]
and "chrome-m" not in job["name"]
):
new_job = deepcopy(job)
new_job["run-on-projects"] = []
new_job["attributes"] = {"cron": False}
new_job["dependencies"] = {
"android-aarch64-shippable": "build-android-aarch64-shippable/opt"
}
new_job["name"] += "-simpleperf"
new_job["run"][
"command"
] += " --simpleperf --simpleperf-path $MOZ_FETCHES_DIR/android-simpleperf"
new_job["description"] = str(new_job["description"]).replace(
"Run", "Profile"
)
new_job["treeherder"]["symbol"] = str(
new_job["treeherder"]["symbol"]
).replace(")", "-profile)")
new_job["fetches"]["toolchain"].extend(
[
"linux64-android-simpleperf-linux-repack",
"linux64-samply",
"symbolicator-cli",
]
)
new_job["fetches"]["android-aarch64-shippable"] = [
{
"artifact": "target.crashreporter-symbols.zip",
"extract": False,
}
]
yield new_job
yield job
@transforms.add
def pass_perftest_options(config, jobs):
for job in jobs:
env = job.setdefault("worker", {}).setdefault("env", {})
env["PERFTEST_OPTIONS"] = json.dumps(
config.params["try_task_config"].get("perftest-options")
)
yield job
@transforms.add
def setup_perftest_test_date(config, jobs):
for job in jobs:
if (
job.get("attributes", {}).get("batch", False)
and "--test-date" not in job["run"]["command"]
):
yesterday = (date.today() - timedelta(1)).strftime("%Y.%m.%d")
job["run"]["command"] += " --test-date %s" % yesterday
yield job
@transforms.add
def setup_regression_detector(config, jobs):
for job in jobs:
if "change-detector" in job.get("name"):
tasks_to_analyze = []
for task in config.params["try_task_config"].get("tasks", []):
# Explicitly skip these tasks since they're
# part of the mozperftest tasks
if "side-by-side" in task:
continue
if "change-detector" in task:
continue
# Select these tasks
if "browsertime" in task:
tasks_to_analyze.append(task)
elif "talos" in task:
tasks_to_analyze.append(task)
elif "awsy" in task:
tasks_to_analyze.append(task)
elif "perftest" in task:
tasks_to_analyze.append(task)
if len(tasks_to_analyze) == 0:
yield job
continue
# Make the change detector task depend on the tasks to analyze.
# This prevents the task from running until all data is available
# within the current push.
job["soft-dependencies"] = tasks_to_analyze
job["requires"] = "all-completed"
new_project = config.params["project"]
if (
"try" in config.params["project"]
or config.params["try_mode"] == "try_select"
):
new_project = "try"
base_project = None
if (
config.params.get("try_task_config", {})
.get("env", {})
.get("PERF_BASE_REVISION", None)
is not None
):
task_names = " --task-name ".join(tasks_to_analyze)
base_revision = config.params["try_task_config"]["env"][
"PERF_BASE_REVISION"
]
base_project = new_project
# Add all the required information to the task
job["run"]["command"] = job["run"]["command"].format(
task_name=task_names,
base_revision=base_revision,
base_branch=base_project,
new_branch=new_project,
new_revision=config.params["head_rev"],
)
yield job
@transforms.add
def apply_perftest_tier_optimization(config, jobs):
for job in jobs:
job["optimization"] = {"skip-unless-backstop": None}
job["treeherder"]["tier"] = max(job["treeherder"]["tier"], 2)
yield job
@transforms.add
def set_perftest_attributes(config, jobs):
for job in jobs:
attributes = job.setdefault("attributes", {})
attributes["perftest_name"] = job["name"]
yield job
|