diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-09-22T12·46+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-09-22T14·05+0200 |
commit | eff120d1b93b99d6ae61b20e18c31a5324a2be4f (patch) | |
tree | eebd5bbbc0d36b50fcd3c8e74f2340937fd77116 /src/libexpr/primops.cc | |
parent | 68cf98c4d20da7175e7e2fecdb4c89bc7cd3f643 (diff) |
Add a function ‘valueSize’
It returns the size of value, including all other values and environments reachable from it. It is intended for debugging memory consumption issues.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 66321c76977d..c721a5681f3d 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -423,6 +423,13 @@ void prim_gcCanary(EvalState & state, const Pos & pos, Value * * args, Value & v } +void prim_valueSize(EvalState & state, const Pos & pos, Value * * args, Value & v) +{ + /* We're not forcing the argument on purpose. */ + mkInt(v, valueSize(*args[0])); +} + + /************************************************************* * Derivations *************************************************************/ @@ -1416,8 +1423,11 @@ void EvalState::createBaseEnv() addPrimOp("__addErrorContext", 2, prim_addErrorContext); addPrimOp("__tryEval", 1, prim_tryEval); addPrimOp("__getEnv", 1, prim_getEnv); + + // Debugging addPrimOp("__trace", 2, prim_trace); addPrimOp("__gcCanary", 1, prim_gcCanary); + addPrimOp("__valueSize", 1, prim_valueSize); // Paths addPrimOp("__toPath", 1, prim_toPath); |