aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build/worker.hh
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-08-30 19:01:30 +0200
committereldritch horrors <pennae@lix.systems>2024-08-30 19:01:30 +0200
commite0fd0ba211b38827627218424f92b7d0e059a626 (patch)
tree0b0b1cf1f32302f683d7ab1bcd1a7469fc6a3e3c /src/libstore/build/worker.hh
parentc2b90d235fb5dd721898d8d41d73a51607654890 (diff)
libstore: use notifications for stats counters
updating statistics *immediately* when any counter changes declutters things somewhat and makes useful status reports less dependent on the current worker main loop. using callbacks will make it easier to move the worker loop into kj entirely, using only promises for scheduling. Change-Id: I695dfa83111b1ec09b1a54cff268f3c1d7743ed6
Diffstat (limited to 'src/libstore/build/worker.hh')
-rw-r--r--src/libstore/build/worker.hh42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/libstore/build/worker.hh b/src/libstore/build/worker.hh
index 3fbf457fe..9a6ed8449 100644
--- a/src/libstore/build/worker.hh
+++ b/src/libstore/build/worker.hh
@@ -1,6 +1,7 @@
#pragma once
///@file
+#include "notifying-counter.hh"
#include "types.hh"
#include "lock.hh"
#include "store-api.hh"
@@ -213,6 +214,21 @@ private:
void childStarted(GoalPtr goal, const std::set<int> & fds,
bool inBuildSlot);
+ /**
+ * Pass current stats counters to the logger for progress bar updates.
+ */
+ void updateStatistics();
+
+ bool statisticsOutdated = true;
+
+ /**
+ * Mark statistics as outdated, such that `updateStatistics` will be called.
+ */
+ void updateStatisticsLater()
+ {
+ statisticsOutdated = true;
+ }
+
public:
const Activity act;
@@ -234,19 +250,19 @@ public:
HookState hook;
- uint64_t expectedBuilds = 0;
- uint64_t doneBuilds = 0;
- uint64_t failedBuilds = 0;
- uint64_t runningBuilds = 0;
-
- uint64_t expectedSubstitutions = 0;
- uint64_t doneSubstitutions = 0;
- uint64_t failedSubstitutions = 0;
- uint64_t runningSubstitutions = 0;
- uint64_t expectedDownloadSize = 0;
- uint64_t doneDownloadSize = 0;
- uint64_t expectedNarSize = 0;
- uint64_t doneNarSize = 0;
+ NotifyingCounter<uint64_t> expectedBuilds{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> doneBuilds{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> failedBuilds{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> runningBuilds{[this] { updateStatisticsLater(); }};
+
+ NotifyingCounter<uint64_t> expectedSubstitutions{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> doneSubstitutions{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> failedSubstitutions{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> runningSubstitutions{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> expectedDownloadSize{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> doneDownloadSize{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> expectedNarSize{[this] { updateStatisticsLater(); }};
+ NotifyingCounter<uint64_t> doneNarSize{[this] { updateStatisticsLater(); }};
Worker(Store & store, Store & evalStore);
~Worker();