libutil: wrap activity updates in macros
we'll eventually want to yield to flush buffers from the non-sync versions. Change-Id: I8bcbb1c4c8af39c7d7ebf5a76e1ce1dc98067e00
This commit is contained in:
@@ -892,7 +892,7 @@ try {
|
||||
const std::string_view data{buffer.data(), *got};
|
||||
for (auto c : data) {
|
||||
if (c == '\n') {
|
||||
act.result(resPostBuildLogLine, currentLine);
|
||||
ACTIVITY_RESULT(act, resPostBuildLogLine, currentLine);
|
||||
currentLine.clear();
|
||||
} else {
|
||||
currentLine += c;
|
||||
@@ -902,7 +902,7 @@ try {
|
||||
|
||||
if (currentLine != "") {
|
||||
currentLine += '\n';
|
||||
act.result(resPostBuildLogLine, currentLine);
|
||||
ACTIVITY_RESULT(act, resPostBuildLogLine, currentLine);
|
||||
}
|
||||
|
||||
wait.run();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "lix/libutil/finally.hh"
|
||||
#include "lix/libstore/build/substitution-goal.hh"
|
||||
#include "lix/libstore/build/local-derivation-goal.hh"
|
||||
#include "lix/libutil/logging.hh"
|
||||
#include "lix/libutil/signals.hh"
|
||||
#include "lix/libstore/build/hook-instance.hh" // IWYU pragma: keep
|
||||
#include <boost/outcome/try.hpp>
|
||||
@@ -290,17 +291,18 @@ try {
|
||||
|
||||
// only update progress info while running. this notably excludes updating
|
||||
// progress info while destroying, which causes the progress bar to assert
|
||||
actDerivations.progress(
|
||||
doneBuilds, expectedBuilds + doneBuilds, runningBuilds, failedBuilds
|
||||
ACTIVITY_PROGRESS(
|
||||
actDerivations, doneBuilds, expectedBuilds + doneBuilds, runningBuilds, failedBuilds
|
||||
);
|
||||
actSubstitutions.progress(
|
||||
ACTIVITY_PROGRESS(
|
||||
actSubstitutions,
|
||||
doneSubstitutions,
|
||||
expectedSubstitutions + doneSubstitutions,
|
||||
runningSubstitutions,
|
||||
failedSubstitutions
|
||||
);
|
||||
act.setExpected(actFileTransfer, expectedDownloadSize + doneDownloadSize);
|
||||
act.setExpected(actCopyPath, expectedNarSize + doneNarSize);
|
||||
ACTIVITY_SET_EXPECTED(act, actFileTransfer, expectedDownloadSize + doneDownloadSize);
|
||||
ACTIVITY_SET_EXPECTED(act, actCopyPath, expectedNarSize + doneNarSize);
|
||||
|
||||
// limit to 50fps. that should be more than good enough for anything we do
|
||||
co_await AIO().provider.getTimer().afterDelay(20 * kj::MILLISECONDS);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "lix/libstore/globals.hh"
|
||||
#include "lix/libutil/async.hh"
|
||||
#include "lix/libutil/c-calls.hh"
|
||||
#include "lix/libutil/logging.hh"
|
||||
#include "lix/libutil/result.hh"
|
||||
#include "lix/libutil/signals.hh"
|
||||
#include "lix/libutil/strings.hh"
|
||||
@@ -272,7 +273,7 @@ try {
|
||||
auto paths = TRY_AWAIT(queryAllValidPaths());
|
||||
InodeHash inodeHash = loadInodeHash();
|
||||
|
||||
act.progress(0, paths.size());
|
||||
ACTIVITY_PROGRESS(act, 0, paths.size());
|
||||
|
||||
uint64_t done = 0;
|
||||
|
||||
@@ -292,7 +293,7 @@ try {
|
||||
);
|
||||
}
|
||||
done++;
|
||||
act.progress(done, paths.size());
|
||||
ACTIVITY_PROGRESS(act, done, paths.size());
|
||||
}
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
|
||||
@@ -826,7 +826,7 @@ try {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
act->result(type, fields);
|
||||
ACTIVITY_RESULT(*act, type, fields);
|
||||
} else if (msg == STDERR_LAST) {
|
||||
break;
|
||||
} else {
|
||||
|
||||
+11
-10
@@ -332,9 +332,7 @@ try {
|
||||
storePathsToAdd.insert(thingToAdd.first.path);
|
||||
}
|
||||
|
||||
auto showProgress = [&]() {
|
||||
act.progress(nrDone, pathsToCopy.size(), nrRunning, nrFailed);
|
||||
};
|
||||
#define SHOW_PROGRESS() ACTIVITY_PROGRESS(act, nrDone, pathsToCopy.size(), nrRunning, nrFailed)
|
||||
|
||||
TRY_AWAIT(processGraphAsync<StorePath>(
|
||||
storePathsToAdd,
|
||||
@@ -346,12 +344,12 @@ try {
|
||||
|
||||
if (TRY_AWAIT(isValidPath(info.path))) {
|
||||
nrDone++;
|
||||
showProgress();
|
||||
SHOW_PROGRESS();
|
||||
co_return StorePathSet();
|
||||
}
|
||||
|
||||
bytesExpected += info.narSize;
|
||||
act.setExpected(actCopyPath, bytesExpected);
|
||||
ACTIVITY_SET_EXPECTED(act, actCopyPath, bytesExpected);
|
||||
|
||||
co_return info.references;
|
||||
} catch (...) {
|
||||
@@ -377,7 +375,7 @@ try {
|
||||
|
||||
if (!TRY_AWAIT(isValidPath(info.path))) {
|
||||
MaintainCount<decltype(nrRunning)> mc(nrRunning);
|
||||
showProgress();
|
||||
SHOW_PROGRESS();
|
||||
try {
|
||||
TRY_AWAIT(addToStore(info, *TRY_AWAIT(source()), repair, checkSigs));
|
||||
} catch (Error & e) {
|
||||
@@ -385,19 +383,22 @@ try {
|
||||
if (!settings.keepGoing)
|
||||
throw e;
|
||||
printMsg(lvlError, "could not copy %s: %s", printStorePath(path), e.what());
|
||||
showProgress();
|
||||
SHOW_PROGRESS();
|
||||
co_return result::success();
|
||||
}
|
||||
}
|
||||
|
||||
nrDone++;
|
||||
showProgress();
|
||||
SHOW_PROGRESS();
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
}));
|
||||
}
|
||||
));
|
||||
co_return result::success();
|
||||
|
||||
#undef SHOW_PROGRESS
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
@@ -1007,7 +1008,7 @@ struct CopyPathStream : AsyncInputStream
|
||||
copied += *result;
|
||||
}
|
||||
if (doLog) {
|
||||
act.progress(copied, expected);
|
||||
ACTIVITY_PROGRESS(act, copied, expected);
|
||||
}
|
||||
co_return result;
|
||||
} catch (...) {
|
||||
|
||||
@@ -265,6 +265,38 @@ Logger * makeJSONLogger(Logger & prevLogger);
|
||||
*/
|
||||
extern Verbosity verbosity;
|
||||
|
||||
#define ACTIVITY_PROGRESS(act, ...) \
|
||||
do { \
|
||||
auto && _lix_act = (act); \
|
||||
_lix_act.progress(__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define ACTIVITY_RESULT(act, ...) \
|
||||
do { \
|
||||
auto && _lix_act = (act); \
|
||||
_lix_act.result(__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define ACTIVITY_SET_EXPECTED(act, ...) \
|
||||
do { \
|
||||
auto && _lix_act = (act); \
|
||||
_lix_act.setExpected(__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define ACTIVITY_PROGRESS_SYNC(aio, act, ...) \
|
||||
do { \
|
||||
auto && _lix_act = (act); \
|
||||
_lix_act.progress(__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define ACTIVITY_RESULT_SYNC(aio, act, ...) \
|
||||
do { \
|
||||
auto && _lix_act = (act); \
|
||||
_lix_act.result(__VA_ARGS__); \
|
||||
} while (0)
|
||||
#define ACTIVITY_SET_EXPECTED_SYNC(aio, act, ...) \
|
||||
do { \
|
||||
auto && _lix_act = (act); \
|
||||
_lix_act.setExpected(__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* Print a message with the standard ErrorInfo format.
|
||||
* In general, use these 'log' macros for reporting problems that may require user
|
||||
|
||||
+8
-3
@@ -2,6 +2,7 @@
|
||||
#include "lix/libmain/shared.hh"
|
||||
#include "lix/libstore/store-api.hh"
|
||||
#include "lix/libutil/async.hh"
|
||||
#include "lix/libutil/logging.hh"
|
||||
#include "lix/libutil/thread-pool.hh"
|
||||
#include "lix/libutil/signals.hh"
|
||||
#include "lix/libutil/exit.hh"
|
||||
@@ -79,7 +80,7 @@ struct CmdVerify : StorePathsCommand
|
||||
std::atomic<size_t> active{0};
|
||||
|
||||
auto update = [&]() {
|
||||
act.progress(done, storePaths.size(), active, failed);
|
||||
ACTIVITY_PROGRESS_SYNC(aio(), act, done, storePaths.size(), active, failed);
|
||||
};
|
||||
|
||||
ThreadPool pool{"Verify pool"};
|
||||
@@ -110,7 +111,9 @@ struct CmdVerify : StorePathsCommand
|
||||
|
||||
if (hash.first != info->narHash) {
|
||||
corrupted++;
|
||||
act2.result(resCorruptedPath, store->printStorePath(info->path));
|
||||
ACTIVITY_RESULT_SYNC(
|
||||
aio, act2, resCorruptedPath, store->printStorePath(info->path)
|
||||
);
|
||||
printError("path '%s' was modified! expected hash '%s', got '%s'",
|
||||
store->printStorePath(info->path),
|
||||
info->narHash.to_string(Base::SRI, true),
|
||||
@@ -163,7 +166,9 @@ struct CmdVerify : StorePathsCommand
|
||||
|
||||
if (!good) {
|
||||
untrusted++;
|
||||
act2.result(resUntrustedPath, store->printStorePath(info->path));
|
||||
ACTIVITY_RESULT_SYNC(
|
||||
aio, act2, resUntrustedPath, store->printStorePath(info->path)
|
||||
);
|
||||
printError("path '%s' is untrusted", store->printStorePath(info->path));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user