Skip to content

Commit 2cc345b

Browse files
committed
Give activities a verbosity level again
And print them (separately from the progress bar) given sufficient -v flags.
1 parent cfc8132 commit 2cc345b

File tree

10 files changed

+41
-19
lines changed

10 files changed

+41
-19
lines changed

src/libstore/build.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ void DerivationGoal::tryToBuild()
13901390
bool buildLocally = buildMode != bmNormal || drv->willBuildLocally();
13911391

13921392
auto started = [&]() {
1393-
act = std::make_unique<Activity>(*logger, actBuild,
1393+
act = std::make_unique<Activity>(*logger, lvlInfo, actBuild,
13941394
fmt("building '%s'", drvPath), Logger::Fields{drvPath});
13951395
mcRunningBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.runningBuilds);
13961396
worker.updateProgress();
@@ -2419,12 +2419,13 @@ struct BuilderLogger : Logger
24192419
prevLogger.log(lvl, fs);
24202420
}
24212421

2422-
void startActivity(ActivityId act, ActivityType type,
2422+
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
24232423
const std::string & s, const Fields & fields, ActivityId parent) override
24242424
{
24252425
nlohmann::json json;
24262426
json["action"] = "start";
24272427
json["id"] = act;
2428+
json["level"] = lvl;
24282429
json["type"] = type;
24292430
json["text"] = s;
24302431
addFields(json, fields);
@@ -3339,7 +3340,8 @@ void DerivationGoal::flushLine()
33393340
if (type == actDownload)
33403341
builderActivities.emplace(std::piecewise_construct,
33413342
std::forward_as_tuple(json["id"]),
3342-
std::forward_as_tuple(*logger, type, json["text"], getFields(json["fields"]), act->id));
3343+
std::forward_as_tuple(*logger, (Verbosity) json["level"], type,
3344+
json["text"], getFields(json["fields"]), act->id));
33433345
}
33443346

33453347
else if (action == "stop")
@@ -3686,7 +3688,7 @@ void SubstitutionGoal::tryToRun()
36863688
/* Wake up the worker loop when we're done. */
36873689
Finally updateStats([this]() { outPipe.writeSide = -1; });
36883690

3689-
Activity act(*logger, actSubstitute, "", Logger::Fields{storePath, sub->getUri()});
3691+
Activity act(*logger, actSubstitute, Logger::Fields{storePath, sub->getUri()});
36903692
PushActivity pact(act.id);
36913693

