valueSize(): Take into account list/bindings/env size

This commit is contained in:
Eelco Dolstra 2015-03-18 14:13:44 +01:00
parent e659978ced
commit 7a84143910

View file

@ -442,7 +442,7 @@ Env & EvalState::allocEnv(unsigned int size)
Env * env = (Env *) GC_MALLOC(sizeof(Env) + size * sizeof(Value *)); Env * env = (Env *) GC_MALLOC(sizeof(Env) + size * sizeof(Value *));
env->size = size; env->size = size;
/* Clear the values because maybeThunk() and lookupVar fromWith expects this. */ /* Clear the values because maybeThunk() and lookupVar fromWith expect this. */
for (unsigned i = 0; i < size; ++i) for (unsigned i = 0; i < size; ++i)
env->values[i] = 0; env->values[i] = 0;
@ -1498,6 +1498,7 @@ void EvalState::printStats()
printMsg(v, format(" time elapsed: %1%") % cpuTime); printMsg(v, format(" time elapsed: %1%") % cpuTime);
printMsg(v, format(" size of a value: %1%") % sizeof(Value)); 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(" environments allocated: %1% (%2% bytes)") % nrEnvs % bEnvs);
printMsg(v, format(" list elements: %1% (%2% bytes)") % nrListElems % bLists); printMsg(v, format(" list elements: %1% (%2% bytes)") % nrListElems % bLists);
printMsg(v, format(" list concatenations: %1%") % nrListConcats); printMsg(v, format(" list concatenations: %1%") % nrListConcats);
@ -1575,12 +1576,20 @@ size_t valueSize(Value & v)
sz += doString(v.path); sz += doString(v.path);
break; break;
case tAttrs: case tAttrs:
if (seen.find(v.attrs) == seen.end()) {
seen.insert(v.attrs);
sz += sizeof(Bindings) + sizeof(Attr) * v.attrs->capacity();
for (auto & i : *v.attrs) for (auto & i : *v.attrs)
sz += doValue(*i.value); sz += doValue(*i.value);
}
break; break;
case tList: case tList:
if (seen.find(v.list.elems) == seen.end()) {
seen.insert(v.list.elems);
sz += v.list.length * sizeof(Value *);
for (unsigned int n = 0; n < v.list.length; ++n) for (unsigned int n = 0; n < v.list.length; ++n)
sz += doValue(*v.list.elems[n]); sz += doValue(*v.list.elems[n]);
}
break; break;
case tThunk: case tThunk:
sz += doEnv(*v.thunk.env); sz += doEnv(*v.thunk.env);
@ -1612,7 +1621,7 @@ size_t valueSize(Value & v)
if (seen.find(&env) != seen.end()) return 0; if (seen.find(&env) != seen.end()) return 0;
seen.insert(&env); seen.insert(&env);
size_t sz = sizeof(Env); size_t sz = sizeof(Env) + sizeof(Value *) * env.size;
for (unsigned int i = 0; i < env.size; ++i) for (unsigned int i = 0; i < env.size; ++i)
if (env.values[i]) if (env.values[i])