Give activities a verbosity level again

And print them (separately from the progress bar) given sufficient -v
flags.
This commit is contained in:
Eelco Dolstra 2017-08-28 19:13:24 +02:00
parent cfc8132391
commit 2cc345b95f
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
10 changed files with 41 additions and 19 deletions

View file

@ -1390,7 +1390,7 @@ void DerivationGoal::tryToBuild()
bool buildLocally = buildMode != bmNormal || drv->willBuildLocally(); bool buildLocally = buildMode != bmNormal || drv->willBuildLocally();
auto started = [&]() { auto started = [&]() {
act = std::make_unique<Activity>(*logger, actBuild, act = std::make_unique<Activity>(*logger, lvlInfo, actBuild,
fmt("building '%s'", drvPath), Logger::Fields{drvPath}); fmt("building '%s'", drvPath), Logger::Fields{drvPath});
mcRunningBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.runningBuilds); mcRunningBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.runningBuilds);
worker.updateProgress(); worker.updateProgress();
@ -2419,12 +2419,13 @@ struct BuilderLogger : Logger
prevLogger.log(lvl, fs); prevLogger.log(lvl, fs);
} }
void startActivity(ActivityId act, ActivityType type, void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
const std::string & s, const Fields & fields, ActivityId parent) override const std::string & s, const Fields & fields, ActivityId parent) override
{ {
nlohmann::json json; nlohmann::json json;
json["action"] = "start"; json["action"] = "start";
json["id"] = act; json["id"] = act;
json["level"] = lvl;
json["type"] = type; json["type"] = type;
json["text"] = s; json["text"] = s;
addFields(json, fields); addFields(json, fields);
@ -3339,7 +3340,8 @@ void DerivationGoal::flushLine()
if (type == actDownload) if (type == actDownload)
builderActivities.emplace(std::piecewise_construct, builderActivities.emplace(std::piecewise_construct,
std::forward_as_tuple(json["id"]), std::forward_as_tuple(json["id"]),
std::forward_as_tuple(*logger, type, json["text"], getFields(json["fields"]), act->id)); std::forward_as_tuple(*logger, (Verbosity) json["level"], type,
json["text"], getFields(json["fields"]), act->id));
} }
else if (action == "stop") else if (action == "stop")
@ -3686,7 +3688,7 @@ void SubstitutionGoal::tryToRun()
/* Wake up the worker loop when we're done. */ /* Wake up the worker loop when we're done. */
Finally updateStats([this]() { outPipe.writeSide = -1; }); Finally updateStats([this]() { outPipe.writeSide = -1; });
Activity act(*logger, actSubstitute, "", Logger::Fields{storePath, sub->getUri()}); Activity act(*logger, actSubstitute, Logger::Fields{storePath, sub->getUri()});
PushActivity pact(act.id); PushActivity pact(act.id);
copyStorePath(ref<Store>(sub), ref<Store>(worker.store.shared_from_this()), copyStorePath(ref<Store>(sub), ref<Store>(worker.store.shared_from_this()),

View file

@ -85,7 +85,7 @@ struct CurlDownloader : public Downloader
DownloadItem(CurlDownloader & downloader, const DownloadRequest & request) DownloadItem(CurlDownloader & downloader, const DownloadRequest & request)
: downloader(downloader) : downloader(downloader)
, request(request) , request(request)
, act(*logger, actDownload, fmt("downloading '%s'", request.uri), {}, request.parentAct) , act(*logger, lvlTalkative, actDownload, fmt("downloading '%s'", request.uri), {}, request.parentAct)
{ {
if (!request.expectedETag.empty()) if (!request.expectedETag.empty())
requestHeaders = curl_slist_append(requestHeaders, ("If-None-Match: " + request.expectedETag).c_str()); requestHeaders = curl_slist_append(requestHeaders, ("If-None-Match: " + request.expectedETag).c_str());

View file

@ -266,7 +266,7 @@ void LocalStore::optimiseStore(OptimiseStats & stats)
addTempRoot(i); addTempRoot(i);
if (!isValidPath(i)) continue; /* path was GC'ed, probably */ if (!isValidPath(i)) continue; /* path was GC'ed, probably */
{ {
Activity act(*logger, actUnknown, fmt("optimising path '%s'", i)); Activity act(*logger, lvlTalkative, actUnknown, fmt("optimising path '%s'", i));
optimisePath_(&act, stats, realStoreDir + "/" + baseNameOf(i), inodeHash); optimisePath_(&act, stats, realStoreDir + "/" + baseNameOf(i), inodeHash);
} }
done++; done++;

View file

@ -679,11 +679,12 @@ void RemoteStore::Connection::processStderr(Sink * sink, Source * source)
else if (msg == STDERR_START_ACTIVITY) { else if (msg == STDERR_START_ACTIVITY) {
auto act = readNum<ActivityId>(from); auto act = readNum<ActivityId>(from);
auto lvl = (Verbosity) readInt(from);
auto type = (ActivityType) readInt(from); auto type = (ActivityType) readInt(from);
auto s = readString(from); auto s = readString(from);
auto fields = readFields(from); auto fields = readFields(from);
auto parent = readNum<ActivityId>(from); auto parent = readNum<ActivityId>(from);
logger->startActivity(act, type, s, fields, parent); logger->startActivity(act, lvl, type, s, fields, parent);
} }
else if (msg == STDERR_STOP_ACTIVITY) { else if (msg == STDERR_STOP_ACTIVITY) {

View file

@ -565,7 +565,7 @@ void Store::buildPaths(const PathSet & paths, BuildMode buildMode)
void copyStorePath(ref<Store> srcStore, ref<Store> dstStore, void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
const Path & storePath, RepairFlag repair, CheckSigsFlag checkSigs) const Path & storePath, RepairFlag repair, CheckSigsFlag checkSigs)
{ {
Activity act(*logger, actCopyPath, fmt("copying path '%s'", storePath), Activity act(*logger, lvlInfo, actCopyPath, fmt("copying path '%s'", storePath),
{storePath, srcStore->getUri(), dstStore->getUri()}); {storePath, srcStore->getUri(), dstStore->getUri()});
PushActivity pact(act.id); PushActivity pact(act.id);
@ -623,7 +623,7 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const PathSet & storePa
for (auto & path : storePaths) for (auto & path : storePaths)
if (!valid.count(path)) missing.insert(path); if (!valid.count(path)) missing.insert(path);
Activity act(*logger, actCopyPaths, fmt("copying %d paths", missing.size())); Activity act(*logger, lvlInfo, actCopyPaths, fmt("copying %d paths", missing.size()));
std::atomic<size_t> nrDone{0}; std::atomic<size_t> nrDone{0};
std::atomic<uint64_t> bytesExpected{0}; std::atomic<uint64_t> bytesExpected{0};

View file

@ -45,6 +45,13 @@ public:
writeToStderr(prefix + (tty ? fs.s : filterANSIEscapes(fs.s)) + "\n"); writeToStderr(prefix + (tty ? fs.s : filterANSIEscapes(fs.s)) + "\n");
} }
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
const std::string & s, const Fields & fields, ActivityId parent)
{
if (lvl <= verbosity && !s.empty())
log(lvl, s + "...");
}
}; };
Verbosity verbosity = lvlInfo; Verbosity verbosity = lvlInfo;
@ -76,11 +83,11 @@ Logger * makeDefaultLogger()
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32}; std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
Activity::Activity(Logger & logger, ActivityType type, Activity::Activity(Logger & logger, Verbosity lvl, ActivityType type,
const std::string & s, const Logger::Fields & fields, ActivityId parent) const std::string & s, const Logger::Fields & fields, ActivityId parent)
: logger(logger), id(nextId++) : logger(logger), id(nextId++)
{ {
logger.startActivity(id, type, s, fields, parent); logger.startActivity(id, lvl, type, s, fields, parent);
} }
} }

