Skip to content

Instantly share code, notes, and snippets.

@cleverca22
Created September 1, 2018 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleverca22/a8d61484e6ce42ebc0818b593c94065a to your computer and use it in GitHub Desktop.
Save cleverca22/a8d61484e6ce42ebc0818b593c94065a to your computer and use it in GitHub Desktop.
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 85adb4e0..a45d4685 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -1665,14 +1680,16 @@ void EvalState::printStats()
uint64_t bValues = nrValues * sizeof(Value);
uint64_t bAttrsets = nrAttrsets * sizeof(Bindings) + nrAttrsInAttrsets * sizeof(Attr);
+ auto sum = bEnvs + bLists + bValues + bAttrsets;
+
printMsg(v, format(" time elapsed: %1%") % cpuTime);
printMsg(v, format(" size of a value: %1%") % sizeof(Value));
printMsg(v, format(" size of an attr: %1%") % sizeof(Attr));
- printMsg(v, format(" environments allocated: %1% (%2% bytes)") % nrEnvs % bEnvs);
- printMsg(v, format(" list elements: %1% (%2% bytes)") % nrListElems % bLists);
+ printMsg(v, format(" environments allocated: %1% (%2% bytes, %3%%%)") % nrEnvs % bEnvs % ((bEnvs*100) / sum));
+ printMsg(v, format(" list elements: %1% (%2% bytes %3%%%)") % nrListElems % bLists % ((bLists*100)/sum));
printMsg(v, format(" list concatenations: %1%") % nrListConcats);
- printMsg(v, format(" values allocated: %1% (%2% bytes)") % nrValues % bValues);
- printMsg(v, format(" sets allocated: %1% (%2% bytes)") % nrAttrsets % bAttrsets);
+ printMsg(v, format(" values allocated: %1% (%2% bytes %3%%%)") % nrValues % bValues % ((bValues*100)/sum));
+ printMsg(v, format(" sets allocated: %1% (%2% bytes %3%%%)") % nrAttrsets % bAttrsets % ((bAttrsets*100)/sum));
printMsg(v, format(" right-biased unions: %1%") % nrOpUpdates);
printMsg(v, format(" values copied in right-biased unions: %1%") % nrOpUpdateValuesCopied);
printMsg(v, format(" symbols in symbol table: %1%") % symbols.size());
@@ -1686,6 +1703,8 @@ void EvalState::printStats()
printMsg(v, format(" memoisation hits: %d") % nrMemoiseHits);
printMsg(v, format(" memoisation misses: %d") % nrMemoiseMisses);
+ printMsg(v, format(" sets: %1% (%2% each, %3% mb total), attrs-in-sets: %4% (%5% each, %6% mb total)") % nrAttrsets % sizeof(Bindings) % ((nrAttrsets * sizeof(Bindings)) / 1024 / 1024) % nrAttrsInAttrsets % sizeof(Attr) % ((nrAttrsInAttrsets * sizeof(Attr)) / 1024 / 1024));
+
#if HAVE_BOEHMGC
GC_word heapSize, totalBytes;
GC_get_heap_usage_safe(&heapSize, 0, 0, 0, &totalBytes);
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index 58366daa..7b92bb31 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -357,7 +357,10 @@ void mainWrapped(int argc, char * * argv)
buildPaths(pathsToBuild);
- if (dryRun) return;
+ if (dryRun) {
+ state.printStats();
+ return;
+ }
// Set the environment.
auto env = getEnv();
@@ -481,7 +484,10 @@ void mainWrapped(int argc, char * * argv)
buildPaths(pathsToBuild);
- if (dryRun) return;
+ if (dryRun) {
+ state.printStats();
+ return;
+ }
for (auto & symlink : resultSymlinks)
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
@@ -490,6 +496,7 @@ void mainWrapped(int argc, char * * argv)
for (auto & path : outPaths)
std::cout << path << '\n';
}
+ state.printStats();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment