mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:50:14 +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. ```
114 lines
3.7 KiB
C++
114 lines
3.7 KiB
C++
// 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
|
|
|
|
#ifndef CARBON_TESTING_FILE_TEST_TEST_FILE_H_
|
|
#define CARBON_TESTING_FILE_TEST_TEST_FILE_H_
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <chrono>
|
|
#include <string>
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "testing/file_test/file_test_base.h"
|
|
#include "testing/file_test/line.h"
|
|
|
|
namespace Carbon::Testing {
|
|
|
|
// A small timer for getting elapsed durations.
|
|
class Timer {
|
|
public:
|
|
explicit Timer() : start_(std::chrono::steady_clock::now()) {}
|
|
|
|
auto elapsed_ms() -> std::chrono::milliseconds {
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
std::chrono::steady_clock::now() - start_);
|
|
}
|
|
|
|
private:
|
|
std::chrono::steady_clock::time_point start_;
|
|
};
|
|
|
|
// Encapsulates test context generated by processing and running.
|
|
//
|
|
// Note this should remain internal to `FileTestBase`, not exposed to individual
|
|
// tests.
|
|
struct TestFile {
|
|
// Represents a split within the test file.
|
|
struct Split {
|
|
friend auto PrintTo(const Split& f, std::ostream* os) -> void {
|
|
// Print content escaped.
|
|
llvm::raw_os_ostream os_wrap(*os);
|
|
os_wrap << "Split(" << f.filename << ", \"" << FormatEscaped(f.content)
|
|
<< "\")";
|
|
}
|
|
|
|
std::string filename;
|
|
std::string content;
|
|
};
|
|
|
|
// The input test file content. Other parts may reference this.
|
|
std::string input_content;
|
|
|
|
// Lines which don't contain CHECKs, and thus need to be retained by
|
|
// autoupdate. Their file and line numbers are attached.
|
|
//
|
|
// If there are splits, then the splitting line is in the respective file.
|
|
// For N splits, the 0th file is the parts of the input file which are not
|
|
// in any split, plus one file per split file.
|
|
llvm::SmallVector<FileTestLine> non_check_lines;
|
|
|
|
// Whether there are splits.
|
|
bool has_splits = false;
|
|
|
|
// Arguments for the test, generated from ARGS.
|
|
llvm::SmallVector<std::string> test_args;
|
|
|
|
// Extra arguments for the test, generated from EXTRA-ARGS. Unlike ARGS,
|
|
// setting EXTRA-ARGS does not suppress the default arguments.
|
|
llvm::SmallVector<std::string> extra_args;
|
|
|
|
// Files in the test, generated by content and splits.
|
|
llvm::SmallVector<Split> file_splits;
|
|
|
|
// Files pulled in by `INCLUDE-FILE`. They're combined with `file_splits` for
|
|
// execution.
|
|
llvm::SmallVector<Split> include_file_splits;
|
|
|
|
// The location of the autoupdate marker, for autoupdated files.
|
|
std::optional<int> autoupdate_line_number;
|
|
|
|
// Whether there should be an AUTOUPDATE-SPLIT.
|
|
bool autoupdate_split = false;
|
|
|
|
// Whether to capture stderr and stdout that would head to console,
|
|
// generated from SET-CAPTURE-CONSOLE-OUTPUT.
|
|
bool capture_console_output = false;
|
|
|
|
// Whether checks are a subset, generated from SET-CHECK-SUBSET.
|
|
bool check_subset = false;
|
|
|
|
// stdout and stderr based on CHECK lines in the file.
|
|
llvm::SmallVector<testing::Matcher<std::string>> expected_stdout;
|
|
llvm::SmallVector<testing::Matcher<std::string>> expected_stderr;
|
|
|
|
// stdout and stderr from Run. 16 is arbitrary but a required value.
|
|
llvm::SmallString<16> actual_stdout;
|
|
llvm::SmallString<16> actual_stderr;
|
|
|
|
FileTestBase::RunResult run_result = {.success = false};
|
|
|
|
// Time spent inside FileTestBase::Run.
|
|
std::chrono::milliseconds run_elapsed_ms = std::chrono::milliseconds(0);
|
|
};
|
|
|
|
// Processes the test input, producing test files and expected output.
|
|
auto ProcessTestFile(llvm::StringRef test_name, bool running_autoupdate)
|
|
-> ErrorOr<TestFile>;
|
|
|
|
} // namespace Carbon::Testing
|
|
|
|
#endif // CARBON_TESTING_FILE_TEST_TEST_FILE_H_
|