1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 04:21:16 +02:00

Progress indicator: Show number of active items

This commit is contained in:
Eelco Dolstra 2017-08-14 22:42:17 +02:00
parent 0e0dcf2c7e
commit bf1f123b09
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
7 changed files with 39 additions and 28 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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();
}

View file

@ -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; }
};
}