2002-04-17 03:36:47 +04:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2004-04-26 01:07:34 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-04-17 03:36:47 +04:00
|
|
|
*
|
2004-04-26 01:07:34 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2002-04-17 03:36:47 +04:00
|
|
|
*
|
|
|
|
* The Original Code is spacecategory.c code, released
|
|
|
|
* Apr 12, 2002.
|
|
|
|
*
|
2004-04-26 01:07:34 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2002-04-17 03:36:47 +04:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2004-04-26 01:07:34 +04:00
|
|
|
* Suresh Duddi <dp@netscape.com>, 12-April-2002
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-04-17 03:36:47 +04:00
|
|
|
*
|
2004-04-26 01:07:34 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2002-04-17 03:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** spacecategory.c
|
|
|
|
**
|
|
|
|
** Cagtegorizes each allocation using a predefined set of rules
|
|
|
|
** and presents a tree of categories for browsing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Required include files.
|
|
|
|
*/
|
|
|
|
#include "spacetrace.h"
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2002-04-20 04:25:55 +04:00
|
|
|
/*
|
|
|
|
** Ugh, MSVC6's qsort is too slow...
|
|
|
|
*/
|
|
|
|
#include "nsQuickSort.h"
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
#if defined(HAVE_BOUTELL_GD)
|
|
|
|
/*
|
|
|
|
** See http://www.boutell.com/gd for the GD graphics library.
|
|
|
|
** Ports for many platorms exist.
|
|
|
|
** Your box may already have the lib (mine did, redhat 7.1 workstation).
|
|
|
|
*/
|
|
|
|
#include <gd.h>
|
|
|
|
#include <gdfontt.h>
|
|
|
|
#include <gdfonts.h>
|
|
|
|
#include <gdfontmb.h>
|
|
|
|
#endif /* HAVE_BOUTELL_GD */
|
|
|
|
|
|
|
|
/*
|
|
|
|
** AddRule
|
|
|
|
**
|
|
|
|
** Add a rule into the list of rules maintainted in global
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
AddRule(STGlobals * g, STCategoryRule * rule)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
if (g->mNRules % ST_ALLOC_STEP == 0) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Need more space */
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryRule **newrules;
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
newrules = (STCategoryRule **) realloc(g->mCategoryRules,
|
2003-06-18 01:10:49 +04:00
|
|
|
(g->mNRules +
|
|
|
|
ST_ALLOC_STEP) *
|
|
|
|
sizeof(STCategoryRule *));
|
|
|
|
if (!newrules) {
|
2002-04-17 03:36:47 +04:00
|
|
|
REPORT_ERROR(__LINE__, AddRule_No_Memory);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
g->mCategoryRules = newrules;
|
|
|
|
}
|
|
|
|
g->mCategoryRules[g->mNRules++] = rule;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** AddChild
|
|
|
|
**
|
|
|
|
** Add the node as a child of the parent node
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
AddChild(STCategoryNode * parent, STCategoryNode * child)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
if (parent->nchildren % ST_ALLOC_STEP == 0) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* need more space */
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode **newnodes;
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
newnodes = (STCategoryNode **) realloc(parent->children,
|
2003-06-18 01:10:49 +04:00
|
|
|
(parent->nchildren +
|
|
|
|
ST_ALLOC_STEP) *
|
|
|
|
sizeof(STCategoryNode *));
|
|
|
|
if (!newnodes) {
|
2002-04-17 03:36:47 +04:00
|
|
|
REPORT_ERROR(__LINE__, AddChild_No_Memory);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
parent->children = newnodes;
|
|
|
|
}
|
|
|
|
parent->children[parent->nchildren++] = child;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
ReParent(STCategoryNode * parent, STCategoryNode * child)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
PRUint32 i;
|
2003-06-18 01:10:49 +04:00
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
if (child->parent == parent)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Remove child from old parent */
|
2003-06-18 01:10:49 +04:00
|
|
|
if (child->parent) {
|
|
|
|
for (i = 0; i < child->parent->nchildren; i++) {
|
|
|
|
if (child->parent->children[i] == child) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Remove child from list */
|
2003-06-18 01:10:49 +04:00
|
|
|
if (i + 1 < child->parent->nchildren)
|
|
|
|
memmove(&child->parent->children[i],
|
|
|
|
&child->parent->children[i + 1],
|
|
|
|
(child->parent->nchildren - i -
|
|
|
|
1) * sizeof(STCategoryNode *));
|
2002-04-17 03:36:47 +04:00
|
|
|
child->parent->nchildren--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add child into new parent */
|
|
|
|
AddChild(parent, child);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** findCategoryNode
|
|
|
|
**
|
|
|
|
** Given a category name, finds the Node corresponding to the category
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *
|
|
|
|
findCategoryNode(const char *catName, STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
PRUint32 i;
|
2003-06-18 01:10:49 +04:00
|
|
|
|
|
|
|
for (i = 0; i < g->mNCategoryMap; i++) {
|
2002-04-17 03:36:47 +04:00
|
|
|
if (!strcmp(g->mCategoryMap[i]->categoryName, catName))
|
|
|
|
return g->mCategoryMap[i]->node;
|
|
|
|
}
|
2002-04-19 00:11:45 +04:00
|
|
|
|
|
|
|
/* Check if we are looking for the root node */
|
|
|
|
if (!strcmp(catName, ST_ROOT_CATEGORY_NAME))
|
|
|
|
return &g->mCategoryRoot;
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** AddCategoryNode
|
|
|
|
**
|
|
|
|
** Adds a mapping between a category and its Node into the categoryMap
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
AddCategoryNode(STCategoryNode * node, STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
if (g->mNCategoryMap % ST_ALLOC_STEP == 0) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Need more space */
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryMapEntry **newmap =
|
|
|
|
(STCategoryMapEntry **) realloc(g->mCategoryMap,
|
|
|
|
(g->mNCategoryMap +
|
|
|
|
ST_ALLOC_STEP) *
|
|
|
|
sizeof(STCategoryMapEntry *));
|
|
|
|
if (!newmap) {
|
2002-04-17 03:36:47 +04:00
|
|
|
REPORT_ERROR(__LINE__, AddCategoryNode_No_Memory);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
g->mCategoryMap = newmap;
|
|
|
|
|
|
|
|
}
|
2003-06-18 01:10:49 +04:00
|
|
|
g->mCategoryMap[g->mNCategoryMap] =
|
|
|
|
(STCategoryMapEntry *) calloc(1, sizeof(STCategoryMapEntry));
|
|
|
|
if (!g->mCategoryMap[g->mNCategoryMap]) {
|
2002-04-17 03:36:47 +04:00
|
|
|
REPORT_ERROR(__LINE__, AddCategoryNode_No_Memory);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
g->mCategoryMap[g->mNCategoryMap]->categoryName = node->categoryName;
|
|
|
|
g->mCategoryMap[g->mNCategoryMap]->node = node;
|
|
|
|
g->mNCategoryMap++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** NewCategoryNode
|
|
|
|
**
|
|
|
|
** Creates a new category node for category name 'catname' and makes
|
|
|
|
** 'parent' its parent.
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *
|
|
|
|
NewCategoryNode(const char *catName, STCategoryNode * parent, STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *node;
|
2002-04-17 03:36:47 +04:00
|
|
|
|
|
|
|
node = (STCategoryNode *) calloc(1, sizeof(STCategoryNode));
|
|
|
|
if (!node)
|
|
|
|
return NULL;
|
2002-05-13 05:48:30 +04:00
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
node->runs =
|
|
|
|
(STRun **) calloc(g->mCommandLineOptions.mContexts, sizeof(STRun *));
|
|
|
|
if (NULL == node->runs) {
|
2002-05-13 05:48:30 +04:00
|
|
|
free(node);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
node->categoryName = catName;
|
|
|
|
|
|
|
|
/* Set parent of child */
|
|
|
|
node->parent = parent;
|
|
|
|
|
|
|
|
/* Set child in parent */
|
|
|
|
AddChild(parent, node);
|
|
|
|
|
|
|
|
/* Add node into mapping table */
|
|
|
|
AddCategoryNode(node, g);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ProcessCategoryLeafRule
|
|
|
|
**
|
2005-11-25 22:48:04 +03:00
|
|
|
** Add this into the tree as a leaf node. It doesn't know who its parent is. For now we make
|
2002-04-17 03:36:47 +04:00
|
|
|
** root as its parent
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
ProcessCategoryLeafRule(STCategoryRule * leafRule, STCategoryNode * root,
|
|
|
|
STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryRule *rule;
|
|
|
|
STCategoryNode *node;
|
2002-04-17 03:36:47 +04:00
|
|
|
|
|
|
|
rule = (STCategoryRule *) calloc(1, sizeof(STCategoryRule));
|
|
|
|
if (!rule)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Take ownership of all elements of rule */
|
|
|
|
*rule = *leafRule;
|
|
|
|
|
|
|
|
/* Find/Make a STCategoryNode and add it into the tree */
|
|
|
|
node = findCategoryNode(rule->categoryName, g);
|
|
|
|
if (!node)
|
|
|
|
node = NewCategoryNode(rule->categoryName, root, g);
|
|
|
|
|
|
|
|
/* Make sure rule knows which node to access */
|
|
|
|
rule->node = node;
|
|
|
|
|
|
|
|
/* Add rule into rulelist */
|
|
|
|
AddRule(g, rule);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ProcessCategoryParentRule
|
|
|
|
**
|
|
|
|
** Rule has all the children of category as patterns. Sets up the tree so that
|
|
|
|
** the parent child relationship is honored.
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
ProcessCategoryParentRule(STCategoryRule * parentRule, STCategoryNode * root,
|
|
|
|
STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *node;
|
|
|
|
STCategoryNode *child;
|
2002-04-17 03:36:47 +04:00
|
|
|
PRUint32 i;
|
|
|
|
|
|
|
|
/* Find the parent node in the tree. If not make one and add it into the tree */
|
|
|
|
node = findCategoryNode(parentRule->categoryName, g);
|
2003-06-18 01:10:49 +04:00
|
|
|
if (!node) {
|
2002-04-17 03:36:47 +04:00
|
|
|
node = NewCategoryNode(parentRule->categoryName, root, g);
|
|
|
|
if (!node)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For every child node, Find/Create it and make it the child of this node */
|
2003-06-18 01:10:49 +04:00
|
|
|
for (i = 0; i < parentRule->npats; i++) {
|
2002-04-17 03:36:47 +04:00
|
|
|
child = findCategoryNode(parentRule->pats[i], g);
|
2003-06-18 01:10:49 +04:00
|
|
|
if (!child) {
|
2002-04-17 03:36:47 +04:00
|
|
|
child = NewCategoryNode(parentRule->pats[i], node, g);
|
|
|
|
if (!child)
|
|
|
|
return -1;
|
|
|
|
}
|
2003-06-18 01:10:49 +04:00
|
|
|
else {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Reparent child to node. This is because when we created the node
|
2003-06-18 01:10:49 +04:00
|
|
|
** we would have created it as the child of root. Now we need to
|
|
|
|
** remove it from root's child list and add it into this node
|
|
|
|
*/
|
2002-04-17 03:36:47 +04:00
|
|
|
ReParent(node, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** initCategories
|
|
|
|
**
|
|
|
|
** Initialize all categories. This reads in a file that says how to categorize
|
|
|
|
** each callsite, creates a tree of these categories and makes a list of these
|
|
|
|
** patterns in order for matching
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
initCategories(STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char buf[1024], *in;
|
2002-05-02 22:38:42 +04:00
|
|
|
int n;
|
2002-04-17 03:36:47 +04:00
|
|
|
PRBool inrule, leaf;
|
|
|
|
STCategoryRule rule;
|
|
|
|
|
2002-05-13 04:01:15 +04:00
|
|
|
fp = fopen(g->mCommandLineOptions.mCategoryFile, "r");
|
2003-06-18 01:10:49 +04:00
|
|
|
if (!fp) {
|
2005-11-25 22:48:04 +03:00
|
|
|
/* It isn't an error to not have a categories file */
|
2002-04-17 04:11:55 +04:00
|
|
|
REPORT_INFO("No categories file.");
|
2002-04-17 03:36:47 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inrule = PR_FALSE;
|
|
|
|
leaf = PR_FALSE;
|
|
|
|
|
|
|
|
memset(&rule, 0, sizeof(rule));
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Lose the \n */
|
|
|
|
n = strlen(buf);
|
2003-06-18 01:10:49 +04:00
|
|
|
if (buf[n - 1] == '\n')
|
2002-04-17 03:36:47 +04:00
|
|
|
buf[--n] = '\0';
|
|
|
|
in = buf;
|
|
|
|
|
|
|
|
/* skip comments */
|
|
|
|
if (*in == '#')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* skip empty lines. If we are in a rule, end the rule. */
|
2003-06-18 01:10:49 +04:00
|
|
|
while (*in && isspace(*in))
|
2002-04-17 03:36:47 +04:00
|
|
|
in++;
|
|
|
|
if (*in == '\0') {
|
2003-06-18 01:10:49 +04:00
|
|
|
if (inrule) {
|
|
|
|
/* End the rule : leaf or non-leaf */
|
2002-04-17 03:36:47 +04:00
|
|
|
if (leaf)
|
|
|
|
ProcessCategoryLeafRule(&rule, &g->mCategoryRoot, g);
|
|
|
|
else
|
|
|
|
/* non-leaf */
|
|
|
|
ProcessCategoryParentRule(&rule, &g->mCategoryRoot, g);
|
|
|
|
inrule = PR_FALSE;
|
|
|
|
memset(&rule, 0, sizeof(rule));
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we are in a rule acculumate */
|
2003-06-18 01:10:49 +04:00
|
|
|
if (inrule) {
|
2002-04-20 01:51:03 +04:00
|
|
|
rule.pats[rule.npats] = strdup(in);
|
|
|
|
rule.patlen[rule.npats++] = strlen(in);
|
2002-04-17 03:36:47 +04:00
|
|
|
}
|
2003-06-18 01:10:49 +04:00
|
|
|
else if (*in == '<') {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Start a category */
|
|
|
|
inrule = PR_TRUE;
|
|
|
|
leaf = PR_TRUE;
|
|
|
|
|
|
|
|
/* Get the category name */
|
|
|
|
in++;
|
|
|
|
n = strlen(in);
|
2003-06-18 01:10:49 +04:00
|
|
|
if (in[n - 1] == '>')
|
|
|
|
in[n - 1] = '\0';
|
2002-04-17 03:36:47 +04:00
|
|
|
rule.categoryName = strdup(in);
|
|
|
|
}
|
2003-06-18 01:10:49 +04:00
|
|
|
else {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* this is a non-leaf category. Should be of the form CategoryName
|
2003-06-18 01:10:49 +04:00
|
|
|
** followed by list of child category names one per line
|
|
|
|
*/
|
2002-04-17 03:36:47 +04:00
|
|
|
inrule = PR_TRUE;
|
|
|
|
leaf = PR_FALSE;
|
|
|
|
rule.categoryName = strdup(in);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we were in a rule when processing the last line, end the rule */
|
2003-06-18 01:10:49 +04:00
|
|
|
if (inrule) {
|
|
|
|
/* End the rule : leaf or non-leaf */
|
2002-04-17 03:36:47 +04:00
|
|
|
if (leaf)
|
|
|
|
ProcessCategoryLeafRule(&rule, &g->mCategoryRoot, g);
|
|
|
|
else
|
|
|
|
/* non-leaf */
|
|
|
|
ProcessCategoryParentRule(&rule, &g->mCategoryRoot, g);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the final "uncategorized" category. We make new memory locations
|
2003-06-18 01:10:49 +04:00
|
|
|
** for all these to conform to the general principle of all strings are allocated
|
|
|
|
** so it makes release logic very simple.
|
|
|
|
*/
|
2002-04-17 03:36:47 +04:00
|
|
|
memset(&rule, 0, sizeof(rule));
|
|
|
|
rule.categoryName = strdup("uncategorized");
|
|
|
|
rule.pats[0] = strdup("");
|
2002-04-20 01:51:03 +04:00
|
|
|
rule.patlen[0] = 0;
|
2002-04-17 03:36:47 +04:00
|
|
|
rule.npats = 1;
|
|
|
|
ProcessCategoryLeafRule(&rule, &g->mCategoryRoot, g);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** callsiteMatchesRule
|
|
|
|
**
|
|
|
|
** Returns the corresponding node if callsite matches the rule. Rule is a sequence
|
|
|
|
** of patterns that must match contiguously the callsite.
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
callsiteMatchesRule(tmcallsite * aCallsite, STCategoryRule * aRule)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
PRUint32 patnum = 0;
|
|
|
|
const char *methodName = NULL;
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
while (patnum < aRule->npats && aCallsite && aCallsite->method) {
|
2002-04-17 03:36:47 +04:00
|
|
|
methodName = tmmethodnode_name(aCallsite->method);
|
|
|
|
if (!methodName)
|
|
|
|
return 0;
|
2003-06-18 01:10:49 +04:00
|
|
|
if (!*aRule->pats[patnum]
|
|
|
|
|| !strncmp(methodName, aRule->pats[patnum],
|
|
|
|
aRule->patlen[patnum])) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* We have matched so far. Proceed up the stack and to the next pattern */
|
|
|
|
patnum++;
|
|
|
|
aCallsite = aCallsite->parent;
|
|
|
|
}
|
2003-06-18 01:10:49 +04:00
|
|
|
else {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Deal with mismatch */
|
2003-06-18 01:10:49 +04:00
|
|
|
if (patnum > 0) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* contiguous mismatch. Stop */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* We still haven't matched the first pattern. Proceed up the stack without
|
2003-06-18 01:10:49 +04:00
|
|
|
** moving to the next pattern.
|
|
|
|
*/
|
2002-04-17 03:36:47 +04:00
|
|
|
aCallsite = aCallsite->parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
if (patnum == aRule->npats) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* all patterns matched. We have a winner. */
|
|
|
|
#if defined(DEBUG_dp) && 0
|
|
|
|
fprintf(stderr, "[%s] match\n", aRule->categoryName);
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-04-20 01:51:03 +04:00
|
|
|
#ifdef DEBUG_dp
|
|
|
|
PRIntervalTime _gMatchTime = 0;
|
|
|
|
PRUint32 _gMatchCount = 0;
|
|
|
|
PRUint32 _gMatchRules = 0;
|
|
|
|
#endif
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
/*
|
|
|
|
** matchAllocation
|
|
|
|
**
|
|
|
|
** Runs through all rules and returns the node corresponding to
|
|
|
|
** a match of the allocation.
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *
|
|
|
|
matchAllocation(STGlobals * g, STAllocation * aAllocation)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2002-04-20 01:51:03 +04:00
|
|
|
#ifdef DEBUG_dp
|
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
|
|
|
#endif
|
2002-04-17 03:36:47 +04:00
|
|
|
PRUint32 rulenum;
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *node = NULL;
|
|
|
|
STCategoryRule *rule;
|
2002-04-17 03:36:47 +04:00
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
for (rulenum = 0; rulenum < g->mNRules; rulenum++) {
|
2002-04-20 01:51:03 +04:00
|
|
|
#ifdef DEBUG_dp
|
|
|
|
_gMatchRules++;
|
|
|
|
#endif
|
2002-04-17 03:36:47 +04:00
|
|
|
rule = g->mCategoryRules[rulenum];
|
2003-06-18 01:10:49 +04:00
|
|
|
if (callsiteMatchesRule(aAllocation->mEvents[0].mCallsite, rule)) {
|
2002-04-20 01:51:03 +04:00
|
|
|
node = rule->node;
|
|
|
|
break;
|
|
|
|
}
|
2002-04-17 03:36:47 +04:00
|
|
|
}
|
2002-04-20 01:51:03 +04:00
|
|
|
#ifdef DEBUG_dp
|
|
|
|
_gMatchCount++;
|
|
|
|
_gMatchTime += PR_IntervalNow() - start;
|
|
|
|
#endif
|
|
|
|
return node;
|
2002-04-17 03:36:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** categorizeAllocation
|
|
|
|
**
|
|
|
|
** Given an allocation, it adds it into the category tree at the right spot
|
|
|
|
** by comparing the allocation to the rules and adding into the right node.
|
|
|
|
** Also, does propogation of cost upwards in the tree.
|
|
|
|
** The root of the tree is in the globls as the tree is dependent on the
|
|
|
|
** category file (options) rather than the run.
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
categorizeAllocation(STOptions * inOptions, STContext * inContext,
|
|
|
|
STAllocation * aAllocation, STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
/* Run through the rules in order to see if this allcation matches
|
2003-06-18 01:10:49 +04:00
|
|
|
** any of them.
|
|
|
|
*/
|
|
|
|
STCategoryNode *node;
|
2002-04-17 03:36:47 +04:00
|
|
|
|
|
|
|
node = matchAllocation(g, aAllocation);
|
2003-06-18 01:10:49 +04:00
|
|
|
if (!node) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* ugh! it should atleast go into the "uncategorized" node. wierd!
|
2003-06-18 01:10:49 +04:00
|
|
|
*/
|
2002-04-17 03:36:47 +04:00
|
|
|
REPORT_ERROR(__LINE__, categorizeAllocation);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create run for node if not already */
|
2003-06-18 01:10:49 +04:00
|
|
|
if (!node->runs[inContext->mIndex]) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** Create run with positive timestamp as we can harvest it later
|
|
|
|
** for callsite details summarization
|
|
|
|
*/
|
|
|
|
node->runs[inContext->mIndex] =
|
|
|
|
createRun(inContext, PR_IntervalNow());
|
|
|
|
if (!node->runs[inContext->mIndex]) {
|
2002-04-17 03:36:47 +04:00
|
|
|
REPORT_ERROR(__LINE__, categorizeAllocation_No_Memory);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add allocation into node. We expand the table of allocations in steps */
|
2003-06-18 01:10:49 +04:00
|
|
|
if (node->runs[inContext->mIndex]->mAllocationCount % ST_ALLOC_STEP == 0) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Need more space */
|
2003-06-18 01:10:49 +04:00
|
|
|
STAllocation **allocs;
|
|
|
|
|
|
|
|
allocs =
|
|
|
|
(STAllocation **) realloc(node->runs[inContext->mIndex]->
|
|
|
|
mAllocations,
|
|
|
|
(node->runs[inContext->mIndex]->
|
|
|
|
mAllocationCount +
|
|
|
|
ST_ALLOC_STEP) *
|
|
|
|
sizeof(STAllocation *));
|
|
|
|
if (!allocs) {
|
2002-04-17 03:36:47 +04:00
|
|
|
REPORT_ERROR(__LINE__, categorizeAllocation_No_Memory);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-05-13 05:48:30 +04:00
|
|
|
node->runs[inContext->mIndex]->mAllocations = allocs;
|
2002-04-17 03:36:47 +04:00
|
|
|
}
|
2003-06-18 01:10:49 +04:00
|
|
|
node->runs[inContext->mIndex]->mAllocations[node->
|
|
|
|
runs[inContext->mIndex]->
|
|
|
|
mAllocationCount++] =
|
|
|
|
aAllocation;
|
2002-04-17 03:36:47 +04:00
|
|
|
|
2002-04-19 00:11:45 +04:00
|
|
|
/*
|
2005-11-25 22:48:04 +03:00
|
|
|
** Make sure run's stats are calculated. We don't go update the parents of allocation
|
2003-06-18 01:10:49 +04:00
|
|
|
** at this time. That will happen when we focus on this category. This updating of
|
|
|
|
** stats will provide us fast categoryreports.
|
|
|
|
*/
|
|
|
|
recalculateAllocationCost(inOptions, inContext,
|
|
|
|
node->runs[inContext->mIndex], aAllocation,
|
|
|
|
PR_FALSE);
|
2002-04-19 00:11:45 +04:00
|
|
|
|
2006-11-02 02:02:18 +03:00
|
|
|
/* Propagate upwards the statistics */
|
2002-04-17 03:36:47 +04:00
|
|
|
/* XXX */
|
|
|
|
#if defined(DEBUG_dp) && 0
|
|
|
|
fprintf(stderr, "DEBUG: [%s] match\n", node->categoryName);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
typedef PRBool STCategoryNodeProcessor(STRequest * inRequest,
|
|
|
|
STOptions * inOptions,
|
|
|
|
STContext * inContext,
|
|
|
|
void *clientData,
|
|
|
|
STCategoryNode * node);
|
2002-05-13 05:48:30 +04:00
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
PRBool
|
|
|
|
freeNodeRunProcessor(STRequest * inRequest, STOptions * inOptions,
|
|
|
|
STContext * inContext, void *clientData,
|
|
|
|
STCategoryNode * node)
|
2002-05-13 05:48:30 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
if (node->runs && node->runs[inContext->mIndex]) {
|
2002-05-13 05:48:30 +04:00
|
|
|
freeRun(node->runs[inContext->mIndex]);
|
|
|
|
node->runs[inContext->mIndex] = NULL;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2002-04-17 03:36:47 +04:00
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
PRBool
|
|
|
|
freeNodeRunsProcessor(STRequest * inRequest, STOptions * inOptions,
|
|
|
|
STContext * inContext, void *clientData,
|
|
|
|
STCategoryNode * node)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
if (node->runs) {
|
2002-05-13 05:48:30 +04:00
|
|
|
PRUint32 loop = 0;
|
2003-06-18 01:10:49 +04:00
|
|
|
|
|
|
|
for (loop = 0; loop < globals.mCommandLineOptions.mContexts; loop++) {
|
|
|
|
if (node->runs[loop]) {
|
2002-05-13 05:48:30 +04:00
|
|
|
freeRun(node->runs[loop]);
|
|
|
|
node->runs[loop] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-06-18 01:10:49 +04:00
|
|
|
|
2002-05-13 05:48:30 +04:00
|
|
|
free(node->runs);
|
|
|
|
node->runs = NULL;
|
2002-04-17 03:36:47 +04:00
|
|
|
}
|
2002-05-13 05:48:30 +04:00
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_dp)
|
2003-06-18 01:10:49 +04:00
|
|
|
PRBool
|
|
|
|
printNodeProcessor(STRequest * inRequest, STOptions * inOptions,
|
|
|
|
STContext * inContext, void *clientData,
|
|
|
|
STCategoryNode * node)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *root = (STCategoryNode *) clientData;
|
|
|
|
|
2002-05-01 03:44:03 +04:00
|
|
|
fprintf(stderr, "%-25s [ %9s size", node->categoryName,
|
2003-06-18 01:10:49 +04:00
|
|
|
FormatNumber(node->run ? node->run->mStats[inContext->mIndex].
|
|
|
|
mSize : 0));
|
2002-05-01 03:44:03 +04:00
|
|
|
fprintf(stderr, ", %5.1f%%",
|
2003-06-18 01:10:49 +04:00
|
|
|
node->run ? ((double) node->run->mStats[inContext->mIndex].mSize /
|
|
|
|
root->run->mStats[inContext->mIndex].mSize *
|
|
|
|
100) : 0);
|
2002-05-01 03:44:03 +04:00
|
|
|
fprintf(stderr, ", %7s allocations ]\n",
|
2003-06-18 01:10:49 +04:00
|
|
|
FormatNumber(node->run ? node->run->mStats[inContext->mIndex].
|
|
|
|
mCompositeCount : 0));
|
2002-04-17 03:36:47 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
typedef struct __struct_optcon
|
|
|
|
{
|
|
|
|
STOptions *mOptions;
|
|
|
|
STContext *mContext;
|
2002-05-13 05:48:30 +04:00
|
|
|
}
|
|
|
|
optcon;
|
|
|
|
|
2002-04-20 04:25:55 +04:00
|
|
|
/*
|
|
|
|
** compareNode
|
|
|
|
**
|
|
|
|
** qsort callback.
|
|
|
|
** Compare the nodes as specified by the options.
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
compareNode(const void *aNode1, const void *aNode2, void *aContext)
|
2002-04-20 04:25:55 +04:00
|
|
|
{
|
|
|
|
int retval = 0;
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *node1, *node2;
|
2002-04-20 04:25:55 +04:00
|
|
|
PRUint32 a, b;
|
2003-06-18 01:10:49 +04:00
|
|
|
optcon *oc = (optcon *) aContext;
|
2002-04-20 04:25:55 +04:00
|
|
|
|
2002-05-13 05:48:30 +04:00
|
|
|
if (!aNode1 || !aNode2 || !oc->mOptions || !oc->mContext)
|
2002-04-20 04:25:55 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
node1 = *((STCategoryNode **) aNode1);
|
|
|
|
node2 = *((STCategoryNode **) aNode2);
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
if (node1 && node2) {
|
|
|
|
if (oc->mOptions->mOrderBy == ST_COUNT) {
|
|
|
|
a = (node1->runs[oc->mContext->mIndex]) ? node1->runs[oc->
|
|
|
|
mContext->
|
|
|
|
mIndex]->
|
|
|
|
mStats[oc->mContext->mIndex].mCompositeCount : 0;
|
|
|
|
b = (node2->runs[oc->mContext->mIndex]) ? node2->runs[oc->
|
|
|
|
mContext->
|
|
|
|
mIndex]->
|
|
|
|
mStats[oc->mContext->mIndex].mCompositeCount : 0;
|
2002-04-20 04:25:55 +04:00
|
|
|
}
|
2003-06-18 01:10:49 +04:00
|
|
|
else {
|
2002-04-20 04:25:55 +04:00
|
|
|
/* Default is by size */
|
2003-06-18 01:10:49 +04:00
|
|
|
a = (node1->runs[oc->mContext->mIndex]) ? node1->runs[oc->
|
|
|
|
mContext->
|
|
|
|
mIndex]->
|
|
|
|
mStats[oc->mContext->mIndex].mSize : 0;
|
|
|
|
b = (node2->runs[oc->mContext->mIndex]) ? node2->runs[oc->
|
|
|
|
mContext->
|
|
|
|
mIndex]->
|
|
|
|
mStats[oc->mContext->mIndex].mSize : 0;
|
2002-04-20 04:25:55 +04:00
|
|
|
}
|
|
|
|
if (a < b)
|
|
|
|
retval = __LINE__;
|
|
|
|
else
|
2003-06-18 01:10:49 +04:00
|
|
|
retval = -__LINE__;
|
2002-04-20 04:25:55 +04:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
PRBool
|
|
|
|
sortNodeProcessor(STRequest * inRequest, STOptions * inOptions,
|
|
|
|
STContext * inContext, void *clientData,
|
|
|
|
STCategoryNode * node)
|
2002-04-20 04:25:55 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
if (node->nchildren) {
|
2002-05-13 05:48:30 +04:00
|
|
|
optcon context;
|
|
|
|
|
|
|
|
context.mOptions = inOptions;
|
|
|
|
context.mContext = inContext;
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
NS_QuickSort(node->children, node->nchildren,
|
|
|
|
sizeof(STCategoryNode *), compareNode, &context);
|
2002-05-13 05:48:30 +04:00
|
|
|
}
|
2002-04-20 04:25:55 +04:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
/*
|
|
|
|
** walkTree
|
|
|
|
**
|
2002-04-19 00:11:45 +04:00
|
|
|
** General purpose tree walker. Issues callback for each node.
|
|
|
|
** If 'maxdepth' > 0, then stops after processing that depth. Root is
|
|
|
|
** depth 0, the nodes below it are depth 1 etc...
|
2002-04-17 03:36:47 +04:00
|
|
|
*/
|
|
|
|
#define MODINC(n, mod) ((n+1) % mod)
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
void
|
|
|
|
walkTree(STCategoryNode * root, STCategoryNodeProcessor func,
|
|
|
|
STRequest * inRequest, STOptions * inOptions, STContext * inContext,
|
|
|
|
void *clientData, int maxdepth)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *nodes[1024], *node;
|
2002-04-17 03:36:47 +04:00
|
|
|
PRUint32 begin, end, i;
|
|
|
|
int ret = 0;
|
2002-04-19 00:11:45 +04:00
|
|
|
int curdepth = 0, ncurdepth = 0;
|
2002-04-17 03:36:47 +04:00
|
|
|
|
|
|
|
nodes[0] = root;
|
2003-06-18 01:10:49 +04:00
|
|
|
begin = 0;
|
|
|
|
end = 1;
|
2002-04-19 00:11:45 +04:00
|
|
|
ncurdepth = 1;
|
2003-06-18 01:10:49 +04:00
|
|
|
while (begin != end) {
|
2002-04-17 03:36:47 +04:00
|
|
|
node = nodes[begin];
|
2003-06-18 01:10:49 +04:00
|
|
|
ret = (*func) (inRequest, inOptions, inContext, clientData, node);
|
|
|
|
if (ret == PR_FALSE) {
|
2002-04-17 03:36:47 +04:00
|
|
|
/* Abort */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
begin = MODINC(begin, 1024);
|
2003-06-18 01:10:49 +04:00
|
|
|
for (i = 0; i < node->nchildren; i++) {
|
2002-04-17 03:36:47 +04:00
|
|
|
nodes[end] = node->children[i];
|
|
|
|
end = MODINC(end, 1024);
|
|
|
|
}
|
2002-04-19 00:11:45 +04:00
|
|
|
/* Depth tracking. Do it only if walkTree is contrained by a maxdepth */
|
2003-06-18 01:10:49 +04:00
|
|
|
if (maxdepth > 0 && --ncurdepth == 0) {
|
2002-04-19 00:11:45 +04:00
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** No more children in current depth. The rest of the nodes
|
|
|
|
** we have in our list should be nodes in the depth below us.
|
|
|
|
*/
|
2002-04-19 00:11:45 +04:00
|
|
|
ncurdepth = (begin < end) ? (end - begin) : (1024 - begin + end);
|
2003-06-18 01:10:49 +04:00
|
|
|
if (++curdepth > maxdepth) {
|
2002-04-19 00:11:45 +04:00
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** Gone too deep. Stop.
|
|
|
|
*/
|
2002-04-19 00:11:45 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-04-17 03:36:47 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
freeRule(STCategoryRule * rule)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
PRUint32 i;
|
2003-06-18 01:10:49 +04:00
|
|
|
char *p = (char *) rule->categoryName;
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
PR_FREEIF(p);
|
|
|
|
|
|
|
|
for (i = 0; i < rule->npats; i++)
|
|
|
|
free(rule->pats[i]);
|
|
|
|
|
|
|
|
free(rule);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
void
|
|
|
|
freeNodeRuns(STCategoryNode * root)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
walkTree(root, freeNodeRunsProcessor, NULL, NULL, NULL, NULL, 0);
|
2002-04-17 03:36:47 +04:00
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
void
|
|
|
|
freeNodeMap(STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
PRUint32 i;
|
|
|
|
|
|
|
|
/* all nodes are in the map table. Just delete all of those. */
|
2003-06-18 01:10:49 +04:00
|
|
|
for (i = 0; i < g->mNCategoryMap; i++) {
|
2002-04-17 03:36:47 +04:00
|
|
|
free(g->mCategoryMap[i]->node);
|
|
|
|
free(g->mCategoryMap[i]);
|
|
|
|
}
|
|
|
|
free(g->mCategoryMap);
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
freeCategories(STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
PRUint32 i;
|
|
|
|
|
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** walk the tree and free runs held in nodes
|
|
|
|
*/
|
2002-05-13 05:48:30 +04:00
|
|
|
freeNodeRuns(&g->mCategoryRoot);
|
2002-04-17 03:36:47 +04:00
|
|
|
|
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** delete nodemap. This is the where nodes get deleted.
|
|
|
|
*/
|
2002-04-17 03:36:47 +04:00
|
|
|
freeNodeMap(g);
|
|
|
|
|
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** delete rule stuff
|
|
|
|
*/
|
|
|
|
for (i = 0; i < g->mNRules; i++) {
|
2002-04-17 03:36:47 +04:00
|
|
|
freeRule(g->mCategoryRules[i]);
|
|
|
|
}
|
|
|
|
free(g->mCategoryRules);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** categorizeRun
|
|
|
|
**
|
|
|
|
** categorize all the allocations of the run using the rules into
|
|
|
|
** a tree rooted at globls.mCategoryRoot
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
categorizeRun(STOptions * inOptions, STContext * inContext,
|
|
|
|
const STRun * aRun, STGlobals * g)
|
2002-04-17 03:36:47 +04:00
|
|
|
{
|
|
|
|
PRUint32 i;
|
2003-06-18 01:10:49 +04:00
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
#if defined(DEBUG_dp)
|
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
2003-06-18 01:10:49 +04:00
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
fprintf(stderr, "DEBUG: categorizing run...\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** First, cleanup our tree
|
|
|
|
*/
|
|
|
|
walkTree(&g->mCategoryRoot, freeNodeRunProcessor, NULL, inOptions,
|
|
|
|
inContext, NULL, 0);
|
|
|
|
|
|
|
|
if (g->mNCategoryMap > 0) {
|
|
|
|
for (i = 0; i < aRun->mAllocationCount; i++) {
|
|
|
|
categorizeAllocation(inOptions, inContext, aRun->mAllocations[i],
|
|
|
|
g);
|
2002-04-17 04:11:55 +04:00
|
|
|
}
|
2002-04-17 03:36:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** the run is always going to be the one corresponding to the root node
|
|
|
|
*/
|
2002-05-13 05:48:30 +04:00
|
|
|
g->mCategoryRoot.runs[inContext->mIndex] = (STRun *) aRun;
|
2002-04-17 03:36:47 +04:00
|
|
|
g->mCategoryRoot.categoryName = ST_ROOT_CATEGORY_NAME;
|
|
|
|
|
|
|
|
#if defined(DEBUG_dp)
|
2003-06-18 01:10:49 +04:00
|
|
|
fprintf(stderr,
|
|
|
|
"DEBUG: categorizing ends: %dms [%d rules, %d allocations]\n",
|
|
|
|
PR_IntervalToMilliseconds(PR_IntervalNow() - start), g->mNRules,
|
|
|
|
aRun->mAllocationCount);
|
2002-04-20 01:51:03 +04:00
|
|
|
fprintf(stderr, "DEBUG: match : %dms [%d calls, %d rule-compares]\n",
|
2003-06-18 01:10:49 +04:00
|
|
|
PR_IntervalToMilliseconds(_gMatchTime), _gMatchCount,
|
|
|
|
_gMatchRules);
|
2002-04-17 03:36:47 +04:00
|
|
|
#endif
|
|
|
|
|
2002-04-20 04:25:55 +04:00
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** sort the tree based on our sort criterion
|
|
|
|
*/
|
|
|
|
walkTree(&g->mCategoryRoot, sortNodeProcessor, NULL, inOptions, inContext,
|
|
|
|
NULL, 0);
|
2002-04-20 04:25:55 +04:00
|
|
|
|
|
|
|
#if defined(DEBUG_dp)
|
2003-06-18 01:10:49 +04:00
|
|
|
walkTree(&g->mCategoryRoot, printNodeProcessor, NULL, inOptions,
|
|
|
|
inContext, &g->mCategoryRoot, 0);
|
2002-04-20 04:25:55 +04:00
|
|
|
#endif
|
|
|
|
|
2002-04-17 03:36:47 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-04-19 00:11:45 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** displayCategoryReport
|
|
|
|
**
|
|
|
|
** Generate the category report - a list of all categories and details about each
|
|
|
|
** depth parameter controls how deep we traverse the category tree.
|
|
|
|
*/
|
2003-06-18 01:10:49 +04:00
|
|
|
PRBool
|
|
|
|
displayCategoryNodeProcessor(STRequest * inRequest, STOptions * inOptions,
|
|
|
|
STContext * inContext, void *clientData,
|
|
|
|
STCategoryNode * node)
|
2002-04-19 00:11:45 +04:00
|
|
|
{
|
2003-06-18 01:10:49 +04:00
|
|
|
STCategoryNode *root = (STCategoryNode *) clientData;
|
2002-04-19 00:11:45 +04:00
|
|
|
PRUint32 byteSize = 0, heapCost = 0, count = 0;
|
|
|
|
double percent = 0;
|
2002-05-11 05:24:52 +04:00
|
|
|
STOptions customOps;
|
2002-04-19 00:11:45 +04:00
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
if (node->runs[inContext->mIndex]) {
|
2002-04-19 00:11:45 +04:00
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** Byte size
|
|
|
|
*/
|
|
|
|
byteSize =
|
|
|
|
node->runs[inContext->mIndex]->mStats[inContext->mIndex].mSize;
|
2002-04-19 00:11:45 +04:00
|
|
|
|
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** Composite count
|
|
|
|
*/
|
|
|
|
count =
|
|
|
|
node->runs[inContext->mIndex]->mStats[inContext->mIndex].
|
|
|
|
mCompositeCount;
|
2002-04-19 00:11:45 +04:00
|
|
|
|
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** Heap operation cost
|
|
|
|
**/
|
|
|
|
heapCost =
|
|
|
|
node->runs[inContext->mIndex]->mStats[inContext->mIndex].
|
|
|
|
mHeapRuntimeCost;
|
2002-04-19 00:11:45 +04:00
|
|
|
|
|
|
|
/*
|
2003-06-18 01:10:49 +04:00
|
|
|
** % of total size
|
|
|
|
*/
|
|
|
|
if (root->runs[inContext->mIndex]) {
|
|
|
|
percent =
|
|
|
|
((double) byteSize) /
|
|
|
|
root->runs[inContext->mIndex]->mStats[inContext->mIndex].
|
|
|
|
mSize * 100;
|
2002-04-19 00:11:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
PR_fprintf(inRequest->mFD, " <tr>\n" " <td>");
|
2002-05-11 05:24:52 +04:00
|
|
|
|
2002-04-19 00:11:45 +04:00
|
|
|
/* a link to topcallsites report with focus on category */
|
2002-05-13 04:01:15 +04:00
|
|
|
memcpy(&customOps, inOptions, sizeof(customOps));
|
2003-06-18 01:10:49 +04:00
|
|
|
PR_snprintf(customOps.mCategoryName, sizeof(customOps.mCategoryName),
|
|
|
|
"%s", node->categoryName);
|
2002-05-11 05:24:52 +04:00
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
htmlAnchor(inRequest, "top_callsites.html", node->categoryName, NULL,
|
|
|
|
"category-callsites", &customOps);
|
2002-05-02 22:38:42 +04:00
|
|
|
PR_fprintf(inRequest->mFD,
|
2003-06-18 01:10:49 +04:00
|
|
|
"</td>\n" " <td align=right>%u</td>\n"
|
2002-04-19 00:11:45 +04:00
|
|
|
" <td align=right>%4.1f%%</td>\n"
|
2003-06-18 01:10:49 +04:00
|
|
|
" <td align=right>%u</td>\n" " <td align=right>"
|
|
|
|
ST_MICROVAL_FORMAT "</td>\n" " </tr>\n", byteSize, percent,
|
|
|
|
count, ST_MICROVAL_PRINTABLE(heapCost));
|
2002-04-19 00:11:45 +04:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
int
|
|
|
|
displayCategoryReport(STRequest * inRequest, STCategoryNode * root, int depth)
|
2002-04-19 00:11:45 +04:00
|
|
|
{
|
2002-05-02 22:38:42 +04:00
|
|
|
PR_fprintf(inRequest->mFD,
|
2003-04-17 11:36:28 +04:00
|
|
|
"<table class=\"category-list data\">\n"
|
2003-04-21 11:26:07 +04:00
|
|
|
" <tr class=\"row-header\">\n"
|
2002-04-19 00:11:45 +04:00
|
|
|
" <th>Category</th>\n"
|
|
|
|
" <th>Composite Byte Size</th>\n"
|
|
|
|
" <th>%% of Total Size</th>\n"
|
|
|
|
" <th>Heap Object Count</th>\n"
|
2003-06-18 01:10:49 +04:00
|
|
|
" <th>Composite Heap Operations Seconds</th>\n" " </tr>\n");
|
2002-04-19 00:11:45 +04:00
|
|
|
|
2003-06-18 01:10:49 +04:00
|
|
|
walkTree(root, displayCategoryNodeProcessor, inRequest,
|
|
|
|
&inRequest->mOptions, inRequest->mContext, root, depth);
|
2002-04-19 00:11:45 +04:00
|
|
|
|
2002-05-02 22:38:42 +04:00
|
|
|
PR_fprintf(inRequest->mFD, "</table>\n");
|
2002-04-19 00:11:45 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|