From bf1f123b09ec7402b0565808619e11b5bfe6b16b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 14 Aug 2017 22:42:17 +0200 Subject: Progress indicator: Show number of active items --- src/libutil/logging.cc | 5 +++++ src/libutil/logging.hh | 13 +------------ src/libutil/types.hh | 1 + src/libutil/util.hh | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 12 deletions(-) (limited to 'src/libutil') 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 - 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 9f32d31addbf..92bf469b5c6f 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 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 +struct MaintainCount +{ + T & counter; + long delta; + MaintainCount(T & counter, long delta = 1) : counter(counter), delta(delta) { counter += delta; } + ~MaintainCount() { counter -= delta; } +}; + + } -- cgit 1.4.1