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");

View File

@ -342,6 +342,8 @@ public:
void realiseContext(const PathSet & context);
void updateCacheStats(ValueCache::CacheResult);
private:
unsigned long nrEnvs = 0;
@ -355,6 +357,10 @@ private:
unsigned long nrListConcats = 0;
unsigned long nrPrimOpCalls = 0;
unsigned long nrFunctionCalls = 0;
unsigned long nrCacheHits = 0;
unsigned long nrCacheMisses = 0;
unsigned long nrUncacheable = 0;
unsigned long nrUncached = 0;
bool countCalls;