From e0fd0ba211b38827627218424f92b7d0e059a626 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 30 Aug 2024 19:01:30 +0200 Subject: 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 --- src/libstore/build/worker.hh | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src/libstore/build/worker.hh') 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 & 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 expectedBuilds{[this] { updateStatisticsLater(); }}; + NotifyingCounter doneBuilds{[this] { updateStatisticsLater(); }}; + NotifyingCounter failedBuilds{[this] { updateStatisticsLater(); }}; + NotifyingCounter runningBuilds{[this] { updateStatisticsLater(); }}; + + NotifyingCounter expectedSubstitutions{[this] { updateStatisticsLater(); }}; + NotifyingCounter doneSubstitutions{[this] { updateStatisticsLater(); }}; + NotifyingCounter failedSubstitutions{[this] { updateStatisticsLater(); }}; + NotifyingCounter runningSubstitutions{[this] { updateStatisticsLater(); }}; + NotifyingCounter expectedDownloadSize{[this] { updateStatisticsLater(); }}; + NotifyingCounter doneDownloadSize{[this] { updateStatisticsLater(); }}; + NotifyingCounter expectedNarSize{[this] { updateStatisticsLater(); }}; + NotifyingCounter doneNarSize{[this] { updateStatisticsLater(); }}; Worker(Store & store, Store & evalStore); ~Worker(); -- cgit v1.2.3