summaryrefslogtreecommitdiff
path: root/src/buildtool/progress_reporting/progress_reporter.cpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-03-07 15:44:28 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-03-11 15:59:05 +0100
commit5f6ff55e97104e46c1b5c2c94b39ea0fca35ca7c (patch)
tree9a8a70d311f2c55c20f426258455f9fb3037328a /src/buildtool/progress_reporting/progress_reporter.cpp
parentb885deebf9fc02b9f1e849d91de93fadcfb71a73 (diff)
downloadjustbuild-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/progress_reporting/progress_reporter.cpp')
-rw-r--r--src/buildtool/progress_reporting/progress_reporter.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/buildtool/progress_reporting/progress_reporter.cpp b/src/buildtool/progress_reporting/progress_reporter.cpp
index 86ec0c0e..27960172 100644
--- a/src/buildtool/progress_reporting/progress_reporter.cpp
+++ b/src/buildtool/progress_reporting/progress_reporter.cpp
@@ -17,25 +17,23 @@
#include <string>
#include "fmt/core.h"
-#include "gsl/gsl"
-#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
-#include "src/buildtool/progress_reporting/progress.hpp"
-auto ProgressReporter::Reporter() noexcept -> progress_reporter_t {
- return BaseProgressReporter::Reporter([]() {
- int total = gsl::narrow<int>(Progress::Instance().OriginMap().size());
+auto ProgressReporter::Reporter(
+ gsl::not_null<Statistics*> const& stats,
+ gsl::not_null<Progress*> const& progress) noexcept -> progress_reporter_t {
+ return BaseProgressReporter::Reporter([stats, progress]() {
+ int total = gsl::narrow<int>(progress->OriginMap().size());
// Note: order matters; queued has to be queried last
- auto const& sample = Progress::Instance().TaskTracker().Sample();
- auto const& stats = Statistics::Instance();
- int cached = stats.ActionsCachedCounter();
- int run = stats.ActionsExecutedCounter();
- int queued = stats.ActionsQueuedCounter();
+ auto const& sample = progress->TaskTracker().Sample();
+ int cached = stats->ActionsCachedCounter();
+ int run = stats->ActionsExecutedCounter();
+ int queued = stats->ActionsQueuedCounter();
int active = queued - run - cached;
std::string now_msg;
if (active > 0 and !sample.empty()) {
- auto const& origin_map = Progress::Instance().OriginMap();
+ auto const& origin_map = progress->OriginMap();
auto origins = origin_map.find(sample);
if (origins != origin_map.end() and !origins->second.empty()) {
auto const& origin = origins->second[0];