From 310e605995dc104bee29d330ac135e3e2bb82f97 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 8 May 2006 10:00:37 +0000 Subject: [PATCH] * Show evaluation stats when NIX_SHOW_STATS=1. --- src/libexpr/eval.cc | 5 ++++- src/libutil/aterm-map.cc | 36 ++++++++++++++++++++++-------------- src/libutil/aterm-map.hh | 4 ++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 38f198fb8..ee17c996c 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -527,9 +527,12 @@ extern "C" { void printEvalStats(EvalState & state) { - printMsg(lvlInfo, + bool showStats = getEnv("NIX_SHOW_STATS", "0") != "0"; + printMsg(showStats ? lvlInfo : lvlDebug, format("evaluated %1% expressions, %2% cache hits, %3%%% efficiency, used %4% ATerm bytes") % state.nrEvaluated % state.nrCached % ((float) state.nrCached / (float) state.nrEvaluated * 100) % AT_calcAllocatedSize()); + if (showStats) + printATermMapStats(); } diff --git a/src/libutil/aterm-map.cc b/src/libutil/aterm-map.cc index e0cfefa2d..60092382a 100644 --- a/src/libutil/aterm-map.cc +++ b/src/libutil/aterm-map.cc @@ -213,6 +213,27 @@ unsigned int ATermMap::size() } +#include + +void printATermMapStats() +{ + cout << "RESIZES: " << nrResizes << " " + << sizeTotalAlloc << " " + << sizeCurAlloc << " " + << sizeMaxAlloc << endl; + + cout << "SET: " + << nrItemsSet << " " + << nrSetProbes << " " + << (double) nrSetProbes / nrItemsSet << endl; + + cout << "GET: " + << nrItemsGet << " " + << nrGetProbes << " " + << (double) nrGetProbes / nrItemsGet << endl; +} + + #if 0 int main(int argc, char * * argv) { @@ -294,19 +315,6 @@ int main(int argc, char * * argv) } - cout << "RESIZES: " << nrResizes << " " - << sizeTotalAlloc << " " - << sizeCurAlloc << " " - << sizeMaxAlloc << endl; - - cout << "SET: " - << nrItemsSet << " " - << nrSetProbes << " " - << (double) nrSetProbes / nrItemsSet << endl; - - cout << "GET: " - << nrItemsGet << " " - << nrGetProbes << " " - << (double) nrGetProbes / nrItemsGet << endl; + printATermMapStats(); } #endif diff --git a/src/libutil/aterm-map.hh b/src/libutil/aterm-map.hh index d7aed2ca2..6d13d7f9e 100644 --- a/src/libutil/aterm-map.hh +++ b/src/libutil/aterm-map.hh @@ -111,4 +111,8 @@ private: }; +/* Hack. */ +void printATermMapStats(); + + #endif /* !__ATERM_MAP_H */