2016-03-29 12:29:50 +00:00
|
|
|
#include "progress-bar.hh"
|
2016-04-25 13:26:07 +00:00
|
|
|
#include "util.hh"
|
|
|
|
#include "sync.hh"
|
2017-05-16 14:09:57 +00:00
|
|
|
#include "store-api.hh"
|
2019-05-15 15:33:56 +00:00
|
|
|
#include "names.hh"
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2017-05-16 14:09:57 +00:00
|
|
|
#include <atomic>
|
2018-02-06 19:51:37 +00:00
|
|
|
#include <map>
|
|
|
|
#include <thread>
|
2020-04-16 11:12:58 +00:00
|
|
|
#include <iostream>
|
2017-05-16 14:09:57 +00:00
|
|
|
|
2016-03-29 12:29:50 +00:00
|
|
|
namespace nix {
|
|
|
|
|
2017-08-16 15:32:18 +00:00
|
|
|
static std::string getS(const std::vector<Logger::Field> & fields, size_t n)
|
|
|
|
{
|
|
|
|
assert(n < fields.size());
|
|
|
|
assert(fields[n].type == Logger::Field::tString);
|
|
|
|
return fields[n].s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t getI(const std::vector<Logger::Field> & fields, size_t n)
|
|
|
|
{
|
|
|
|
assert(n < fields.size());
|
|
|
|
assert(fields[n].type == Logger::Field::tInt);
|
|
|
|
return fields[n].i;
|
|
|
|
}
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
static std::string_view storePathToName(std::string_view path)
|
|
|
|
{
|
|
|
|
auto base = baseNameOf(path);
|
|
|
|
auto i = base.find('-');
|
|
|
|
return i == std::string::npos ? base.substr(0, 0) : base.substr(i + 1);
|
|
|
|
}
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
class ProgressBar : public Logger
|
2016-03-29 12:29:50 +00:00
|
|
|
{
|
2016-04-25 13:26:07 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
struct ActInfo
|
|
|
|
{
|
2017-08-25 16:04:05 +00:00
|
|
|
std::string s, lastLine, phase;
|
2020-03-28 23:22:10 +00:00
|
|
|
ActivityType type = ActivityType::Unknown;
|
2017-08-14 17:00:03 +00:00
|
|
|
uint64_t done = 0;
|
|
|
|
uint64_t expected = 0;
|
2017-08-14 20:42:17 +00:00
|
|
|
uint64_t running = 0;
|
2017-08-15 13:31:59 +00:00
|
|
|
uint64_t failed = 0;
|
2017-08-14 17:00:03 +00:00
|
|
|
std::map<ActivityType, uint64_t> expectedByType;
|
2017-08-25 15:49:40 +00:00
|
|
|
bool visible = true;
|
|
|
|
ActivityId parent;
|
2019-05-15 15:33:56 +00:00
|
|
|
std::optional<std::string> name;
|
2016-03-29 12:29:50 +00:00
|
|
|
};
|
|
|
|
|
2017-08-14 17:00:03 +00:00
|
|
|
struct ActivitiesByType
|
|
|
|
{
|
2017-08-16 14:38:23 +00:00
|
|
|
std::map<ActivityId, std::list<ActInfo>::iterator> its;
|
2017-08-14 17:00:03 +00:00
|
|
|
uint64_t done = 0;
|
|
|
|
uint64_t expected = 0;
|
2017-08-15 13:31:59 +00:00
|
|
|
uint64_t failed = 0;
|
2017-08-14 17:00:03 +00:00
|
|
|
};
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
struct State
|
|
|
|
{
|
|
|
|
std::list<ActInfo> activities;
|
2017-08-16 14:38:23 +00:00
|
|
|
std::map<ActivityId, std::list<ActInfo>::iterator> its;
|
2017-08-14 17:00:03 +00:00
|
|
|
|
|
|
|
std::map<ActivityType, ActivitiesByType> activitiesByType;
|
2017-08-16 15:32:18 +00:00
|
|
|
|
|
|
|
uint64_t filesLinked = 0, bytesLinked = 0;
|
2017-08-16 17:23:46 +00:00
|
|
|
|
|
|
|
uint64_t corruptedPaths = 0, untrustedPaths = 0;
|
2017-08-29 13:13:30 +00:00
|
|
|
|
|
|
|
bool active = true;
|
2019-06-25 19:57:18 +00:00
|
|
|
bool haveUpdate = true;
|
2016-04-25 13:26:07 +00:00
|
|
|
};
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
Sync<State> state_;
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2018-02-06 19:51:37 +00:00
|
|
|
std::thread updateThread;
|
|
|
|
|
|
|
|
std::condition_variable quitCV, updateCV;
|
|
|
|
|
2019-05-15 15:33:56 +00:00
|
|
|
bool printBuildLogs;
|
|
|
|
bool isTTY;
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
public:
|
|
|
|
|
2019-05-15 15:33:56 +00:00
|
|
|
ProgressBar(bool printBuildLogs, bool isTTY)
|
|
|
|
: printBuildLogs(printBuildLogs)
|
|
|
|
, isTTY(isTTY)
|
2017-05-16 14:09:57 +00:00
|
|
|
{
|
2019-05-15 15:33:56 +00:00
|
|
|
state_.lock()->active = isTTY;
|
2018-02-06 19:51:37 +00:00
|
|
|
updateThread = std::thread([&]() {
|
|
|
|
auto state(state_.lock());
|
|
|
|
while (state->active) {
|
2019-06-25 19:57:18 +00:00
|
|
|
if (!state->haveUpdate)
|
|
|
|
state.wait(updateCV);
|
2018-02-06 19:51:37 +00:00
|
|
|
draw(*state);
|
2018-07-19 15:29:31 +00:00
|
|
|
state.wait_for(quitCV, std::chrono::milliseconds(50));
|
2018-02-06 19:51:37 +00:00
|
|
|
}
|
|
|
|
});
|
2017-05-16 14:09:57 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
~ProgressBar()
|
2017-08-29 13:13:30 +00:00
|
|
|
{
|
|
|
|
stop();
|
2018-02-06 19:51:37 +00:00
|
|
|
updateThread.join();
|
2017-08-29 13:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void stop()
|
2016-04-25 13:26:07 +00:00
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2017-08-29 13:13:30 +00:00
|
|
|
if (!state->active) return;
|
2017-08-29 14:18:00 +00:00
|
|
|
state->active = false;
|
2017-08-15 13:31:59 +00:00
|
|
|
std::string status = getStatus(*state);
|
2016-04-25 13:26:07 +00:00
|
|
|
writeToStderr("\r\e[K");
|
2017-08-15 13:31:59 +00:00
|
|
|
if (status != "")
|
|
|
|
writeToStderr("[" + status + "]\n");
|
2018-02-06 19:51:37 +00:00
|
|
|
updateCV.notify_one();
|
|
|
|
quitCV.notify_one();
|
2016-03-29 12:29:50 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
void log(Verbosity lvl, const FormatOrString & fs) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
|
|
|
log(*state, lvl, fs.s);
|
|
|
|
}
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
void log(State & state, Verbosity lvl, const std::string & s)
|
|
|
|
{
|
2019-05-15 15:33:56 +00:00
|
|
|
if (state.active) {
|
2019-10-09 21:25:06 +00:00
|
|
|
writeToStderr("\r\e[K" + filterANSIEscapes(s, !isTTY) + ANSI_NORMAL "\n");
|
2019-05-15 15:33:56 +00:00
|
|
|
draw(state);
|
|
|
|
} else {
|
|
|
|
auto s2 = s + ANSI_NORMAL "\n";
|
|
|
|
if (!isTTY) s2 = filterANSIEscapes(s2, true);
|
|
|
|
writeToStderr(s2);
|
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
2017-08-28 17:13:24 +00:00
|
|
|
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
|
|
|
const std::string & s, const Fields & fields, ActivityId parent) override
|
2017-08-16 14:38:23 +00:00
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2017-08-16 15:32:18 +00:00
|
|
|
|
2017-08-31 13:25:58 +00:00
|
|
|
if (lvl <= verbosity && !s.empty())
|
|
|
|
log(*state, lvl, s + "...");
|
|
|
|
|
2017-08-25 14:11:18 +00:00
|
|
|
state->activities.emplace_back(ActInfo());
|
2017-08-16 15:32:18 +00:00
|
|
|
auto i = std::prev(state->activities.end());
|
2017-08-25 14:11:18 +00:00
|
|
|
i->s = s;
|
|
|
|
i->type = type;
|
2017-08-25 15:49:40 +00:00
|
|
|
i->parent = parent;
|
2017-08-16 15:32:18 +00:00
|
|
|
state->its.emplace(act, i);
|
|
|
|
state->activitiesByType[type].its.emplace(act, i);
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
if (type == ActivityType::Build) {
|
2017-08-25 12:53:50 +00:00
|
|
|
auto name = storePathToName(getS(fields, 0));
|
|
|
|
if (hasSuffix(name, ".drv"))
|
2019-12-14 22:19:04 +00:00
|
|
|
name = name.substr(0, name.size() - 4);
|
2017-08-25 12:53:50 +00:00
|
|
|
i->s = fmt("building " ANSI_BOLD "%s" ANSI_NORMAL, name);
|
2017-10-24 12:24:57 +00:00
|
|
|
auto machineName = getS(fields, 1);
|
|
|
|
if (machineName != "")
|
|
|
|
i->s += fmt(" on " ANSI_BOLD "%s" ANSI_NORMAL, machineName);
|
2017-10-24 13:05:21 +00:00
|
|
|
auto curRound = getI(fields, 2);
|
|
|
|
auto nrRounds = getI(fields, 3);
|
|
|
|
if (nrRounds != 1)
|
|
|
|
i->s += fmt(" (round %d/%d)", curRound, nrRounds);
|
2019-05-15 15:33:56 +00:00
|
|
|
i->name = DrvName(name).name;
|
2017-08-25 12:53:50 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
if (type == ActivityType::Substitute) {
|
2017-08-25 15:49:40 +00:00
|
|
|
auto name = storePathToName(getS(fields, 0));
|
2018-02-05 17:32:23 +00:00
|
|
|
auto sub = getS(fields, 1);
|
|
|
|
i->s = fmt(
|
|
|
|
hasPrefix(sub, "local")
|
|
|
|
? "copying " ANSI_BOLD "%s" ANSI_NORMAL " from %s"
|
|
|
|
: "fetching " ANSI_BOLD "%s" ANSI_NORMAL " from %s",
|
|
|
|
name, sub);
|
2017-08-25 15:49:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
if (type == ActivityType::PostBuildHook) {
|
2019-07-11 18:23:03 +00:00
|
|
|
auto name = storePathToName(getS(fields, 0));
|
|
|
|
if (hasSuffix(name, ".drv"))
|
2019-12-14 22:19:04 +00:00
|
|
|
name = name.substr(0, name.size() - 4);
|
2019-07-11 18:23:03 +00:00
|
|
|
i->s = fmt("post-build " ANSI_BOLD "%s" ANSI_NORMAL, name);
|
|
|
|
i->name = DrvName(name).name;
|
|
|
|
}
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
if (type == ActivityType::QueryPathInfo) {
|
2017-08-31 13:25:58 +00:00
|
|
|
auto name = storePathToName(getS(fields, 0));
|
2017-09-27 11:21:08 +00:00
|
|
|
i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1));
|
2017-08-31 13:25:58 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
if ((type == ActivityType::Download && hasAncestor(*state, ActivityType::CopyPath, parent))
|
|
|
|
|| (type == ActivityType::Download && hasAncestor(*state, ActivityType::QueryPathInfo, parent))
|
|
|
|
|| (type == ActivityType::CopyPath && hasAncestor(*state, ActivityType::Substitute, parent)))
|
2017-08-25 15:49:40 +00:00
|
|
|
i->visible = false;
|
|
|
|
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-16 14:38:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 15:49:40 +00:00
|
|
|
/* Check whether an activity has an ancestore with the specified
|
|
|
|
type. */
|
|
|
|
bool hasAncestor(State & state, ActivityType type, ActivityId act)
|
|
|
|
{
|
|
|
|
while (act != 0) {
|
|
|
|
auto i = state.its.find(act);
|
|
|
|
if (i == state.its.end()) break;
|
|
|
|
if (i->second->type == type) return true;
|
2017-08-25 18:52:34 +00:00
|
|
|
act = i->second->parent;
|
2017-08-25 15:49:40 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-16 14:38:23 +00:00
|
|
|
void stopActivity(ActivityId act) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2017-08-16 15:32:18 +00:00
|
|
|
|
|
|
|
auto i = state->its.find(act);
|
|
|
|
if (i != state->its.end()) {
|
2017-08-31 13:25:58 +00:00
|
|
|
|
2017-08-16 15:32:18 +00:00
|
|
|
auto & actByType = state->activitiesByType[i->second->type];
|
|
|
|
actByType.done += i->second->done;
|
|
|
|
actByType.failed += i->second->failed;
|
|
|
|
|
|
|
|
for (auto & j : i->second->expectedByType)
|
|
|
|
state->activitiesByType[j.first].expected -= j.second;
|
|
|
|
|
|
|
|
actByType.its.erase(act);
|
|
|
|
state->activities.erase(i->second);
|
|
|
|
state->its.erase(i);
|
|
|
|
}
|
|
|
|
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-16 14:38:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 15:32:18 +00:00
|
|
|
void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override
|
2016-04-25 13:26:07 +00:00
|
|
|
{
|
2017-08-16 15:32:18 +00:00
|
|
|
auto state(state_.lock());
|
2017-08-14 17:00:03 +00:00
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
if (type == ResultType::FileLinked) {
|
2017-08-16 15:32:18 +00:00
|
|
|
state->filesLinked++;
|
|
|
|
state->bytesLinked += getI(fields, 0);
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-05-16 14:09:57 +00:00
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
else if (type == ResultType::BuildLogLine || type == ResultType::PostBuildLogLine) {
|
2017-08-25 16:04:05 +00:00
|
|
|
auto lastLine = trim(getS(fields, 0));
|
|
|
|
if (!lastLine.empty()) {
|
2017-08-16 15:32:18 +00:00
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
ActInfo info = *i->second;
|
2019-05-15 15:33:56 +00:00
|
|
|
if (printBuildLogs) {
|
2019-07-11 18:23:03 +00:00
|
|
|
auto suffix = "> ";
|
2020-03-28 23:22:10 +00:00
|
|
|
if (type == ResultType::PostBuildLogLine) {
|
2019-07-11 18:23:03 +00:00
|
|
|
suffix = " (post)> ";
|
|
|
|
}
|
2020-03-28 23:22:10 +00:00
|
|
|
log(*state, Verbosity::Info, ANSI_FAINT + info.name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine);
|
2019-05-15 15:33:56 +00:00
|
|
|
} else {
|
|
|
|
state->activities.erase(i->second);
|
|
|
|
info.lastLine = lastLine;
|
|
|
|
state->activities.emplace_back(info);
|
|
|
|
i->second = std::prev(state->activities.end());
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2019-05-15 15:33:56 +00:00
|
|
|
}
|
2017-08-16 15:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-16 17:23:46 +00:00
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
else if (type == ResultType::UntrustedPath) {
|
2017-08-16 17:23:46 +00:00
|
|
|
state->untrustedPaths++;
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-16 17:23:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
else if (type == ResultType::CorruptedPath) {
|
2017-08-16 17:23:46 +00:00
|
|
|
state->corruptedPaths++;
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-16 17:23:46 +00:00
|
|
|
}
|
2017-08-25 16:04:05 +00:00
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
else if (type == ResultType::SetPhase) {
|
2017-08-25 16:04:05 +00:00
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
i->second->phase = getS(fields, 0);
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-25 19:26:37 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
else if (type == ResultType::Progress) {
|
2017-08-25 19:26:37 +00:00
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
ActInfo & actInfo = *i->second;
|
|
|
|
actInfo.done = getI(fields, 0);
|
|
|
|
actInfo.expected = getI(fields, 1);
|
|
|
|
actInfo.running = getI(fields, 2);
|
|
|
|
actInfo.failed = getI(fields, 3);
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-25 16:04:05 +00:00
|
|
|
}
|
2017-08-28 12:30:35 +00:00
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
else if (type == ResultType::SetExpected) {
|
2017-08-28 12:30:35 +00:00
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
ActInfo & actInfo = *i->second;
|
|
|
|
auto type = (ActivityType) getI(fields, 0);
|
|
|
|
auto & j = actInfo.expectedByType[type];
|
|
|
|
state->activitiesByType[type].expected -= j;
|
|
|
|
j = getI(fields, 1);
|
|
|
|
state->activitiesByType[type].expected += j;
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-28 12:30:35 +00:00
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 19:57:18 +00:00
|
|
|
void update(State & state)
|
2016-04-25 13:26:07 +00:00
|
|
|
{
|
2019-06-25 19:57:18 +00:00
|
|
|
state.haveUpdate = true;
|
2018-02-06 19:51:37 +00:00
|
|
|
updateCV.notify_one();
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 19:51:37 +00:00
|
|
|
void draw(State & state)
|
2016-04-25 13:26:07 +00:00
|
|
|
{
|
2019-06-25 19:57:18 +00:00
|
|
|
state.haveUpdate = false;
|
2017-08-29 13:13:30 +00:00
|
|
|
if (!state.active) return;
|
|
|
|
|
2017-08-25 13:44:36 +00:00
|
|
|
std::string line;
|
2016-04-25 13:26:07 +00:00
|
|
|
|
|
|
|
std::string status = getStatus(state);
|
|
|
|
if (!status.empty()) {
|
|
|
|
line += '[';
|
|
|
|
line += status;
|
|
|
|
line += "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!state.activities.empty()) {
|
|
|
|
if (!status.empty()) line += " ";
|
2017-05-16 14:09:57 +00:00
|
|
|
auto i = state.activities.rbegin();
|
2017-08-14 18:14:55 +00:00
|
|
|
|
2017-08-25 16:04:05 +00:00
|
|
|
while (i != state.activities.rend() && (!i->visible || (i->s.empty() && i->lastLine.empty())))
|
2017-08-14 18:14:55 +00:00
|
|
|
++i;
|
|
|
|
|
|
|
|
if (i != state.activities.rend()) {
|
|
|
|
line += i->s;
|
2017-08-25 16:04:05 +00:00
|
|
|
if (!i->phase.empty()) {
|
|
|
|
line += " (";
|
|
|
|
line += i->phase;
|
|
|
|
line += ")";
|
|
|
|
}
|
|
|
|
if (!i->lastLine.empty()) {
|
2017-08-15 13:31:59 +00:00
|
|
|
if (!i->s.empty()) line += ": ";
|
2017-08-25 16:04:05 +00:00
|
|
|
line += i->lastLine;
|
2017-08-14 18:14:55 +00:00
|
|
|
}
|
2017-05-16 14:09:57 +00:00
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 14:19:10 +00:00
|
|
|
auto width = getWindowSize().second;
|
2019-11-03 21:46:59 +00:00
|
|
|
if (width <= 0) width = std::numeric_limits<decltype(width)>::max();
|
2018-02-07 14:19:10 +00:00
|
|
|
|
2018-03-15 15:08:07 +00:00
|
|
|
writeToStderr("\r" + filterANSIEscapes(line, false, width) + "\e[K");
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string getStatus(State & state)
|
|
|
|
{
|
2017-08-14 17:00:03 +00:00
|
|
|
auto MiB = 1024.0 * 1024.0;
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
std::string res;
|
2017-05-16 14:09:57 +00:00
|
|
|
|
2017-08-16 15:00:24 +00:00
|
|
|
auto renderActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
|
2017-08-14 18:14:55 +00:00
|
|
|
auto & act = state.activitiesByType[type];
|
2017-08-15 13:31:59 +00:00
|
|
|
uint64_t done = act.done, expected = act.done, running = 0, failed = act.failed;
|
2017-08-14 18:14:55 +00:00
|
|
|
for (auto & j : act.its) {
|
|
|
|
done += j.second->done;
|
|
|
|
expected += j.second->expected;
|
2017-08-14 20:42:17 +00:00
|
|
|
running += j.second->running;
|
2017-08-15 13:31:59 +00:00
|
|
|
failed += j.second->failed;
|
2017-08-14 18:14:55 +00:00
|
|
|
}
|
2017-08-14 17:00:03 +00:00
|
|
|
|
2017-08-14 18:14:55 +00:00
|
|
|
expected = std::max(expected, act.expected);
|
2017-08-14 17:00:03 +00:00
|
|
|
|
2017-08-15 13:31:59 +00:00
|
|
|
std::string s;
|
|
|
|
|
|
|
|
if (running || done || expected || failed) {
|
|
|
|
if (running)
|
2019-05-06 20:23:15 +00:00
|
|
|
if (expected != 0)
|
|
|
|
s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
|
|
|
|
running / unit, done / unit, expected / unit);
|
|
|
|
else
|
|
|
|
s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL,
|
|
|
|
running / unit, done / unit);
|
2017-08-15 13:31:59 +00:00
|
|
|
else if (expected != done)
|
2019-05-06 20:23:15 +00:00
|
|
|
if (expected != 0)
|
|
|
|
s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
|
|
|
|
done / unit, expected / unit);
|
|
|
|
else
|
|
|
|
s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL, done / unit);
|
2017-08-15 13:31:59 +00:00
|
|
|
else
|
|
|
|
s = fmt(done ? ANSI_GREEN + numberFmt + ANSI_NORMAL : numberFmt, done / unit);
|
|
|
|
s = fmt(itemFmt, s);
|
|
|
|
|
|
|
|
if (failed)
|
|
|
|
s += fmt(" (" ANSI_RED "%d failed" ANSI_NORMAL ")", failed / unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
2017-08-16 15:00:24 +00:00
|
|
|
auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
|
2017-08-15 13:31:59 +00:00
|
|
|
auto s = renderActivity(type, itemFmt, numberFmt, unit);
|
|
|
|
if (s.empty()) return;
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += s;
|
2017-08-14 18:14:55 +00:00
|
|
|
};
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
showActivity(ActivityType::Builds, "%s built");
|
2017-08-15 13:31:59 +00:00
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
auto s1 = renderActivity(ActivityType::CopyPaths, "%s copied");
|
|
|
|
auto s2 = renderActivity(ActivityType::CopyPath, "%s MiB", "%.1f", MiB);
|
2017-08-15 13:31:59 +00:00
|
|
|
|
|
|
|
if (!s1.empty() || !s2.empty()) {
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
if (s1.empty()) res += "0 copied"; else res += s1;
|
|
|
|
if (!s2.empty()) { res += " ("; res += s2; res += ')'; }
|
|
|
|
}
|
|
|
|
|
2020-03-28 23:22:10 +00:00
|
|
|
showActivity(ActivityType::Download, "%s MiB DL", "%.1f", MiB);
|
2017-08-14 17:00:03 +00:00
|
|
|
|
2017-08-16 15:32:18 +00:00
|
|
|
{
|
2020-03-28 23:22:10 +00:00
|
|
|
auto s = renderActivity(ActivityType::OptimiseStore, "%s paths optimised");
|
2017-08-16 15:32:18 +00:00
|
|
|
if (s != "") {
|
|
|
|
s += fmt(", %.1f MiB / %d inodes freed", state.bytesLinked / MiB, state.filesLinked);
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += s;
|
|
|
|
}
|
|
|
|
}
|
2017-08-16 15:00:24 +00:00
|
|
|
|
2017-08-16 17:23:46 +00:00
|
|
|
// FIXME: don't show "done" paths in green.
|
2020-03-28 23:22:10 +00:00
|
|
|
showActivity(ActivityType::VerifyPaths, "%s paths verified");
|
2017-08-16 17:23:46 +00:00
|
|
|
|
|
|
|
if (state.corruptedPaths) {
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += fmt(ANSI_RED "%d corrupted" ANSI_NORMAL, state.corruptedPaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.untrustedPaths) {
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += fmt(ANSI_RED "%d untrusted" ANSI_NORMAL, state.untrustedPaths);
|
|
|
|
}
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
return res;
|
|
|
|
}
|
2020-04-16 11:12:58 +00:00
|
|
|
|
|
|
|
void writeToStdout(std::string_view s) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
|
|
|
if (state->active) {
|
|
|
|
std::cerr << "\r\e[K";
|
|
|
|
Logger::writeToStdout(s);
|
|
|
|
draw(*state);
|
|
|
|
} else {
|
|
|
|
Logger::writeToStdout(s);
|
|
|
|
}
|
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
};
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2019-05-15 15:33:56 +00:00
|
|
|
void startProgressBar(bool printBuildLogs)
|
2016-03-29 12:29:50 +00:00
|
|
|
{
|
2020-02-18 16:47:53 +00:00
|
|
|
logger = new ProgressBar(
|
|
|
|
printBuildLogs,
|
|
|
|
isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb");
|
2016-03-29 12:29:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 13:13:30 +00:00
|
|
|
void stopProgressBar()
|
2016-03-29 12:29:50 +00:00
|
|
|
{
|
2017-08-29 13:13:30 +00:00
|
|
|
auto progressBar = dynamic_cast<ProgressBar *>(logger);
|
|
|
|
if (progressBar) progressBar->stop();
|
|
|
|
|
2016-03-29 12:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|