View file

@ -68,7 +68,7 @@ public:
virtual void warn(const std::string & msg); virtual void warn(const std::string & msg);
virtual void startActivity(ActivityId act, ActivityType type, virtual void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
const std::string & s, const Fields & fields, ActivityId parent) { }; const std::string & s, const Fields & fields, ActivityId parent) { };
virtual void stopActivity(ActivityId act) { }; virtual void stopActivity(ActivityId act) { };
@ -84,9 +84,13 @@ struct Activity
const ActivityId id; const ActivityId id;
Activity(Logger & logger, ActivityType type, const std::string & s = "", Activity(Logger & logger, Verbosity lvl, ActivityType type, const std::string & s = "",
const Logger::Fields & fields = {}, ActivityId parent = curActivity); const Logger::Fields & fields = {}, ActivityId parent = curActivity);
Activity(Logger & logger, ActivityType type,
const Logger::Fields & fields = {}, ActivityId parent = curActivity)
: Activity(logger, lvlError, type, "", fields, parent) { };
Activity(const Activity & act) = delete; Activity(const Activity & act) = delete;
~Activity() ~Activity()

View file

@ -149,12 +149,17 @@ struct TunnelLogger : public Logger
} }
} }
void startActivity(ActivityId act, ActivityType type, void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
const std::string & s, const Fields & fields, ActivityId parent) override const std::string & s, const Fields & fields, ActivityId parent) override
{ {
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return; if (GET_PROTOCOL_MINOR(clientVersion) < 20) {
if (!s.empty())
log(lvl, s + "...");
return;
}
StringSink buf; StringSink buf;
buf << STDERR_START_ACTIVITY << act << type << s << fields << parent; buf << STDERR_START_ACTIVITY << act << lvl << type << s << fields << parent;
enqueueMsg(*buf.s); enqueueMsg(*buf.s);
} }

View file

@ -126,9 +126,12 @@ public:
update(state); update(state);
} }
void startActivity(ActivityId act, ActivityType type, const std::string & s, void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
const Fields & fields, ActivityId parent) override const std::string & s, const Fields & fields, ActivityId parent) override
{ {
if (lvl <= verbosity && !s.empty())
log(lvl, s + "...");
auto state(state_.lock()); auto state(state_.lock());
state->activities.emplace_back(ActInfo()); state->activities.emplace_back(ActInfo());

View file

@ -79,7 +79,7 @@ struct CmdVerify : StorePathsCommand
try { try {
checkInterrupt(); checkInterrupt();
Activity act2(*logger, actUnknown, fmt("checking '%s'", storePath)); Activity act2(*logger, lvlInfo, actUnknown, fmt("checking '%s'", storePath));
MaintainCount<std::atomic<size_t>> mcActive(active); MaintainCount<std::atomic<size_t>> mcActive(active);
update(); update();