From 59bb951af6ad9f8e09e5607bbe70f60358316d7f Mon Sep 17 00:00:00 2001 From: "dbaron%dbaron.org" Date: Fri, 8 Feb 2008 19:55:03 +0000 Subject: [PATCH] Add leak logging for node info managers that can be added to leak-gauge. b=414704 r+sr=sicking a=schrep --- content/base/src/nsNodeInfoManager.cpp | 31 +++++++++++++ tools/footprint/leak-gauge.html | 62 ++++++++++++++++++++++++-- tools/footprint/leak-gauge.pl | 61 ++++++++++++++++++++++--- 3 files changed, 145 insertions(+), 9 deletions(-) diff --git a/content/base/src/nsNodeInfoManager.cpp b/content/base/src/nsNodeInfoManager.cpp index dc8719bacac..1198e4cd16a 100644 --- a/content/base/src/nsNodeInfoManager.cpp +++ b/content/base/src/nsNodeInfoManager.cpp @@ -53,6 +53,16 @@ #include "nsComponentManagerUtils.h" #include "nsLayoutStatics.h" +#ifdef MOZ_LOGGING +// so we can get logging even in release builds +#define FORCE_PR_LOG 1 +#endif +#include "prlog.h" + +#ifdef PR_LOGGING +static PRLogModuleInfo* gNodeInfoManagerLeakPRLog; +#endif + PLHashNumber nsNodeInfoManager::GetNodeInfoInnerHashValue(const void *key) { @@ -91,6 +101,15 @@ nsNodeInfoManager::nsNodeInfoManager() { nsLayoutStatics::AddRef(); +#ifdef PR_LOGGING + if (!gNodeInfoManagerLeakPRLog) + gNodeInfoManagerLeakPRLog = PR_NewLogModule("NodeInfoManagerLeak"); + + if (gNodeInfoManagerLeakPRLog) + PR_LOG(gNodeInfoManagerLeakPRLog, PR_LOG_DEBUG, + ("NODEINFOMANAGER %p created", this)); +#endif + mNodeInfoHash = PL_NewHashTable(32, GetNodeInfoInnerHashValue, NodeInfoInnerKeyCompare, PL_CompareValues, nsnull, nsnull); @@ -105,6 +124,12 @@ nsNodeInfoManager::~nsNodeInfoManager() // Note: mPrincipal may be null here if we never got inited correctly NS_IF_RELEASE(mPrincipal); +#ifdef PR_LOGGING + if (gNodeInfoManagerLeakPRLog) + PR_LOG(gNodeInfoManagerLeakPRLog, PR_LOG_DEBUG, + ("NODEINFOMANAGER %p destroyed", this)); +#endif + nsLayoutStatics::Release(); } @@ -150,6 +175,12 @@ nsNodeInfoManager::Init(nsIDocument *aDocument) mDocument = aDocument; +#ifdef PR_LOGGING + if (gNodeInfoManagerLeakPRLog) + PR_LOG(gNodeInfoManagerLeakPRLog, PR_LOG_DEBUG, + ("NODEINFOMANAGER %p Init document=%p", this, aDocument)); +#endif + return NS_OK; } diff --git a/tools/footprint/leak-gauge.html b/tools/footprint/leak-gauge.html index 84779da1b7c..04632269d99 100755 --- a/tools/footprint/leak-gauge.html +++ b/tools/footprint/leak-gauge.html @@ -121,7 +121,12 @@ function run() { var m = rest.match(/^ (.*)$/); if (!m) throw "URI expected"; - this.docs[addr][m[1]] = true; + var uri = m[1]; + var doc_info = this.docs[addr]; + doc_info[uri] = true; + if ("nim" in doc_info) { + doc_info["nim"][uri] = true; + } } } }, @@ -130,7 +135,9 @@ function run() { var doc = this.docs[addr]; result += "Leaked document at address " + addr + ".\n"; for (var uri in doc) { - result += " ... with URI \"" + uri + "\".\n"; + if (uri != "nim") { + result += " ... with URI \"" + uri + "\".\n"; + } } } }, @@ -181,6 +188,53 @@ function run() { result += 'Leaked ' + len + ' out of ' + this.count + " docshells\n"; } + }, + "NODEINFOMANAGER": { + count: 0, + nims: {}, + handle_line: function(line) { + var match = line.match(/^([0-9a-f]*) (\S*)(.*)/); + if (match) { + var addr = match[1]; + var verb = match[2]; + var rest = match[3]; + if (verb == "created") { + this.nims[addr] = {}; + ++this.count; + } else if (verb == "destroyed") { + delete this.nims[addr]; + } else if (verb == "Init") { + var m = rest.match(/^ document=(.*)$/); + if (!m) + throw "document pointer expected"; + var nim_info = this.nims[addr]; + var doc = m[1]; + if (doc != "0") { + var doc_info = handlers["DOCUMENT"].docs[doc]; + for (var uri in doc_info) { + nim_info[uri] = true; + } + doc_info["nim"] = nim_info; + } + } + } + }, + dump: function() { + for (var addr in this.nims) { + var nim = this.nims[addr]; + result += "Leaked content nodes associated with node info manager at address " + addr + ".\n"; + for (var uri in nim) { + result += " ... with document URI \"" + uri + "\".\n"; + } + } + }, + summary: function() { + var len = 0; + for (var w in this.nims) + ++len; + result += 'Leaked content nodes in ' + len + ' out of ' + + this.count + " documents\n"; + } } }; @@ -237,7 +291,7 @@ function run() {

Leak Gauge

-
$Id: leak-gauge.html,v 1.6 2006-01-14 00:27:41 dbaron%dbaron.org Exp $
+
$Id: leak-gauge.html,v 1.7 2008-02-08 19:55:03 dbaron%dbaron.org Exp $

This script is designed to help testers isolate and simplify testcases for many classes of leaks (those that involve large graphs of core @@ -249,7 +303,7 @@ leak. Once a site is known to leak, the logging can then be repeated to figure out under what conditions the leak occurs.

The way to create this log is to set the environment variables:

-
  NSPR_LOG_MODULES=DOMLeak:5,DocumentLeak:5,nsDocShellLeak:5
+
  NSPR_LOG_MODULES=DOMLeak:5,DocumentLeak:5,nsDocShellLeak:5,NodeInfoManagerLeak:5
   NSPR_LOG_FILE=nspr.log     (or any other filename of your choice)

in your shell and then run the program.