about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-08-14T20·42+0200
committerEelco Dolstra <edolstra@gmail.com>2017-08-16T18·56+0200
commitbf1f123b09ec7402b0565808619e11b5bfe6b16b (patch)
treed0e4c9af039b8bf05244f648907c21274ee37054 /src/libutil
parent0e0dcf2c7ec054f1b30629e275f53f56039b8257 (diff)
Progress indicator: Show number of active items
Diffstat (limited to 'src/libutil')
-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
4 files changed, 21 insertions, 12 deletions
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; }
+};
+
+
 }