mirror of
https://github.com/NixOS/nix
synced 2025-06-28 13:41:15 +02:00
worker protocol: serialise cgroup stats in BuildResult
(#9598)
By doing so, they get reported when building through the daemon via either `unix://` or `ssh-ng://`.
This commit is contained in:
parent
e6515bd47b
commit
1e3d811840
5 changed files with 101 additions and 8 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "archive.hh"
|
||||
#include "path-info.hh"
|
||||
|
||||
#include <chrono>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace nix {
|
||||
|
@ -47,6 +48,31 @@ void WorkerProto::Serialise<std::optional<TrustedFlag>>::write(const StoreDirCon
|
|||
}
|
||||
|
||||
|
||||
std::optional<std::chrono::microseconds> WorkerProto::Serialise<std::optional<std::chrono::microseconds>>::read(const StoreDirConfig & store, WorkerProto::ReadConn conn)
|
||||
{
|
||||
auto tag = readNum<uint8_t>(conn.from);
|
||||
switch (tag) {
|
||||
case 0:
|
||||
return std::nullopt;
|
||||
case 1:
|
||||
return std::optional<std::chrono::microseconds>{std::chrono::microseconds(readNum<int64_t>(conn.from))};
|
||||
default:
|
||||
throw Error("Invalid optional tag from remote");
|
||||
}
|
||||
}
|
||||
|
||||
void WorkerProto::Serialise<std::optional<std::chrono::microseconds>>::write(const StoreDirConfig & store, WorkerProto::WriteConn conn, const std::optional<std::chrono::microseconds> & optDuration)
|
||||
{
|
||||
if (!optDuration.has_value()) {
|
||||
conn.to << uint8_t{0};
|
||||
} else {
|
||||
conn.to
|
||||
<< uint8_t{1}
|
||||
<< optDuration.value().count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DerivedPath WorkerProto::Serialise<DerivedPath>::read(const StoreDirConfig & store, WorkerProto::ReadConn conn)
|
||||
{
|
||||
auto s = readString(conn.from);
|
||||
|
@ -110,6 +136,10 @@ BuildResult WorkerProto::Serialise<BuildResult>::read(const StoreDirConfig & sto
|
|||
>> res.startTime
|
||||
>> res.stopTime;
|
||||
}
|
||||
if (GET_PROTOCOL_MINOR(conn.version) >= 37) {
|
||||
res.cpuUser = WorkerProto::Serialise<std::optional<std::chrono::microseconds>>::read(store, conn);
|
||||
res.cpuSystem = WorkerProto::Serialise<std::optional<std::chrono::microseconds>>::read(store, conn);
|
||||
}
|
||||
if (GET_PROTOCOL_MINOR(conn.version) >= 28) {
|
||||
auto builtOutputs = WorkerProto::Serialise<DrvOutputs>::read(store, conn);
|
||||
for (auto && [output, realisation] : builtOutputs)
|
||||
|
@ -132,6 +162,10 @@ void WorkerProto::Serialise<BuildResult>::write(const StoreDirConfig & store, Wo
|
|||
<< res.startTime
|
||||
<< res.stopTime;
|
||||
}
|
||||
if (GET_PROTOCOL_MINOR(conn.version) >= 37) {
|
||||
WorkerProto::write(store, conn, res.cpuUser);
|
||||
WorkerProto::write(store, conn, res.cpuSystem);
|
||||
}
|
||||
if (GET_PROTOCOL_MINOR(conn.version) >= 28) {
|
||||
DrvOutputs builtOutputs;
|
||||
for (auto & [output, realisation] : res.builtOutputs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue