1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-20 17:29:36 +01:00

Add some stats for the evaluation caching

This commit is contained in:
regnat 2021-02-05 13:35:59 +01:00
parent 007c4a7f3a
commit 357e095a7b
2 changed files with 36 additions and 0 deletions

View file

@ -1257,6 +1257,27 @@ ValueCache::CacheResult ValueCache::getValue(Store & store, const std::vector<Sy
cachedValue);
}
void EvalState::updateCacheStats(ValueCache::CacheResult cacheResult)
{
switch (cacheResult.returnCode) {
case ValueCache::CacheHit:
nrCacheHits++;
break;
case ValueCache::CacheMiss:
nrCacheMisses++;
break;
case ValueCache::UnCacheable:
nrUncacheable++;
break;
case ValueCache::NoCacheKey:
nrUncached++;
break;
case ValueCache::Forward:
nrCacheHits++;
break;
};
}
struct ExprCastedVar : Expr
{
Value * v;
@ -1280,6 +1301,7 @@ EvalState::AttrAccesResult EvalState::lazyGetOptionalAttrField(Value & attrs, co
Value * dest = allocValue();
auto evalCache = attrs.getCache();
auto cacheResult = evalCache.getValue(*store, selector, *dest);
updateCacheStats(cacheResult);
if (cacheResult.returnCode == ValueCache::CacheHit) {
if (cacheResult.lastQueriedSymbolIfMissing)
@ -1324,6 +1346,7 @@ EvalState::AttrAccesResult EvalState::getOptionalAttrField(Value & attrs, const
};
auto cacheResult = evalCache.getValue(*store, selector, dest);
updateCacheStats(cacheResult);
if (cacheResult.returnCode == ValueCache::CacheHit) {
if (cacheResult.lastQueriedSymbolIfMissing)
@ -2306,6 +2329,13 @@ void EvalState::printStats()
topObj.attr("nrLookups", nrLookups);
topObj.attr("nrPrimOpCalls", nrPrimOpCalls);
topObj.attr("nrFunctionCalls", nrFunctionCalls);
{
auto cache = topObj.object("evalCache");
cache.attr("nrCacheMisses", nrCacheMisses);
cache.attr("nrCacheHits", nrCacheHits);
cache.attr("nrUncached", nrUncached);
cache.attr("nrUncacheable", nrUncacheable);
}
#if HAVE_BOEHMGC
{
auto gc = topObj.object("gc");