mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +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
8
doc/manual/rl-next/cgroup-stats.md
Normal file
8
doc/manual/rl-next/cgroup-stats.md
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
synopsis: Include cgroup stats when building through the daemon
|
||||||
|
prs: 9598
|
||||||
|
---
|
||||||
|
|
||||||
|
Nix now also reports cgroup statistics when building through the nix daemon and when doing remote builds using ssh-ng,
|
||||||
|
if both sides of the connection are this version of Nix or newer.
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "path-info.hh"
|
#include "path-info.hh"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace nix {
|
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)
|
DerivedPath WorkerProto::Serialise<DerivedPath>::read(const StoreDirConfig & store, WorkerProto::ReadConn conn)
|
||||||
{
|
{
|
||||||
auto s = readString(conn.from);
|
auto s = readString(conn.from);
|
||||||
|
@ -110,6 +136,10 @@ BuildResult WorkerProto::Serialise<BuildResult>::read(const StoreDirConfig & sto
|
||||||
>> res.startTime
|
>> res.startTime
|
||||||
>> res.stopTime;
|
>> 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) {
|
if (GET_PROTOCOL_MINOR(conn.version) >= 28) {
|
||||||
auto builtOutputs = WorkerProto::Serialise<DrvOutputs>::read(store, conn);
|
auto builtOutputs = WorkerProto::Serialise<DrvOutputs>::read(store, conn);
|
||||||
for (auto && [output, realisation] : builtOutputs)
|
for (auto && [output, realisation] : builtOutputs)
|
||||||
|
@ -132,6 +162,10 @@ void WorkerProto::Serialise<BuildResult>::write(const StoreDirConfig & store, Wo
|
||||||
<< res.startTime
|
<< res.startTime
|
||||||
<< res.stopTime;
|
<< 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) {
|
if (GET_PROTOCOL_MINOR(conn.version) >= 28) {
|
||||||
DrvOutputs builtOutputs;
|
DrvOutputs builtOutputs;
|
||||||
for (auto & [output, realisation] : res.builtOutputs)
|
for (auto & [output, realisation] : res.builtOutputs)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
///@file
|
///@file
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include "common-protocol.hh"
|
#include "common-protocol.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -9,7 +11,7 @@ namespace nix {
|
||||||
#define WORKER_MAGIC_1 0x6e697863
|
#define WORKER_MAGIC_1 0x6e697863
|
||||||
#define WORKER_MAGIC_2 0x6478696f
|
#define WORKER_MAGIC_2 0x6478696f
|
||||||
|
|
||||||
#define PROTOCOL_VERSION (1 << 8 | 36)
|
#define PROTOCOL_VERSION (1 << 8 | 37)
|
||||||
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
|
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
|
||||||
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
|
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
|
||||||
|
|
||||||
|
@ -214,6 +216,8 @@ template<>
|
||||||
DECLARE_WORKER_SERIALISER(UnkeyedValidPathInfo);
|
DECLARE_WORKER_SERIALISER(UnkeyedValidPathInfo);
|
||||||
template<>
|
template<>
|
||||||
DECLARE_WORKER_SERIALISER(std::optional<TrustedFlag>);
|
DECLARE_WORKER_SERIALISER(std::optional<TrustedFlag>);
|
||||||
|
template<>
|
||||||
|
DECLARE_WORKER_SERIALISER(std::optional<std::chrono::microseconds>);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
DECLARE_WORKER_SERIALISER(std::vector<T>);
|
DECLARE_WORKER_SERIALISER(std::vector<T>);
|
||||||
|
|
BIN
tests/unit/libstore/data/worker-protocol/build-result-1.37.bin
Normal file
BIN
tests/unit/libstore/data/worker-protocol/build-result-1.37.bin
Normal file
Binary file not shown.
|
@ -280,13 +280,60 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
},
|
},
|
||||||
.startTime = 30,
|
.startTime = 30,
|
||||||
.stopTime = 50,
|
.stopTime = 50,
|
||||||
#if 0
|
},
|
||||||
// These fields are not yet serialized.
|
};
|
||||||
// FIXME Include in next version of protocol or document
|
t;
|
||||||
// why they are skipped.
|
}))
|
||||||
.cpuUser = std::chrono::milliseconds(500s),
|
|
||||||
.cpuSystem = std::chrono::milliseconds(604s),
|
VERSIONED_CHARACTERIZATION_TEST(
|
||||||
#endif
|
WorkerProtoTest,
|
||||||
|
buildResult_1_37,
|
||||||
|
"build-result-1.37",
|
||||||
|
1 << 8 | 37,
|
||||||
|
({
|
||||||
|
using namespace std::literals::chrono_literals;
|
||||||
|
std::tuple<BuildResult, BuildResult, BuildResult> t {
|
||||||
|
BuildResult {
|
||||||
|
.status = BuildResult::OutputRejected,
|
||||||
|
.errorMsg = "no idea why",
|
||||||
|
},
|
||||||
|
BuildResult {
|
||||||
|
.status = BuildResult::NotDeterministic,
|
||||||
|
.errorMsg = "no idea why",
|
||||||
|
.timesBuilt = 3,
|
||||||
|
.isNonDeterministic = true,
|
||||||
|
.startTime = 30,
|
||||||
|
.stopTime = 50,
|
||||||
|
},
|
||||||
|
BuildResult {
|
||||||
|
.status = BuildResult::Built,
|
||||||
|
.timesBuilt = 1,
|
||||||
|
.builtOutputs = {
|
||||||
|
{
|
||||||
|
"foo",
|
||||||
|
{
|
||||||
|
.id = DrvOutput {
|
||||||
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
||||||
|
.outputName = "foo",
|
||||||
|
},
|
||||||
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bar",
|
||||||
|
{
|
||||||
|
.id = DrvOutput {
|
||||||
|
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
|
||||||
|
.outputName = "bar",
|
||||||
|
},
|
||||||
|
.outPath = StorePath { "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.startTime = 30,
|
||||||
|
.stopTime = 50,
|
||||||
|
.cpuUser = std::chrono::microseconds(500s),
|
||||||
|
.cpuSystem = std::chrono::microseconds(604s),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
t;
|
t;
|
||||||
|
|
Loading…
Reference in a new issue