diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-03-07 15:44:28 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-03-11 15:59:05 +0100 |
commit | 5f6ff55e97104e46c1b5c2c94b39ea0fca35ca7c (patch) | |
tree | 9a8a70d311f2c55c20f426258455f9fb3037328a /src/buildtool/main/main.cpp | |
parent | b885deebf9fc02b9f1e849d91de93fadcfb71a73 (diff) | |
download | justbuild-5f6ff55e97104e46c1b5c2c94b39ea0fca35ca7c.tar.gz |
just: Replace singletons for progress tracking and statistics...
...with regular instances that have controlled life-times.
This avoids race conditions in tracking and reporting the results
of analysis and build, as the serve endpoint can orchestrate
multiple builds at the same time asynchronously. As a bonus
side-effect this also ensures the correctness of the progress
reporting per orchestrated build.
Diffstat (limited to 'src/buildtool/main/main.cpp')
-rw-r--r-- | src/buildtool/main/main.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 642251c4..65f5278d 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -55,6 +55,7 @@ #include "src/buildtool/serve_api/serve_service/serve_server_implementation.hpp" #include "src/buildtool/storage/garbage_collector.hpp" #endif // BOOTSTRAP_BUILD_TOOL +#include "src/buildtool/common/statistics.hpp" #include "src/buildtool/logging/log_config.hpp" #include "src/buildtool/logging/log_sink_cmdline.hpp" #include "src/buildtool/logging/log_sink_file.hpp" @@ -62,6 +63,7 @@ #include "src/buildtool/main/version.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/progress_reporting/progress.hpp" #include "src/utils/cpp/concepts.hpp" #include "src/utils/cpp/json.hpp" @@ -913,6 +915,11 @@ auto main(int argc, char* argv[]) -> int { ? std::make_optional(std::move(arguments.rebuild)) : std::nullopt; + // statistics and progress instances; need to be kept alive + // used also in bootstrapped just + Statistics stats{}; + Progress progress{}; + #ifndef BOOTSTRAP_BUILD_TOOL SetupRetryConfig(arguments.retry); GraphTraverser const traverser{ @@ -923,7 +930,9 @@ auto main(int argc, char* argv[]) -> int { &repo_config, RemoteExecutionConfig::PlatformProperties(), RemoteExecutionConfig::DispatchList(), - ProgressReporter::Reporter()}; + &stats, + &progress, + ProgressReporter::Reporter(&stats, &progress)}; if (arguments.cmd == SubCommand::kInstallCas) { if (not repo_config.SetGitCAS(StorageConfig::GitRoot())) { @@ -999,11 +1008,13 @@ auto main(int argc, char* argv[]) -> int { &result_map, &repo_config, Storage::Instance().TargetCache(), + &stats, arguments.common.jobs, arguments.analysis.request_action_input); if (result) { if (arguments.analysis.graph_file) { - result_map.ToFile(*arguments.analysis.graph_file); + result_map.ToFile( + *arguments.analysis.graph_file, &stats, &progress); } auto const [artifacts, runfiles] = ReadOutputArtifacts(result->target); @@ -1028,11 +1039,10 @@ auto main(int argc, char* argv[]) -> int { "Analysed target {}", result->id.ToString()); - auto const& stat = Statistics::Instance(); { - auto cached = stat.ExportsCachedCounter(); - auto uncached = stat.ExportsUncachedCounter(); - auto not_eligible = stat.ExportsNotEligibleCounter(); + auto cached = stats.ExportsCachedCounter(); + auto uncached = stats.ExportsUncachedCounter(); + auto not_eligible = stats.ExportsNotEligibleCounter(); Logger::Log(cached + uncached + not_eligible > 0 ? LogLevel::Info : LogLevel::Debug, @@ -1044,7 +1054,8 @@ auto main(int argc, char* argv[]) -> int { } ReportTaintedness(*result); - auto const& [actions, blobs, trees] = result_map.ToResult(); + auto const& [actions, blobs, trees] = + result_map.ToResult(&stats, &progress); // collect cache targets and artifacts for target-level caching auto const cache_targets = result_map.CacheTargets(); |