From bf1f123b09ec7402b0565808619e11b5bfe6b16b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 14 Aug 2017 22:42:17 +0200 Subject: [PATCH] Progress indicator: Show number of active items --- src/libstore/build.cc | 20 ++++++++------------ src/libstore/store-api.cc | 5 ++++- src/libutil/logging.cc | 5 +++++ src/libutil/logging.hh | 13 +------------ src/libutil/types.hh | 1 + src/libutil/util.hh | 14 ++++++++++++++ src/nix/progress-bar.cc | 9 ++++++--- 7 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 9ea4e4b88..a45ca8923 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -202,16 +202,6 @@ struct Child }; -template -struct MaintainCount -{ - T & counter; - T delta; - MaintainCount(T & counter, T delta = 1) : counter(counter), delta(delta) { counter += delta; } - ~MaintainCount() { counter -= delta; } -}; - - /* The worker class. */ class Worker { @@ -271,6 +261,7 @@ public: uint64_t expectedSubstitutions = 0; uint64_t doneSubstitutions = 0; + uint64_t runningSubstitutions = 0; uint64_t expectedDownloadSize = 0; uint64_t doneDownloadSize = 0; uint64_t expectedNarSize = 0; @@ -337,7 +328,7 @@ public: void updateProgress() { - actSubstitutions.progress(doneSubstitutions, expectedSubstitutions + doneSubstitutions); + actSubstitutions.progress(doneSubstitutions, expectedSubstitutions + doneSubstitutions, runningSubstitutions); logger->event(evSetExpected, act, actDownload, expectedDownloadSize + doneDownloadSize); logger->event(evSetExpected, act, actCopyPath, expectedNarSize + doneNarSize); } @@ -3333,7 +3324,7 @@ private: Path destPath; std::unique_ptr> maintainExpectedSubstitutions, - maintainExpectedNar, maintainExpectedDownload; + maintainRunningSubstitutions, maintainExpectedNar, maintainExpectedDownload; typedef void (SubstitutionGoal::*GoalState)(); GoalState state; @@ -3531,6 +3522,9 @@ void SubstitutionGoal::tryToRun() printInfo(format("fetching path '%1%'...") % storePath); + maintainRunningSubstitutions = std::make_unique>(worker.runningSubstitutions); + worker.updateProgress(); + outPipe.create(); promise = std::promise(); @@ -3578,6 +3572,8 @@ void SubstitutionGoal::finished() printMsg(lvlChatty, format("substitution of path '%1%' succeeded") % storePath); + maintainRunningSubstitutions.reset(); + maintainExpectedSubstitutions.reset(); worker.doneSubstitutions++; diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 1e11e54eb..5aa3dcfd2 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -625,9 +625,10 @@ void copyPaths(ref srcStore, ref dstStore, const PathSet & storePa std::atomic nrDone{0}; std::atomic bytesExpected{0}; + std::atomic nrRunning{0}; auto showProgress = [&]() { - act.progress(nrDone, missing.size()); + act.progress(nrDone, missing.size(), nrRunning); }; ThreadPool pool; @@ -655,6 +656,8 @@ void copyPaths(ref srcStore, ref dstStore, const PathSet & storePa if (!dstStore->isValidPath(storePath)) { printInfo("copying '%s'...", storePath); + MaintainCount mc(nrRunning); + showProgress(); copyStorePath(srcStore, dstStore, storePath, repair, checkSigs); } diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 321c90712..ed83770a1 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -91,4 +91,9 @@ Activity::~Activity() logger->event(evStopActivity, id); } +void Activity::progress(uint64_t done, uint64_t expected, uint64_t running, uint64_t failed) const +{ + logger->event(evProgress, id, done, expected, running, failed); +} + } diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index f3ff099f0..b6ab3d7d3 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -32,8 +32,7 @@ public: Activity(ActivityType type, std::string msg = ""); ~Activity(); - template - void progress(const Args & ... args) const; + void progress(uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0) const; }; typedef enum { @@ -146,14 +145,4 @@ void warnOnce(bool & haveWarned, const FormatOrString & fs); void writeToStderr(const string & s); -template -void Activity::progress(const Args & ... args) const -{ - Event ev; - ev.type = evProgress; - ev.fields.emplace_back(id); - nop{(ev.fields.emplace_back(Event::Field(args)), 1)...}; - logger->event(ev); -} - } diff --git a/src/libutil/types.hh b/src/libutil/types.hh index 9f32d31ad..92bf469b5 100644 --- a/src/libutil/types.hh +++ b/src/libutil/types.hh @@ -70,6 +70,7 @@ template inline std::string fmt(const std::string & fs, Args... args) { boost::format f(fs); + f.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); nop{boost::io::detail::feed(f, args)...}; return f.str(); } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index f37f2c5d1..35909c8d5 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -462,4 +462,18 @@ struct ReceiveInterrupts { } }; + + +/* A RAII helper that increments a counter on construction and + decrements it on destruction. */ +template +struct MaintainCount +{ + T & counter; + long delta; + MaintainCount(T & counter, long delta = 1) : counter(counter), delta(delta) { counter += delta; } + ~MaintainCount() { counter -= delta; } +}; + + } diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc index 21d89e477..f4fc79fca 100644 --- a/src/nix/progress-bar.cc +++ b/src/nix/progress-bar.cc @@ -22,6 +22,7 @@ private: ActivityType type = actUnknown; uint64_t done = 0; uint64_t expected = 0; + uint64_t running = 0; std::map expectedByType; }; @@ -174,19 +175,20 @@ public: auto showActivity = [&](ActivityType type, const std::string & f, double unit) { auto & act = state.activitiesByType[type]; - uint64_t done = act.done, expected = act.done; + uint64_t done = act.done, expected = act.done, running = 0; for (auto & j : act.its) { done += j.second->done; expected += j.second->expected; + running += j.second->running; } expected = std::max(expected, act.expected); if (done || expected) - add(fmt(f, done / unit, expected / unit)); + add(fmt(f, done / unit, expected / unit, running)); }; - showActivity(actCopyPaths, ANSI_GREEN "%d" ANSI_NORMAL "/%d copied", 1); + showActivity(actCopyPaths, ANSI_BLUE "%3$d" ANSI_NORMAL "/" ANSI_GREEN "%1$d" ANSI_NORMAL "/%2$d copied", 1); showActivity(actDownload, "%1$.1f/%2$.1f MiB DL", MiB); showActivity(actCopyPath, "%1$.1f/%2$.1f MiB copied", MiB); @@ -213,6 +215,7 @@ public: ActInfo & actInfo = *i->second; actInfo.done = ev.getI(1); actInfo.expected = ev.getI(2); + actInfo.running = ev.getI(3); } if (ev.type == evSetExpected) {