Keep better bytesReceived/bytesSent stats

This commit is contained in:
Eelco Dolstra 2016-02-26 16:16:36 +01:00
parent 6d741d2ffa
commit b9afaadfb3
2 changed files with 22 additions and 19 deletions

View file

@ -8,6 +8,7 @@
#include "state.hh"
#include "util.hh"
#include "worker-protocol.hh"
#include "finally.hh"
using namespace nix;
@ -75,7 +76,6 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil
static void copyClosureTo(ref<Store> destStore,
FdSource & from, FdSink & to, const PathSet & paths,
counter & bytesSent,
bool useSubstitutes = false)
{
PathSet closure;
@ -103,9 +103,6 @@ static void copyClosureTo(ref<Store> destStore,
printMsg(lvlDebug, format("sending %1% missing paths") % missing.size());
for (auto & p : missing)
bytesSent += destStore->queryPathInfo(p).narSize;
to << cmdImportPaths;
destStore->exportPaths(missing, false, to);
to.flush();
@ -115,19 +112,6 @@ static void copyClosureTo(ref<Store> destStore,
}
static void copyClosureFrom(ref<Store> destStore,
FdSource & from, FdSink & to, const PathSet & paths, counter & bytesReceived,
std::shared_ptr<FSAccessor> accessor)
{
to << cmdExportPaths << 0 << paths;
to.flush();
destStore->importPaths(false, from, accessor);
for (auto & p : paths)
bytesReceived += destStore->queryPathInfo(p).narSize;
}
void State::buildRemote(ref<Store> destStore,
Machine::ptr machine, Step::ptr step,
unsigned int maxSilentTime, unsigned int buildTimeout,
@ -153,6 +137,11 @@ void State::buildRemote(ref<Store> destStore,
FdSource from(child.from);
FdSink to(child.to);
Finally updateStats([&]() {
bytesReceived += from.read;
bytesSent += to.written;
});
/* Handshake. */
bool sendDerivation = true;
unsigned int remoteVersion;
@ -239,7 +228,7 @@ void State::buildRemote(ref<Store> destStore,
auto now1 = std::chrono::steady_clock::now();
copyClosureTo(destStore, from, to, inputs, bytesSent, true);
copyClosureTo(destStore, from, to, inputs, true);
auto now2 = std::chrono::steady_clock::now();
@ -302,7 +291,9 @@ void State::buildRemote(ref<Store> destStore,
auto now1 = std::chrono::steady_clock::now();
copyClosureFrom(destStore, from, to, outputs, bytesReceived, result.accessor);
to << cmdExportPaths << 0 << outputs;
to.flush();
destStore->importPaths(false, from, result.accessor);
auto now2 = std::chrono::steady_clock::now();

View file

@ -0,0 +1,12 @@
#pragma once
/* A trivial class to run a function at the end of a scope. */
class Finally
{
private:
std::function<void()> fun;
public:
Finally(std::function<void()> fun) : fun(fun) { }
~Finally() { fun(); }
};