diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 784def811..7652662d3 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1657,7 +1657,7 @@ void EvalState::printStats() if (outPath != "-") fs.open(outPath, std::fstream::out); JSONObject topObj(outPath == "-" ? std::cerr : fs, true); - topObj.attr("cpuTime",cpuTime); + topObj.attr("cpuTime", cpuTime); { auto envs = topObj.object("envs"); envs.attr("number", nrEnvs); @@ -1700,6 +1700,13 @@ void EvalState::printStats() topObj.attr("nrLookups", nrLookups); topObj.attr("nrPrimOpCalls", nrPrimOpCalls); topObj.attr("nrFunctionCalls", nrFunctionCalls); + { + auto j = topObj.object("gc"); + j.attr("heapSize", gc.getHeapSize()); + j.attr("totalBytes", gc.allTimeWordsAllocated * WORD_SIZE); + j.attr("reclaimedBytes", gc.allTimeWordsFreed * WORD_SIZE); + j.attr("gcTime", gc.totalDurationMs / 1000.0); + } if (countCalls) { { diff --git a/src/libexpr/gc.hh b/src/libexpr/gc.hh index 6825329b5..7a87a4036 100644 --- a/src/libexpr/gc.hh +++ b/src/libexpr/gc.hh @@ -191,10 +191,16 @@ private: std::array freeLists; +public: + + size_t getHeapSize() { return totalSize * WORD_SIZE; } + size_t allTimeWordsAllocated = 0; size_t allTimeWordsFreed = 0; uint64_t totalDurationMs = 0; +private: + Object * allocObject(size_t size) { assert(size >= 2);