forked from lix-project/lix
Progress indicator: Show number of active items
This commit is contained in:
parent
0e0dcf2c7e
commit
bf1f123b09
|
@ -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. */
|
/* The worker class. */
|
||||||
class Worker
|
class Worker
|
||||||
{
|
{
|
||||||
|
@ -271,6 +261,7 @@ public:
|
||||||
|
|
||||||
uint64_t expectedSubstitutions = 0;
|
uint64_t expectedSubstitutions = 0;
|
||||||
uint64_t doneSubstitutions = 0;
|
uint64_t doneSubstitutions = 0;
|
||||||
|
uint64_t runningSubstitutions = 0;
|
||||||
uint64_t expectedDownloadSize = 0;
|
uint64_t expectedDownloadSize = 0;
|
||||||
uint64_t doneDownloadSize = 0;
|
uint64_t doneDownloadSize = 0;
|
||||||
uint64_t expectedNarSize = 0;
|
uint64_t expectedNarSize = 0;
|
||||||
|
@ -337,7 +328,7 @@ public:
|
||||||
|
|
||||||
void updateProgress()
|
void updateProgress()
|
||||||
{
|
{
|
||||||
actSubstitutions.progress(doneSubstitutions, expectedSubstitutions + doneSubstitutions);
|
actSubstitutions.progress(doneSubstitutions, expectedSubstitutions + doneSubstitutions, runningSubstitutions);
|
||||||
logger->event(evSetExpected, act, actDownload, expectedDownloadSize + doneDownloadSize);
|
logger->event(evSetExpected, act, actDownload, expectedDownloadSize + doneDownloadSize);
|
||||||
logger->event(evSetExpected, act, actCopyPath, expectedNarSize + doneNarSize);
|
logger->event(evSetExpected, act, actCopyPath, expectedNarSize + doneNarSize);
|
||||||
}
|
}
|
||||||
|
@ -3333,7 +3324,7 @@ private:
|
||||||
Path destPath;
|
Path destPath;
|
||||||
|
|
||||||
std::unique_ptr<MaintainCount<uint64_t>> maintainExpectedSubstitutions,
|
std::unique_ptr<MaintainCount<uint64_t>> maintainExpectedSubstitutions,
|
||||||
maintainExpectedNar, maintainExpectedDownload;
|
maintainRunningSubstitutions, maintainExpectedNar, maintainExpectedDownload;
|
||||||
|
|
||||||
typedef void (SubstitutionGoal::*GoalState)();
|
typedef void (SubstitutionGoal::*GoalState)();
|
||||||
GoalState state;
|
GoalState state;
|
||||||
|
@ -3531,6 +3522,9 @@ void SubstitutionGoal::tryToRun()
|
||||||
|
|
||||||
printInfo(format("fetching path '%1%'...") % storePath);
|
printInfo(format("fetching path '%1%'...") % storePath);
|
||||||
|
|
||||||
|
maintainRunningSubstitutions = std::make_unique<MaintainCount<uint64_t>>(worker.runningSubstitutions);
|
||||||
|
worker.updateProgress();
|
||||||
|
|
||||||
outPipe.create();
|
outPipe.create();
|
||||||
|
|
||||||
promise = std::promise<void>();
|
promise = std::promise<void>();
|
||||||
|
@ -3578,6 +3572,8 @@ void SubstitutionGoal::finished()
|
||||||
printMsg(lvlChatty,
|
printMsg(lvlChatty,
|
||||||
format("substitution of path '%1%' succeeded") % storePath);
|
format("substitution of path '%1%' succeeded") % storePath);
|
||||||
|
|
||||||
|
maintainRunningSubstitutions.reset();
|
||||||
|
|
||||||
maintainExpectedSubstitutions.reset();
|
maintainExpectedSubstitutions.reset();
|
||||||
worker.doneSubstitutions++;
|
worker.doneSubstitutions++;
|
||||||
|
|
||||||
|
|
|
@ -625,9 +625,10 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const PathSet & storePa
|
||||||
|
|
||||||
std::atomic<size_t> nrDone{0};
|
std::atomic<size_t> nrDone{0};
|
||||||
std::atomic<uint64_t> bytesExpected{0};
|
std::atomic<uint64_t> bytesExpected{0};
|
||||||
|
std::atomic<uint64_t> nrRunning{0};
|
||||||
|
|
||||||
auto showProgress = [&]() {
|
auto showProgress = [&]() {
|
||||||
act.progress(nrDone, missing.size());
|
act.progress(nrDone, missing.size(), nrRunning);
|
||||||
};
|
};
|
||||||
|
|
||||||
ThreadPool pool;
|
ThreadPool pool;
|
||||||
|
@ -655,6 +656,8 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const PathSet & storePa
|
||||||
|
|
||||||
if (!dstStore->isValidPath(storePath)) {
|
if (!dstStore->isValidPath(storePath)) {
|
||||||
printInfo("copying '%s'...", storePath);
|
printInfo("copying '%s'...", storePath);
|
||||||
|
MaintainCount<decltype(nrRunning)> mc(nrRunning);
|
||||||
|
showProgress();
|
||||||
copyStorePath(srcStore, dstStore, storePath, repair, checkSigs);
|
copyStorePath(srcStore, dstStore, storePath, repair, checkSigs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,4 +91,9 @@ Activity::~Activity()
|
||||||
logger->event(evStopActivity, id);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,7 @@ public:
|
||||||
Activity(ActivityType type, std::string msg = "");
|
Activity(ActivityType type, std::string msg = "");
|
||||||
~Activity();
|
~Activity();
|
||||||
|
|
||||||
template<typename... Args>
|
void progress(uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0) const;
|
||||||
void progress(const Args & ... args) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -146,14 +145,4 @@ void warnOnce(bool & haveWarned, const FormatOrString & fs);
|
||||||
|
|
||||||
void writeToStderr(const string & s);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ template<typename... Args>
|
||||||
inline std::string fmt(const std::string & fs, Args... args)
|
inline std::string fmt(const std::string & fs, Args... args)
|
||||||
{
|
{
|
||||||
boost::format f(fs);
|
boost::format f(fs);
|
||||||
|
f.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
|
||||||
nop{boost::io::detail::feed(f, args)...};
|
nop{boost::io::detail::feed(f, args)...};
|
||||||
return f.str();
|
return f.str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ private:
|
||||||
ActivityType type = actUnknown;
|
ActivityType type = actUnknown;
|
||||||
uint64_t done = 0;
|
uint64_t done = 0;
|
||||||
uint64_t expected = 0;
|
uint64_t expected = 0;
|
||||||
|
uint64_t running = 0;
|
||||||
std::map<ActivityType, uint64_t> expectedByType;
|
std::map<ActivityType, uint64_t> expectedByType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -174,19 +175,20 @@ public:
|
||||||
|
|
||||||
auto showActivity = [&](ActivityType type, const std::string & f, double unit) {
|
auto showActivity = [&](ActivityType type, const std::string & f, double unit) {
|
||||||
auto & act = state.activitiesByType[type];
|
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) {
|
for (auto & j : act.its) {
|
||||||
done += j.second->done;
|
done += j.second->done;
|
||||||
expected += j.second->expected;
|
expected += j.second->expected;
|
||||||
|
running += j.second->running;
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = std::max(expected, act.expected);
|
expected = std::max(expected, act.expected);
|
||||||
|
|
||||||
if (done || 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(actDownload, "%1$.1f/%2$.1f MiB DL", MiB);
|
||||||
showActivity(actCopyPath, "%1$.1f/%2$.1f MiB copied", MiB);
|
showActivity(actCopyPath, "%1$.1f/%2$.1f MiB copied", MiB);
|
||||||
|
|
||||||
|
@ -213,6 +215,7 @@ public:
|
||||||
ActInfo & actInfo = *i->second;
|
ActInfo & actInfo = *i->second;
|
||||||
actInfo.done = ev.getI(1);
|
actInfo.done = ev.getI(1);
|
||||||
actInfo.expected = ev.getI(2);
|
actInfo.expected = ev.getI(2);
|
||||||
|
actInfo.running = ev.getI(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.type == evSetExpected) {
|
if (ev.type == evSetExpected) {
|
||||||
|
|
Loading…
Reference in a new issue