Implement VoidBuildSystem v1 (Plans 01-19) with VoidLibrary integration
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
This commit is contained in:
1 parent
3cac890ce9
commit
ab64147f9d
114 files changed
+23777
-1392
No files matched your search
@@ -0,0 +1,129 @@
|
||||
#include <Void/Build/Execution/Scheduler.hpp>
|
||||
#include <Void/Build/Graph/Graph.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Snapshot/Snapshot.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
#include <Void/Build/Toolchain/Driver.hpp>
|
||||
#include <Void/Configuration/Argparse.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Text/Str.hpp>
|
||||
#include <Void/Time/Stopwatch.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
using namespace Void::Build;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::string files_opt;
|
||||
std::string jobs_opt;
|
||||
Void::Argparse::Parser parser{
|
||||
"vbs_benchmarks",
|
||||
"Run reproducible snapshot, cold build, and warm no-op timings for VoidBuildSystem."};
|
||||
parser.option_default("--files", "-n", "number of generated source units", files_opt, "20")
|
||||
.option_default("--jobs", "-j", "parallel worker count", jobs_opt, "4");
|
||||
|
||||
// Preserve positional shorthand `vbs_benchmarks 15` alongside `--files 15`.
|
||||
if (argc == 2 && (std::string_view{argv[1]} == "--help" || std::string_view{argv[1]} == "-h")) {
|
||||
std::cout << parser.help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parsed_files = 20;
|
||||
int parsed_jobs = 4;
|
||||
if (argc == 2 && Void::Str::to_int(argv[1], parsed_files)) {
|
||||
if (parsed_files <= 0) {
|
||||
std::cerr << "vbs_benchmarks: file count must be positive\n";
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
auto parsed = parser.parse(argc, argv);
|
||||
if (!parsed) {
|
||||
std::cerr << "vbs_benchmarks: " << parsed.error() << '\n';
|
||||
return 2;
|
||||
}
|
||||
if (!Void::Str::to_int(files_opt, parsed_files) || parsed_files <= 0) {
|
||||
std::cerr << "vbs_benchmarks: invalid --files value '" << files_opt << "'\n";
|
||||
return 2;
|
||||
}
|
||||
if (!Void::Str::to_int(jobs_opt, parsed_jobs) || parsed_jobs <= 0) {
|
||||
std::cerr << "vbs_benchmarks: invalid --jobs value '" << jobs_opt << "'\n";
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
const auto file_count = static_cast<std::size_t>(parsed_files);
|
||||
const auto jobs = static_cast<std::size_t>(parsed_jobs);
|
||||
|
||||
Void::FileSystem::TempDir tmp{"vbs_bench_"};
|
||||
const auto proj = tmp / "proj";
|
||||
const auto build_dir = tmp / "build";
|
||||
|
||||
std::string main_cpp = "int main() {\n int sum = 0;\n";
|
||||
for (std::size_t i = 0; i < file_count; ++i) {
|
||||
const std::string fn = "f_" + std::to_string(i);
|
||||
(void)Platform::atomic_write_file(proj / "include" / (fn + ".hpp"),
|
||||
"#pragma once\nint " + fn + "();\n", false);
|
||||
(void)Platform::atomic_write_file(proj / "src" / (fn + ".cpp"),
|
||||
"#include \"" + fn + ".hpp\"\nint " + fn +
|
||||
"() { return " + std::to_string(i) + "; }\n",
|
||||
false);
|
||||
main_cpp = "#include \"" + fn + ".hpp\"\n" + main_cpp;
|
||||
main_cpp += " sum += " + fn + "();\n";
|
||||
}
|
||||
main_cpp += " return sum == 0 ? 0 : 0;\n}\n";
|
||||
(void)Platform::atomic_write_file(proj / "src" / "main.cpp", main_cpp, false);
|
||||
|
||||
auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(),
|
||||
Toolchain::host_architecture_name());
|
||||
auto tc = Toolchain::discover_and_probe(ctx, build_dir / ".vbs" / "probes");
|
||||
if (!tc) {
|
||||
std::cerr << "bench toolchain error: " << tc.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
Graph::ProjectDescription desc;
|
||||
desc.profile = ctx;
|
||||
TargetRecord app;
|
||||
app.name = "bench_app";
|
||||
app.kind = TargetKind::Executable;
|
||||
app.sources.push_back({SourceKind::Glob, "src/*.cpp"});
|
||||
app.include_directories.push_back({"include", Visibility::Private, false});
|
||||
desc.targets.push_back(std::move(app));
|
||||
|
||||
auto snap_sw = Void::Time::Stopwatch::started();
|
||||
Snapshot::SnapshotOptions sopts{
|
||||
proj, build_dir / ".vbs" / "snapshots", {}, {".git", "build"}, 0, 5, true};
|
||||
auto snap = Snapshot::capture_snapshot(sopts, {}, {proj / "src", proj / "include"});
|
||||
const auto snap_ms = snap_sw.elapsed_as<std::chrono::milliseconds>().count();
|
||||
if (!snap) {
|
||||
std::cerr << "bench snapshot error: " << snap.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto graph = Graph::lower_project_graph(desc, *tc, {proj, build_dir, &(*snap), {}, 32768});
|
||||
auto state = State::StateStore::open(build_dir / ".vbs");
|
||||
if (!graph || !state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto cold_sw = Void::Time::Stopwatch::started();
|
||||
auto cold = Execution::execute_graph(*graph, *state, {jobs, true, true, {}, {}, {}});
|
||||
const auto cold_ms = cold_sw.elapsed_as<std::chrono::milliseconds>().count();
|
||||
|
||||
auto warm_sw = Void::Time::Stopwatch::started();
|
||||
auto warm = Execution::execute_graph(*graph, *state, {jobs, true, true, {}, {}, {}});
|
||||
const auto warm_ms = warm_sw.elapsed_as<std::chrono::milliseconds>().count();
|
||||
|
||||
std::cout << "{\"fixture_files\":" << (file_count + 1) << ",\"compiler\":\""
|
||||
<< tc->version_banner << "\""
|
||||
<< ",\"snapshot_ms\":" << snap_ms << ",\"cold_build_ms\":" << cold_ms
|
||||
<< ",\"cold_executed\":" << (cold ? cold->executed_count : 0)
|
||||
<< ",\"warm_noop_ms\":" << warm_ms
|
||||
<< ",\"warm_executed\":" << (warm ? warm->executed_count : 0)
|
||||
<< ",\"warm_cached\":" << (warm ? warm->cached_count : 0) << "}\n";
|
||||
return (cold && cold->succeeded && warm && warm->succeeded) ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user