From 422297bad3a478ac69ecd73dd76af0b84b182aae Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Thu, 30 Sep 1999 21:22:16 +0000 Subject: [PATCH] More graph work git-svn-id: svn://10.0.0.236/trunk@49471 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/tools/leaky/leaky.cpp | 31 ++++++++++++++++++++++++++++--- mozilla/tools/leaky/leaky.h | 6 ++++++ mozilla/tools/leaky/leaky.js | 9 +++++---- mozilla/tools/leaky/strset.h | 11 ++++++----- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/mozilla/tools/leaky/leaky.cpp b/mozilla/tools/leaky/leaky.cpp index 49009c84d32..f7689f20369 100644 --- a/mozilla/tools/leaky/leaky.cpp +++ b/mozilla/tools/leaky/leaky.cpp @@ -90,7 +90,7 @@ leaky::~leaky() void leaky::usageError() { fprintf(stderr, - "Usage: %s [-aAEdfgqx] [-e name] [-s depth] [-h hash-buckets] prog log\n", + "Usage: %s [-aAEdfgqx] [-e name] [-s depth] [-h hash-buckets] [-r root] prog log\n", (char*) applicationName); exit(-1); } @@ -107,7 +107,7 @@ void leaky::initialize(int argc, char** argv) int arg; int errflg = 0; - while ((arg = getopt(argc, argv, "adEe:fgh:s:tqx")) != -1) { + while ((arg = getopt(argc, argv, "adEe:fgh:r:s:tqx")) != -1) { switch (arg) { case '?': errflg++; @@ -132,6 +132,9 @@ void leaky::initialize(int argc, char** argv) dumpGraph = TRUE; if (dumpAll) errflg++; break; + case 'r': + roots.add(optarg); + break; case 'h': buckets = atoi(optarg); if ((buckets < 0) || (buckets > MaxBuckets)) { @@ -480,8 +483,13 @@ void leaky::buildLeakGraph() Symbol* sym = findSymbol((u_long) *pcp); TreeNode* node = sym->root; if (!node) { - displayStackTrace(stderr, lep); sym->root = node = new TreeNode(sym); + + // Add root to list of roots + if (roots.IsEmpty()) { + node->nextRoot = rootList; + rootList = node; + } } pcp--; @@ -498,6 +506,14 @@ void leaky::buildLeakGraph() nextNode = node->AddDescendant(sym); } + // See if the symbol is to be a user specified root. If it is, + // and we haven't already stuck it on the root-list do so now. + if (!sym->root && !roots.IsEmpty() && roots.contains(sym->name)) { + sym->root = nextNode; + nextNode->nextRoot = rootList; + rootList = nextNode; + } + if (pcp == basepcp) { nextNode->bytesLeaked += lep->size; } @@ -532,6 +548,8 @@ void leaky::dumpLeakGraph() printf("Bytes directly leaked
\n"); printf("Bytes leaked by descendants\n"); } + +#if 0 Symbol* base = externalSymbols; Symbol* end = externalSymbols + usefulSymbols; while (base < end) { @@ -540,6 +558,13 @@ void leaky::dumpLeakGraph() dumpLeakTree(sym->root, 0); base = sym + 1; } +#else + TreeNode* root = rootList; + while (root) { + dumpLeakTree(root, 0); + root = root->nextRoot; + } +#endif if (dumpHTML) { printf("\n"); } diff --git a/mozilla/tools/leaky/leaky.h b/mozilla/tools/leaky/leaky.h index 21c27e2568f..608f55775ad 100644 --- a/mozilla/tools/leaky/leaky.h +++ b/mozilla/tools/leaky/leaky.h @@ -29,6 +29,7 @@ struct TreeNode { symbol = aSymbol; nextSibling = NULL; descendants = NULL; + nextRoot = NULL; } TreeNode* GetDirectDescendant(Symbol* aSymbol); @@ -41,6 +42,7 @@ struct TreeNode { TreeNode* descendants; TreeNode* nextSibling; + TreeNode* nextRoot; Symbol* symbol; u_long bytesLeaked; @@ -113,6 +115,10 @@ struct leaky { LoadMapEntry* loadMap; + TreeNode* rootList; + + StrSet roots; + void usageError(); void LoadMap(); diff --git a/mozilla/tools/leaky/leaky.js b/mozilla/tools/leaky/leaky.js index 1a077edee99..32209afb14c 100644 --- a/mozilla/tools/leaky/leaky.js +++ b/mozilla/tools/leaky/leaky.js @@ -3,8 +3,9 @@ function I(event) { var it = event.target; if (it) { var s = it.src; - var s1 = s.replace(".gif", "-over.gif"); - it.src = s1; + s = s.replace("-over", ""); // just in case + s = s.replace(".gif", "-over.gif"); + it.src = s; lastIn = it; } } @@ -12,8 +13,8 @@ function O(event) { var it = lastIn; if (it) { var s = it.src; - var s1 = s.replace("-over", ""); - it.src = s1; + s = s.replace("-over", ""); + it.src = s; lastIn = null; } } diff --git a/mozilla/tools/leaky/strset.h b/mozilla/tools/leaky/strset.h index 2a63c49687b..480bb31f612 100644 --- a/mozilla/tools/leaky/strset.h +++ b/mozilla/tools/leaky/strset.h @@ -14,13 +14,14 @@ #define __strset_h_ struct StrSet { - StrSet(); + StrSet(); - void add(const char* string); - int contains(const char* string); + void add(const char* string); + int contains(const char* string); + bool IsEmpty() const { return 0 == numstrings; } - char** strings; - int numstrings; + char** strings; + int numstrings; }; #endif /* __strset_h_ */