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.cc | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/libstore/build/worker.cc') diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc index 7336ad50f..24c700396 100644 --- a/src/libstore/build/worker.cc +++ b/src/libstore/build/worker.cc @@ -320,6 +320,27 @@ void Worker::waitForAWhile(GoalPtr goal) } +void Worker::updateStatistics() +{ + // only update progress info while running. this notably excludes updating + // progress info while destroying, which causes the progress bar to assert + if (running && statisticsOutdated) { + actDerivations.progress( + doneBuilds, expectedBuilds + doneBuilds, runningBuilds, failedBuilds + ); + actSubstitutions.progress( + doneSubstitutions, + expectedSubstitutions + doneSubstitutions, + runningSubstitutions, + failedSubstitutions + ); + act.setExpected(actFileTransfer, expectedDownloadSize + doneDownloadSize); + act.setExpected(actCopyPath, expectedNarSize + doneNarSize); + + statisticsOutdated = false; + } +} + Goals Worker::run(std::function req) { auto _topGoals = req(goalFactory()); @@ -329,6 +350,8 @@ Goals Worker::run(std::function req) running = true; Finally const _stop([&] { running = false; }); + updateStatistics(); + for (auto & i : _topGoals) { topGoals.insert(i); if (auto goal = dynamic_cast(i.get())) { @@ -373,18 +396,7 @@ Goals Worker::run(std::function req) ? nrSubstitutions < std::max(1U, (unsigned int) settings.maxSubstitutionJobs) : nrLocalBuilds < settings.maxBuildJobs; handleWorkResult(goal, goal->work(inSlot)); - - actDerivations.progress( - doneBuilds, expectedBuilds + doneBuilds, runningBuilds, failedBuilds - ); - actSubstitutions.progress( - doneSubstitutions, - expectedSubstitutions + doneSubstitutions, - runningSubstitutions, - failedSubstitutions - ); - act.setExpected(actFileTransfer, expectedDownloadSize + doneDownloadSize); - act.setExpected(actCopyPath, expectedNarSize + doneNarSize); + updateStatistics(); if (topGoals.empty()) break; // stuff may have been cancelled } -- cgit v1.2.3