about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libstore/build.cc20
-rw-r--r--src/libstore/store-api.cc5
-rw-r--r--src/libutil/logging.cc5
-rw-r--r--src/libutil/logging.hh13
-rw-r--r--src/libutil/types.hh1
-rw-r--r--src/libutil/util.hh14
-rw-r--r--src/nix/progress-bar.cc9
7 files changed, 39 insertions, 28 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 9ea4e4b88ef9..a45ca8923016 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -202,16 +202,6 @@ struct Child
 };
 
 
-template<typename T>
-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<MaintainCount<uint64_t>> 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<MaintainCount<uint64_t>>(worker.runningSubstitutions);
+    worker.updateProgress();
+
     outPipe.create();
 
     promise = std::promise<void>();
@@ -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 1e11e54eba7c..5aa3dcfd26a3 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -625,9 +625,10 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const PathSet & storePa
 
     std::atomic<size_t> nrDone{0};
     std::atomic<uint64_t> bytesExpected{0};
+    std::atomic<uint64_t> nrRunning{0};
 
     auto showProgress = [&]() {
-        act.progress(nrDone, missing.size());
+        act.progress(nrDone, missing.size(), nrRunning);
     };
 
     ThreadPool pool;
@@ -655,6 +656,8 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const PathSet & storePa
 
             if (!dstStore->isValidPath(storePath)) {
                 printInfo("copying '%s'...", storePath);
+                MaintainCount<decltype(nrRunning)> mc(nrRunning);
+                showProgress();
                 copyStorePath(srcStore, dstStore, storePath, repair, checkSigs);
             }
 
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc
index 321c90712917..ed83770a14aa 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 f3ff099f0cec..b6ab3d7d3b8f 100644
--- a/src/libutil/logging.hh
+++ b/src/libutil/logging.hh
@@ -32,8 +32,7 @@ public:
     Activity(ActivityType type, std::string msg = "");
     ~Activity();
 
-    template<typename... Args>
-    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<typename... Args>
-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 9f32d31addbf..92bf469b5c6f 100644
--- a/src/libutil/types.hh
+++ b/src/libutil/types.hh
@@ -70,6 +70,7 @@ template<typename... Args>
 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 f37f2c5d1be5..35909c8d5b31 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<typename T>
+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 21d89e47709e..f4fc79fca160 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<ActivityType, uint64_t> 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) {