From 30964103dc31c32ccb69912fdd73474cd65447e9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 11 Jun 2018 16:10:50 +0200 Subject: [PATCH] Add temporary stats --- src/libexpr/eval.cc | 28 +++++++++++++++++++++++++++- src/libexpr/eval.hh | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index facfddbb5..1ab2b0ac1 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -13,6 +13,9 @@ #include #include +#include +#include + #if HAVE_BOEHMGC #include @@ -574,10 +577,19 @@ inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval) } +std::atomic nrValuesFreed{0}; + +void finalizeValue(void * obj, void * data) +{ + nrValuesFreed++; +} + Value * EvalState::allocValue() { nrValues++; - return (Value *) allocBytes(sizeof(Value)); + auto v = (Value *) allocBytes(sizeof(Value)); + //GC_register_finalizer_no_order(v, finalizeValue, nullptr, nullptr, nullptr); + return v; } @@ -1707,6 +1719,20 @@ bool EvalState::eqValues(Value & v1, Value & v2) } +void EvalState::printStats2() +{ + struct rusage ru; + getrusage(RUSAGE_SELF, &ru); + + GC_prof_stats_s gc; + GC_get_prof_stats(&gc, sizeof(gc)); + + printError("STATS %d %d %d %d %d %d", + nrValues, nrValuesFreed.load(), nrValues - nrValuesFreed, + ru.ru_maxrss, + gc.heapsize_full, gc.free_bytes_full); +} + void EvalState::printStats() { bool showStats = getEnv("NIX_SHOW_STATS", "0") != "0"; diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index d0f298e16..46bda86d0 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -276,6 +276,7 @@ public: /* Print statistics. */ void printStats(); + void printStats2(); void realiseContext(const PathSet & context);