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

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

View file

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

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

View file

@ -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) {