mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:30:12 +01:00
Trying to make it easier to see possible bottlenecks. Disabling hyperthreading seems like a significant reduction in contention (15% improvement for me). Going down by half again reduces a contention a little further, but not significantly from what I see. My thought is that just flipping the flag is going to work best for people cross-system versus a "divide by four", but welcome to other opinions there. Note, I'm not digging into the source of the contention here, just observing it. Current default on my system (equivalent to `--threads=128`): ``` Running tests with 128 thread(s) ... Ran 1272 tests in 3955 ms wall time, 397615 ms across threads ``` Disabling hyperthreads (equivalent to `--threads=64`): ``` Running tests with 64 thread(s) ... Ran 1272 tests in 3520 ms wall time, 161957 ms across threads ``` `--threads=32`: ``` Running tests with 32 thread(s) ... Ran 1272 tests in 3329 ms wall time, 69327 ms across threads ``` And for `./autoupdate_testdata.py --threads=64 --print_slowest_tests=5`: ``` Running tests with 64 thread(s) ... Ran 1272 tests in 3417 ms wall time, 157946 ms across threads Slowest tests: - toolchain/lower/testdata/function/generic/call_recursive_basic.carbon: 1508 ms, 1484 ms in Run - toolchain/lower/testdata/builtins/print_read.carbon: 1506 ms, 1506 ms in Run - toolchain/lower/testdata/array/field.carbon: 1488 ms, 1487 ms in Run - toolchain/lower/testdata/builtins/int.carbon: 1482 ms, 1475 ms in Run - toolchain/lower/testdata/function/definition/params_one.carbon: 1472 ms, 1471 ms in Run ``` In test: ``` ==================== Test output for //toolchain/testing:file_test: Running tests with 64 thread(s) ... Ran 1272 tests in 2968 ms wall time, 177732 ms across threads Slowest tests: - toolchain/lower/testdata/builtins/int.carbon: 1544 ms, 1533 ms in Run - toolchain/lower/testdata/array/function_param.carbon: 1539 ms, 1537 ms in Run - toolchain/lower/testdata/basics/zero.carbon: 1537 ms, 1536 ms in Run - toolchain/lower/testdata/function/call/params_one.carbon: 1535 ms, 1534 ms in Run - toolchain/lower/testdata/function/definition/params_zero.carbon: 1531 ms, 1531 ms in Run [==========] Running 1272 tests from 1 test suite. [----------] Global test environment set-up. ```
100 lines
3.0 KiB
Python
Executable File
100 lines
3.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""Autoupdates testdata in toolchain."""
|
|
|
|
__copyright__ = """
|
|
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
Exceptions. See /LICENSE for license information.
|
|
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
"""
|
|
|
|
import argparse
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def main() -> None:
|
|
bazel = str(Path(__file__).parents[1] / "scripts" / "run_bazel.py")
|
|
configs = []
|
|
# Use the most recently used build mode, or `fastbuild` if missing
|
|
# `bazel-bin`.
|
|
build_mode = "fastbuild"
|
|
workspace = subprocess.check_output(
|
|
[
|
|
bazel,
|
|
"info",
|
|
"workspace",
|
|
"--ui_event_filters=stdout",
|
|
],
|
|
encoding="utf-8",
|
|
).strip()
|
|
bazel_bin_path = Path(workspace).joinpath("bazel-bin")
|
|
if bazel_bin_path.exists():
|
|
link = str(bazel_bin_path.readlink())
|
|
m = re.search(r"-(\w+)/bin$", link)
|
|
if m:
|
|
build_mode = m[1]
|
|
else:
|
|
exit(f"Build mode not found in `bazel-bin` symlink: {link}")
|
|
|
|
# Parse arguments.
|
|
parser = argparse.ArgumentParser(__doc__)
|
|
parser.add_argument("--non-fatal-checks", action="store_true")
|
|
parser.add_argument(
|
|
"--print_slowest_tests", default=0, help="Forwarded to file_test"
|
|
)
|
|
parser.add_argument("--threads", help="Forwarded to file_test")
|
|
parser.add_argument("files", nargs="*")
|
|
args = parser.parse_args()
|
|
|
|
if args.non_fatal_checks:
|
|
if build_mode == "opt":
|
|
exit(
|
|
"`--non-fatal-checks` is incompatible with inferred "
|
|
"`-c opt` build mode"
|
|
)
|
|
configs.append("--config=non-fatal-checks")
|
|
|
|
argv = [
|
|
bazel,
|
|
"run",
|
|
"-c",
|
|
build_mode,
|
|
*configs,
|
|
"--experimental_convenience_symlinks=ignore",
|
|
"--ui_event_filters=-info,-stdout,-stderr,-finish",
|
|
"//toolchain/testing:file_test",
|
|
"--",
|
|
"--autoupdate",
|
|
"--print_slowest_tests",
|
|
str(args.print_slowest_tests),
|
|
]
|
|
if args.threads:
|
|
argv += ["--threads", args.threads]
|
|
# Support specifying tests to update, such as:
|
|
# ./autoupdate_testdata.py lex/**/*
|
|
if args.files:
|
|
repo_root = Path(__file__).parents[1]
|
|
file_tests = []
|
|
# Filter down to just test files.
|
|
for f in args.files:
|
|
if f.endswith(".carbon"):
|
|
path = str(Path(f).resolve().relative_to(repo_root))
|
|
if path.count("/testdata/"):
|
|
file_tests.append(path)
|
|
if not file_tests:
|
|
sys.exit(
|
|
"Args do not seem to be test files; for example, "
|
|
f"{args.files[0]}"
|
|
)
|
|
argv.append("--file_tests=" + ",".join(file_tests))
|
|
# Provide an empty stdin so that the driver tests that read from stdin
|
|
# don't block waiting for input. This matches the behavior of `bazel test`.
|
|
subprocess.run(argv, check=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|