36923694
copyStorePath(ref<Store>(sub), ref<Store>(worker.store.shared_from_this()),

src/libstore/download.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct CurlDownloader : public Downloader
8585
DownloadItem(CurlDownloader & downloader, const DownloadRequest & request)
8686
: downloader(downloader)
8787
, request(request)
88-
, act(*logger, actDownload, fmt("downloading '%s'", request.uri), {}, request.parentAct)
88+
, act(*logger, lvlTalkative, actDownload, fmt("downloading '%s'", request.uri), {}, request.parentAct)
8989
{
9090
if (!request.expectedETag.empty())
9191
requestHeaders = curl_slist_append(requestHeaders, ("If-None-Match: " + request.expectedETag).c_str());

src/libstore/optimise-store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void LocalStore::optimiseStore(OptimiseStats & stats)
266266
addTempRoot(i);
267267
if (!isValidPath(i)) continue; /* path was GC'ed, probably */
268268
{
269-
Activity act(*logger, actUnknown, fmt("optimising path '%s'", i));
269+
Activity act(*logger, lvlTalkative, actUnknown, fmt("optimising path '%s'", i));
270270
optimisePath_(&act, stats, realStoreDir + "/" + baseNameOf(i), inodeHash);
271271
}
272272
done++;

src/libstore/remote-store.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,12 @@ void RemoteStore::Connection::processStderr(Sink * sink, Source * source)
679679

680680
else if (msg == STDERR_START_ACTIVITY) {
681681
auto act = readNum<ActivityId>(from);
682+
auto lvl = (Verbosity) readInt(from);
682683
auto type = (ActivityType) readInt(from);
683684
auto s = readString(from);
684685
auto fields = readFields(from);
685686
auto parent = readNum<ActivityId>(from);
686-
logger->startActivity(act, type, s, fields, parent);
687+
logger->startActivity(act, lvl, type, s, fields, parent);
687688
}
688689

689690
else if (msg == STDERR_STOP_ACTIVITY) {

src/libstore/store-api.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ void Store::buildPaths(const PathSet & paths, BuildMode buildMode)
565565
void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
566566
const Path & storePath, RepairFlag repair, CheckSigsFlag checkSigs)
567567
{
568-
Activity act(*logger, actCopyPath, fmt("copying path '%s'", storePath),
568+
Activity act(*logger, lvlInfo, actCopyPath, fmt("copying path '%s'", storePath),
569569
{storePath, srcStore->getUri(), dstStore->getUri()});
570570
PushActivity pact(act.id);
571571

@@ -623,7 +623,7 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const PathSet & storePa
623623
for (auto & path : storePaths)
624624
if (!valid.count(path)) missing.insert(path);
625625

626-
Activity act(*logger, actCopyPaths, fmt("copying %d paths", missing.size()));
626+
Activity act(*logger, lvlInfo, actCopyPaths, fmt("copying %d paths", missing.size()));
627627

628628
std::atomic<size_t> nrDone{0};
629629
std::atomic<uint64_t> bytesExpected{0};

src/libutil/logging.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class SimpleLogger : public Logger
4545

4646
writeToStderr(prefix + (tty ? fs.s : filterANSIEscapes(fs.s)) + "\n");
4747
}
48+
49+
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
50+
const std::string & s, const Fields & fields, ActivityId parent)
51+
{
52+
if (lvl <= verbosity && !s.empty())
53+
log(lvl, s + "...");
54+
}
4855
};
4956

5057
Verbosity verbosity = lvlInfo;
@@ -76,11 +83,11 @@ Logger * makeDefaultLogger()
7683

7784
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
7885

79-
Activity::Activity(Logger & logger, ActivityType type,
86+
Activity::Activity(Logger & logger, Verbosity lvl, ActivityType type,
8087
const std::string & s, const Logger::Fields & fields, ActivityId parent)
8188
: logger(logger), id(nextId++)
8289
{
83-
logger.startActivity(id, type, s, fields, parent);
90+
logger.startActivity(id, lvl, type, s, fields, parent);
8491
}
8592

8693
}

src/libutil/logging.hh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public:
6868

6969
virtual void warn(const std::string & msg);
7070

71-
virtual void startActivity(ActivityId act, ActivityType type,
71+
virtual void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
7272
const std::string & s, const Fields & fields, ActivityId parent) { };
7373

7474
virtual void stopActivity(ActivityId act) { };
@@ -84,9 +84,13 @@ struct Activity
8484

8585
const ActivityId id;
8686

87-
Activity(Logger & logger, ActivityType type, const std::string & s = "",
87+
Activity(Logger & logger, Verbosity lvl, ActivityType type, const std::string & s = "",
8888
const Logger::Fields & fields = {}, ActivityId parent = curActivity);
8989

90+
Activity(Logger & logger, ActivityType type,
91+
const Logger::Fields & fields = {}, ActivityId parent = curActivity)
92+
: Activity(logger, lvlError, type, "", fields, parent) { };
93+
9094
Activity(const Activity & act) = delete;
9195

9296
~Activity()

src/nix-daemon/nix-daemon.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ struct TunnelLogger : public Logger
149149
}
150150
}
151151

152-
void startActivity(ActivityId act, ActivityType type,
152+
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
153153
const std::string & s, const Fields & fields, ActivityId parent) override
154154
{
155-
if (GET_PROTOCOL_MINOR(clientVersion) < 20) return;
155+
if (GET_PROTOCOL_MINOR(clientVersion) < 20) {
156+
if (!s.empty())
157+
log(lvl, s + "...");
158+
return;
159+
}
160+
156161
StringSink buf;
157-
buf << STDERR_START_ACTIVITY << act << type << s << fields << parent;
162+
buf << STDERR_START_ACTIVITY << act << lvl << type << s << fields << parent;
158163
enqueueMsg(*buf.s);
159164
}
160165

src/nix/progress-bar.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,12 @@ class ProgressBar : public Logger
126126
update(state);
127127
}
128128

129-
void startActivity(ActivityId act, ActivityType type, const std::string & s,
130-
const Fields & fields, ActivityId parent) override
129+
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
130+
const std::string & s, const Fields & fields, ActivityId parent) override
131131
{
132+
if (lvl <= verbosity && !s.empty())
133+
log(lvl, s + "...");
134+
132135
auto state(state_.lock());
133136

134137
state->activities.emplace_back(ActInfo());

src/nix/verify.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct CmdVerify : StorePathsCommand
7979
try {
8080
checkInterrupt();
8181

82-
Activity act2(*logger, actUnknown, fmt("checking '%s'", storePath));
82+
Activity act2(*logger, lvlInfo, actUnknown, fmt("checking '%s'", storePath));
8383

8484
MaintainCount<std::atomic<size_t>> mcActive(active);
8585
update();

0 commit comments

Comments
 (0)