[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
200/376: Add some instrumentation for debugging GC leaks
From: |
Ludovic Courtès |
Subject: |
200/376: Add some instrumentation for debugging GC leaks |
Date: |
Wed, 28 Jan 2015 22:05:01 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit 6e5b02bee4c117863f11e4697da9e4f55b81e52d
Author: Eelco Dolstra <address@hidden>
Date: Wed Sep 17 15:19:07 2014 +0200
Add some instrumentation for debugging GC leaks
---
src/libexpr/eval.cc | 22 ++++++++++++++++++++++
src/libexpr/eval.hh | 8 ++++++++
src/libexpr/primops.cc | 27 +++++++++++++++++++++++++++
src/nix-instantiate/nix-instantiate.cc | 2 ++
4 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 2af6a67..70b3365 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -230,6 +230,8 @@ EvalState::EvalState(const Strings & _searchPath)
EvalState::~EvalState()
{
+ fileEvalCache.clear();
+ printCanaries();
}
@@ -1464,4 +1466,24 @@ void EvalState::printStats()
}
+void EvalState::printCanaries()
+{
+#if HAVE_BOEHMGC
+ if (!settings.get("debug-gc", false)) return;
+
+ GC_gcollect();
+
+ if (gcCanaries.empty()) {
+ printMsg(lvlError, "all canaries have been garbage-collected");
+ return;
+ }
+
+ printMsg(lvlError, "the following canaries have not been
garbage-collected:");
+
+ for (auto i : gcCanaries)
+ printMsg(lvlError, format(" %1%") % i->string.s);
+#endif
+}
+
+
}
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 82c1a43..af9452c 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -255,6 +255,8 @@ public:
/* Print statistics. */
void printStats();
+ void printCanaries();
+
private:
unsigned long nrEnvs;
@@ -285,6 +287,12 @@ private:
friend struct ExprOpConcatLists;
friend struct ExprSelect;
friend void prim_getAttr(EvalState & state, const Pos & pos, Value * *
args, Value & v);
+
+#if HAVE_BOEHMGC
+ std::set<Value *> gcCanaries;
+ friend void canaryFinalizer(GC_PTR obj, GC_PTR client_data);
+ friend void prim_gcCanary(EvalState & state, const Pos & pos, Value * *
args, Value & v);
+#endif
};
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 0c4381b..2dd242a 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -397,6 +397,32 @@ static void prim_trace(EvalState & state, const Pos & pos,
Value * * args, Value
}
+#if HAVE_BOEHMGC
+void canaryFinalizer(GC_PTR obj, GC_PTR client_data)
+{
+ Value * v = (Value *) obj;
+ EvalState & state(* (EvalState *) client_data);
+ printMsg(lvlError, format("canary ‘%1%’ garbage-collected") % v->string.s);
+ auto i = state.gcCanaries.find(v);
+ assert(i != state.gcCanaries.end());
+ state.gcCanaries.erase(i);
+}
+#endif
+
+
+void prim_gcCanary(EvalState & state, const Pos & pos, Value * * args, Value &
v)
+{
+ string s = state.forceStringNoCtx(*args[0], pos);
+ state.mkList(v, 1);
+ Value * canary = v.list.elems[0] = state.allocValue();
+#if HAVE_BOEHMGC
+ state.gcCanaries.insert(canary);
+ GC_register_finalizer(canary, canaryFinalizer, &state, 0, 0);
+#endif
+ mkString(*canary, s);
+}
+
+
/*************************************************************
* Derivations
*************************************************************/
@@ -1393,6 +1419,7 @@ void EvalState::createBaseEnv()
addPrimOp("__tryEval", 1, prim_tryEval);
addPrimOp("__getEnv", 1, prim_getEnv);
addPrimOp("__trace", 2, prim_trace);
+ addPrimOp("__gcCanary", 1, prim_gcCanary);
// Paths
addPrimOp("__toPath", 1, prim_toPath);
diff --git a/src/nix-instantiate/nix-instantiate.cc
b/src/nix-instantiate/nix-instantiate.cc
index 5080160..7a38f2a 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -86,6 +86,8 @@ void processExpr(EvalState & state, const Strings & attrPaths,
}
}
}
+
+ state.printCanaries();
}
- 193/376: Fix parallel make of manpages, (continued)
- 193/376: Fix parallel make of manpages, Ludovic Courtès, 2015/01/28
- 195/376: Make troubleshooting an appendix, Ludovic Courtès, 2015/01/28
- 197/376: Remove unhelpful suggestion, Ludovic Courtès, 2015/01/28
- 196/376: Delete bugs.xml, Ludovic Courtès, 2015/01/28
- 183/376: Manual build fixes, Ludovic Courtès, 2015/01/28
- 203/376: Remove unused w3m dependency, Ludovic Courtès, 2015/01/28
- 182/376: Merge branch 'master' of github.com:thatdocslady/nix, Ludovic Courtès, 2015/01/28
- 207/376: Remove debug statement, Ludovic Courtès, 2015/01/28
- 204/376: Install some pkgconfig files, Ludovic Courtès, 2015/01/28
- 206/376: Store.so: Add dependency on libnixutil, Ludovic Courtès, 2015/01/28
- 200/376: Add some instrumentation for debugging GC leaks,
Ludovic Courtès <=
- 210/376: Inline Bindings::find(), Ludovic Courtès, 2015/01/28
- 202/376: On Linux, disable address space randomization, Ludovic Courtès, 2015/01/28
- 205/376: Update spec file, Ludovic Courtès, 2015/01/28
- 201/376: Add Make flag to disable optimization, Ludovic Courtès, 2015/01/28
- 213/376: configure: Force regeneration of Makefile.config, Ludovic Courtès, 2015/01/28
- 212/376: attrNames: Don't allocate duplicates of the symbols, Ludovic Courtès, 2015/01/28
- 216/376: Handle cycles when printing a value, Ludovic Courtès, 2015/01/28
- 211/376: Fix off-by-one, Ludovic Courtès, 2015/01/28
- 215/376: Add ‘seq’ primop, Ludovic Courtès, 2015/01/28
- 209/376: Store Attrs inside Bindings, Ludovic Courtès, 2015/01/28