diff --git a/tools/trace-malloc/spacecategory.c b/tools/trace-malloc/spacecategory.c
index 51fa1cb931b..d60ed6a45d8 100644
--- a/tools/trace-malloc/spacecategory.c
+++ b/tools/trace-malloc/spacecategory.c
@@ -69,16 +69,18 @@
**
** Add a rule into the list of rules maintainted in global
*/
-int AddRule(STGlobals *g, STCategoryRule *rule)
+int
+AddRule(STGlobals * g, STCategoryRule * rule)
{
- if (g->mNRules % ST_ALLOC_STEP == 0)
- {
+ if (g->mNRules % ST_ALLOC_STEP == 0) {
/* Need more space */
- STCategoryRule** newrules;
+ STCategoryRule **newrules;
+
newrules = (STCategoryRule **) realloc(g->mCategoryRules,
- (g->mNRules + ST_ALLOC_STEP)*sizeof(STCategoryRule *));
- if (!newrules)
- {
+ (g->mNRules +
+ ST_ALLOC_STEP) *
+ sizeof(STCategoryRule *));
+ if (!newrules) {
REPORT_ERROR(__LINE__, AddRule_No_Memory);
return -1;
}
@@ -93,16 +95,18 @@ int AddRule(STGlobals *g, STCategoryRule *rule)
**
** Add the node as a child of the parent node
*/
-int AddChild(STCategoryNode* parent, STCategoryNode* child)
+int
+AddChild(STCategoryNode * parent, STCategoryNode * child)
{
- if (parent->nchildren % ST_ALLOC_STEP == 0)
- {
+ if (parent->nchildren % ST_ALLOC_STEP == 0) {
/* need more space */
- STCategoryNode** newnodes;
+ STCategoryNode **newnodes;
+
newnodes = (STCategoryNode **) realloc(parent->children,
- (parent->nchildren + ST_ALLOC_STEP)*sizeof(STCategoryNode *));
- if (!newnodes)
- {
+ (parent->nchildren +
+ ST_ALLOC_STEP) *
+ sizeof(STCategoryNode *));
+ if (!newnodes) {
REPORT_ERROR(__LINE__, AddChild_No_Memory);
return -1;
}
@@ -112,23 +116,24 @@ int AddChild(STCategoryNode* parent, STCategoryNode* child)
return 0;
}
-int ReParent(STCategoryNode* parent, STCategoryNode* child)
+int
+ReParent(STCategoryNode * parent, STCategoryNode * child)
{
PRUint32 i;
+
if (child->parent == parent)
return 0;
/* Remove child from old parent */
- if (child->parent)
- {
- for (i = 0; i < child->parent->nchildren; i++)
- {
- if (child->parent->children[i] == child)
- {
+ if (child->parent) {
+ for (i = 0; i < child->parent->nchildren; i++) {
+ if (child->parent->children[i] == child) {
/* Remove child from list */
- if (i+1 < child->parent->nchildren)
- memmove(&child->parent->children[i], &child->parent->children[i+1],
- (child->parent->nchildren - i - 1) * sizeof(STCategoryNode*));
+ if (i + 1 < child->parent->nchildren)
+ memmove(&child->parent->children[i],
+ &child->parent->children[i + 1],
+ (child->parent->nchildren - i -
+ 1) * sizeof(STCategoryNode *));
child->parent->nchildren--;
break;
}
@@ -146,11 +151,12 @@ int ReParent(STCategoryNode* parent, STCategoryNode* child)
**
** Given a category name, finds the Node corresponding to the category
*/
-STCategoryNode* findCategoryNode(const char *catName, STGlobals *g)
+STCategoryNode *
+findCategoryNode(const char *catName, STGlobals * g)
{
PRUint32 i;
- for(i = 0; i < g->mNCategoryMap; i++)
- {
+
+ for (i = 0; i < g->mNCategoryMap; i++) {
if (!strcmp(g->mCategoryMap[i]->categoryName, catName))
return g->mCategoryMap[i]->node;
}
@@ -167,24 +173,26 @@ STCategoryNode* findCategoryNode(const char *catName, STGlobals *g)
**
** Adds a mapping between a category and its Node into the categoryMap
*/
-int AddCategoryNode(STCategoryNode* node, STGlobals* g)
+int
+AddCategoryNode(STCategoryNode * node, STGlobals * g)
{
- if (g->mNCategoryMap % ST_ALLOC_STEP == 0)
- {
+ if (g->mNCategoryMap % ST_ALLOC_STEP == 0) {
/* Need more space */
- STCategoryMapEntry **newmap = (STCategoryMapEntry **) realloc(g->mCategoryMap,
- (g->mNCategoryMap + ST_ALLOC_STEP) * sizeof(STCategoryMapEntry *));
- if (!newmap)
- {
+ STCategoryMapEntry **newmap =
+ (STCategoryMapEntry **) realloc(g->mCategoryMap,
+ (g->mNCategoryMap +
+ ST_ALLOC_STEP) *
+ sizeof(STCategoryMapEntry *));
+ if (!newmap) {
REPORT_ERROR(__LINE__, AddCategoryNode_No_Memory);
return -1;
}
g->mCategoryMap = newmap;
}
- g->mCategoryMap[g->mNCategoryMap] = (STCategoryMapEntry *) calloc(1, sizeof(STCategoryMapEntry));
- if (!g->mCategoryMap[g->mNCategoryMap])
- {
+ g->mCategoryMap[g->mNCategoryMap] =
+ (STCategoryMapEntry *) calloc(1, sizeof(STCategoryMapEntry));
+ if (!g->mCategoryMap[g->mNCategoryMap]) {
REPORT_ERROR(__LINE__, AddCategoryNode_No_Memory);
return -1;
}
@@ -200,17 +208,18 @@ int AddCategoryNode(STCategoryNode* node, STGlobals* g)
** Creates a new category node for category name 'catname' and makes
** 'parent' its parent.
*/
-STCategoryNode* NewCategoryNode(const char* catName, STCategoryNode* parent, STGlobals* g)
+STCategoryNode *
+NewCategoryNode(const char *catName, STCategoryNode * parent, STGlobals * g)
{
- STCategoryNode* node;
+ STCategoryNode *node;
node = (STCategoryNode *) calloc(1, sizeof(STCategoryNode));
if (!node)
return NULL;
- node->runs = (STRun**)calloc(g->mCommandLineOptions.mContexts, sizeof(STRun*));
- if(NULL == node->runs)
- {
+ node->runs =
+ (STRun **) calloc(g->mCommandLineOptions.mContexts, sizeof(STRun *));
+ if (NULL == node->runs) {
free(node);
return NULL;
}
@@ -235,10 +244,12 @@ STCategoryNode* NewCategoryNode(const char* catName, STCategoryNode* parent, STG
** Add this into the tree as a leaf node. It doesnt know who its parent is. For now we make
** root as its parent
*/
-int ProcessCategoryLeafRule(STCategoryRule* leafRule, STCategoryNode *root, STGlobals *g)
+int
+ProcessCategoryLeafRule(STCategoryRule * leafRule, STCategoryNode * root,
+ STGlobals * g)
{
- STCategoryRule* rule;
- STCategoryNode* node;
+ STCategoryRule *rule;
+ STCategoryNode *node;
rule = (STCategoryRule *) calloc(1, sizeof(STCategoryRule));
if (!rule)
@@ -267,37 +278,35 @@ int ProcessCategoryLeafRule(STCategoryRule* leafRule, STCategoryNode *root, STGl
** Rule has all the children of category as patterns. Sets up the tree so that
** the parent child relationship is honored.
*/
-int ProcessCategoryParentRule(STCategoryRule* parentRule, STCategoryNode *root, STGlobals* g)
+int
+ProcessCategoryParentRule(STCategoryRule * parentRule, STCategoryNode * root,
+ STGlobals * g)
{
- STCategoryNode* node;
- STCategoryNode* child;
+ STCategoryNode *node;
+ STCategoryNode *child;
PRUint32 i;
/* Find the parent node in the tree. If not make one and add it into the tree */
node = findCategoryNode(parentRule->categoryName, g);
- if (!node)
- {
+ if (!node) {
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 */
- for(i = 0; i < parentRule->npats; i++)
- {
+ for (i = 0; i < parentRule->npats; i++) {
child = findCategoryNode(parentRule->pats[i], g);
- if (!child)
- {
+ if (!child) {
child = NewCategoryNode(parentRule->pats[i], node, g);
if (!child)
return -1;
}
- else
- {
+ else {
/* Reparent child to node. This is because when we created the node
- ** 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
- */
+ ** 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
+ */
ReParent(node, child);
}
}
@@ -312,7 +321,8 @@ int ProcessCategoryParentRule(STCategoryRule* parentRule, STCategoryNode *root,
** each callsite, creates a tree of these categories and makes a list of these
** patterns in order for matching
*/
-int initCategories(STGlobals* g)
+int
+initCategories(STGlobals * g)
{
FILE *fp;
char buf[1024], *in;
@@ -321,8 +331,7 @@ int initCategories(STGlobals* g)
STCategoryRule rule;
fp = fopen(g->mCommandLineOptions.mCategoryFile, "r");
- if (!fp)
- {
+ if (!fp) {
/* It isnt an error to not have a categories file */
REPORT_INFO("No categories file.");
return -1;
@@ -333,11 +342,10 @@ int initCategories(STGlobals* g)
memset(&rule, 0, sizeof(rule));
- while (fgets(buf, sizeof(buf), fp) != NULL)
- {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
/* Lose the \n */
n = strlen(buf);
- if (buf[n-1] == '\n')
+ if (buf[n - 1] == '\n')
buf[--n] = '\0';
in = buf;
@@ -346,12 +354,11 @@ int initCategories(STGlobals* g)
continue;
/* skip empty lines. If we are in a rule, end the rule. */
- while(*in && isspace(*in))
+ while (*in && isspace(*in))
in++;
if (*in == '\0') {
- if (inrule)
- {
- /* End the rule : leaf or non-leaf*/
+ if (inrule) {
+ /* End the rule : leaf or non-leaf */
if (leaf)
ProcessCategoryLeafRule(&rule, &g->mCategoryRoot, g);
else
@@ -364,13 +371,11 @@ int initCategories(STGlobals* g)
}
/* if we are in a rule acculumate */
- if (inrule)
- {
+ if (inrule) {
rule.pats[rule.npats] = strdup(in);
rule.patlen[rule.npats++] = strlen(in);
}
- else if (*in == '<')
- {
+ else if (*in == '<') {
/* Start a category */
inrule = PR_TRUE;
leaf = PR_TRUE;
@@ -378,15 +383,14 @@ int initCategories(STGlobals* g)
/* Get the category name */
in++;
n = strlen(in);
- if (in[n-1] == '>')
- in[n-1] = '\0';
+ if (in[n - 1] == '>')
+ in[n - 1] = '\0';
rule.categoryName = strdup(in);
}
- else
- {
+ else {
/* this is a non-leaf category. Should be of the form CategoryName
- ** followed by list of child category names one per line
- */
+ ** followed by list of child category names one per line
+ */
inrule = PR_TRUE;
leaf = PR_FALSE;
rule.categoryName = strdup(in);
@@ -394,9 +398,8 @@ int initCategories(STGlobals* g)
}
/* If we were in a rule when processing the last line, end the rule */
- if (inrule)
- {
- /* End the rule : leaf or non-leaf*/
+ if (inrule) {
+ /* End the rule : leaf or non-leaf */
if (leaf)
ProcessCategoryLeafRule(&rule, &g->mCategoryRoot, g);
else
@@ -405,9 +408,9 @@ int initCategories(STGlobals* g)
}
/* Add the final "uncategorized" category. We make new memory locations
- ** for all these to conform to the general principle of all strings are allocated
- ** so it makes release logic very simple.
- */
+ ** for all these to conform to the general principle of all strings are allocated
+ ** so it makes release logic very simple.
+ */
memset(&rule, 0, sizeof(rule));
rule.categoryName = strdup("uncategorized");
rule.pats[0] = strdup("");
@@ -424,39 +427,37 @@ int initCategories(STGlobals* g)
** Returns the corresponding node if callsite matches the rule. Rule is a sequence
** of patterns that must match contiguously the callsite.
*/
-int callsiteMatchesRule(tmcallsite* aCallsite, STCategoryRule* aRule)
+int
+callsiteMatchesRule(tmcallsite * aCallsite, STCategoryRule * aRule)
{
PRUint32 patnum = 0;
const char *methodName = NULL;
- while (patnum < aRule->npats && aCallsite && aCallsite->method)
- {
+ while (patnum < aRule->npats && aCallsite && aCallsite->method) {
methodName = tmmethodnode_name(aCallsite->method);
if (!methodName)
return 0;
- if (!*aRule->pats[patnum] || !strncmp(methodName, aRule->pats[patnum], aRule->patlen[patnum]))
- {
+ if (!*aRule->pats[patnum]
+ || !strncmp(methodName, aRule->pats[patnum],
+ aRule->patlen[patnum])) {
/* We have matched so far. Proceed up the stack and to the next pattern */
patnum++;
aCallsite = aCallsite->parent;
}
- else
- {
+ else {
/* Deal with mismatch */
- if (patnum > 0)
- {
+ if (patnum > 0) {
/* contiguous mismatch. Stop */
return 0;
}
/* We still haven't matched the first pattern. Proceed up the stack without
- ** moving to the next pattern.
- */
+ ** moving to the next pattern.
+ */
aCallsite = aCallsite->parent;
}
}
- if (patnum == aRule->npats)
- {
+ if (patnum == aRule->npats) {
/* all patterns matched. We have a winner. */
#if defined(DEBUG_dp) && 0
fprintf(stderr, "[%s] match\n", aRule->categoryName);
@@ -479,23 +480,22 @@ PRUint32 _gMatchRules = 0;
** Runs through all rules and returns the node corresponding to
** a match of the allocation.
*/
-STCategoryNode* matchAllocation(STGlobals* g, STAllocation* aAllocation)
+STCategoryNode *
+matchAllocation(STGlobals * g, STAllocation * aAllocation)
{
#ifdef DEBUG_dp
PRIntervalTime start = PR_IntervalNow();
#endif
PRUint32 rulenum;
- STCategoryNode* node = NULL;
- STCategoryRule* rule;
+ STCategoryNode *node = NULL;
+ STCategoryRule *rule;
- for (rulenum = 0; rulenum < g->mNRules; rulenum++)
- {
+ for (rulenum = 0; rulenum < g->mNRules; rulenum++) {
#ifdef DEBUG_dp
_gMatchRules++;
#endif
rule = g->mCategoryRules[rulenum];
- if (callsiteMatchesRule(aAllocation->mEvents[0].mCallsite, rule))
- {
+ if (callsiteMatchesRule(aAllocation->mEvents[0].mCallsite, rule)) {
node = rule->node;
break;
}
@@ -516,59 +516,68 @@ STCategoryNode* matchAllocation(STGlobals* g, STAllocation* aAllocation)
** The root of the tree is in the globls as the tree is dependent on the
** category file (options) rather than the run.
*/
-int categorizeAllocation(STOptions* inOptions, STContext* inContext, STAllocation* aAllocation, STGlobals* g)
+int
+categorizeAllocation(STOptions * inOptions, STContext * inContext,
+ STAllocation * aAllocation, STGlobals * g)
{
/* Run through the rules in order to see if this allcation matches
- ** any of them.
- */
- STCategoryNode* node;
+ ** any of them.
+ */
+ STCategoryNode *node;
node = matchAllocation(g, aAllocation);
- if (!node)
- {
+ if (!node) {
/* ugh! it should atleast go into the "uncategorized" node. wierd!
- */
+ */
REPORT_ERROR(__LINE__, categorizeAllocation);
return -1;
}
/* Create run for node if not already */
- if (!node->runs[inContext->mIndex])
- {
+ if (!node->runs[inContext->mIndex]) {
/*
- ** 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])
- {
+ ** 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]) {
REPORT_ERROR(__LINE__, categorizeAllocation_No_Memory);
return -1;
}
}
/* Add allocation into node. We expand the table of allocations in steps */
- if (node->runs[inContext->mIndex]->mAllocationCount % ST_ALLOC_STEP == 0)
- {
+ if (node->runs[inContext->mIndex]->mAllocationCount % ST_ALLOC_STEP == 0) {
/* Need more space */
- STAllocation** allocs;
- allocs = (STAllocation**) realloc(node->runs[inContext->mIndex]->mAllocations,
- (node->runs[inContext->mIndex]->mAllocationCount + ST_ALLOC_STEP) * sizeof(STAllocation*));
- if (!allocs)
- {
+ STAllocation **allocs;
+
+ allocs =
+ (STAllocation **) realloc(node->runs[inContext->mIndex]->
+ mAllocations,
+ (node->runs[inContext->mIndex]->
+ mAllocationCount +
+ ST_ALLOC_STEP) *
+ sizeof(STAllocation *));
+ if (!allocs) {
REPORT_ERROR(__LINE__, categorizeAllocation_No_Memory);
return -1;
}
node->runs[inContext->mIndex]->mAllocations = allocs;
}
- node->runs[inContext->mIndex]->mAllocations[node->runs[inContext->mIndex]->mAllocationCount++] = aAllocation;
+ node->runs[inContext->mIndex]->mAllocations[node->
+ runs[inContext->mIndex]->
+ mAllocationCount++] =
+ aAllocation;
/*
- ** Make sure run's stats are calculated. We dont go update the parents of allocation
- ** 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);
+ ** Make sure run's stats are calculated. We dont go update the parents of allocation
+ ** 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);
/* Propogate upwards the statistics */
/* XXX */
@@ -578,33 +587,39 @@ int categorizeAllocation(STOptions* inOptions, STContext* inContext, STAllocatio
return 0;
}
-typedef PRBool STCategoryNodeProcessor(STRequest* inRequest, STOptions* inOptions, STContext* inContext, void* clientData, STCategoryNode* node);
+typedef PRBool STCategoryNodeProcessor(STRequest * inRequest,
+ STOptions * inOptions,
+ STContext * inContext,
+ void *clientData,
+ STCategoryNode * node);
-PRBool freeNodeRunProcessor(STRequest* inRequest, STOptions* inOptions, STContext* inContext, void* clientData, STCategoryNode* node)
+PRBool
+freeNodeRunProcessor(STRequest * inRequest, STOptions * inOptions,
+ STContext * inContext, void *clientData,
+ STCategoryNode * node)
{
- if (node->runs && node->runs[inContext->mIndex])
- {
+ if (node->runs && node->runs[inContext->mIndex]) {
freeRun(node->runs[inContext->mIndex]);
node->runs[inContext->mIndex] = NULL;
}
return PR_TRUE;
}
-PRBool freeNodeRunsProcessor(STRequest* inRequest, STOptions* inOptions, STContext* inContext, void* clientData, STCategoryNode* node)
+PRBool
+freeNodeRunsProcessor(STRequest * inRequest, STOptions * inOptions,
+ STContext * inContext, void *clientData,
+ STCategoryNode * node)
{
- if (node->runs)
- {
+ if (node->runs) {
PRUint32 loop = 0;
-
- for(loop = 0; loop < globals.mCommandLineOptions.mContexts; loop++)
- {
- if (node->runs[loop])
- {
+
+ for (loop = 0; loop < globals.mCommandLineOptions.mContexts; loop++) {
+ if (node->runs[loop]) {
freeRun(node->runs[loop]);
node->runs[loop] = NULL;
}
}
-
+
free(node->runs);
node->runs = NULL;
}
@@ -613,23 +628,32 @@ PRBool freeNodeRunsProcessor(STRequest* inRequest, STOptions* inOptions, STConte
}
#if defined(DEBUG_dp)
-PRBool printNodeProcessor(STRequest* inRequest, STOptions* inOptions, STContext* inContext, void* clientData, STCategoryNode* node)
+PRBool
+printNodeProcessor(STRequest * inRequest, STOptions * inOptions,
+ STContext * inContext, void *clientData,
+ STCategoryNode * node)
{
- STCategoryNode* root = (STCategoryNode*) clientData;
+ STCategoryNode *root = (STCategoryNode *) clientData;
+
fprintf(stderr, "%-25s [ %9s size", node->categoryName,
- FormatNumber(node->run ? node->run->mStats[inContext->mIndex].mSize:0));
+ FormatNumber(node->run ? node->run->mStats[inContext->mIndex].
+ mSize : 0));
fprintf(stderr, ", %5.1f%%",
- node->run ? ((double)node->run->mStats[inContext->mIndex].mSize / root->run->mStats[inContext->mIndex].mSize * 100):0);
+ node->run ? ((double) node->run->mStats[inContext->mIndex].mSize /
+ root->run->mStats[inContext->mIndex].mSize *
+ 100) : 0);
fprintf(stderr, ", %7s allocations ]\n",
- FormatNumber(node->run ? node->run->mStats[inContext->mIndex].mCompositeCount:0));
+ FormatNumber(node->run ? node->run->mStats[inContext->mIndex].
+ mCompositeCount : 0));
return PR_TRUE;
}
#endif
-typedef struct __struct_optcon {
- STOptions* mOptions;
- STContext* mContext;
+typedef struct __struct_optcon
+{
+ STOptions *mOptions;
+ STContext *mContext;
}
optcon;
@@ -639,12 +663,13 @@ optcon;
** qsort callback.
** Compare the nodes as specified by the options.
*/
-int compareNode(const void* aNode1, const void* aNode2, void* aContext)
+int
+compareNode(const void *aNode1, const void *aNode2, void *aContext)
{
int retval = 0;
- STCategoryNode* node1, * node2;
+ STCategoryNode *node1, *node2;
PRUint32 a, b;
- optcon *oc = (optcon*)aContext;
+ optcon *oc = (optcon *) aContext;
if (!aNode1 || !aNode2 || !oc->mOptions || !oc->mContext)
return 0;
@@ -652,37 +677,49 @@ int compareNode(const void* aNode1, const void* aNode2, void* aContext)
node1 = *((STCategoryNode **) aNode1);
node2 = *((STCategoryNode **) aNode2);
- 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;
+ 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;
}
- else
- {
+ else {
/* Default is by size */
- 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;
+ 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;
}
if (a < b)
retval = __LINE__;
else
- retval = - __LINE__;
+ retval = -__LINE__;
}
return retval;
}
-PRBool sortNodeProcessor(STRequest* inRequest, STOptions* inOptions, STContext* inContext, void* clientData, STCategoryNode* node)
+PRBool
+sortNodeProcessor(STRequest * inRequest, STOptions * inOptions,
+ STContext * inContext, void *clientData,
+ STCategoryNode * node)
{
- if (node->nchildren)
- {
+ if (node->nchildren) {
optcon context;
context.mOptions = inOptions;
context.mContext = inContext;
- NS_QuickSort(node->children, node->nchildren, sizeof(STCategoryNode *), compareNode, &context);
+ NS_QuickSort(node->children, node->nchildren,
+ sizeof(STCategoryNode *), compareNode, &context);
}
return PR_TRUE;
@@ -698,44 +735,43 @@ PRBool sortNodeProcessor(STRequest* inRequest, STOptions* inOptions, STContext*
*/
#define MODINC(n, mod) ((n+1) % mod)
-void walkTree(STCategoryNode* root, STCategoryNodeProcessor func, STRequest* inRequest, STOptions* inOptions, STContext* inContext, void *clientData, int maxdepth)
+void
+walkTree(STCategoryNode * root, STCategoryNodeProcessor func,
+ STRequest * inRequest, STOptions * inOptions, STContext * inContext,
+ void *clientData, int maxdepth)
{
- STCategoryNode* nodes[1024], *node;
+ STCategoryNode *nodes[1024], *node;
PRUint32 begin, end, i;
int ret = 0;
int curdepth = 0, ncurdepth = 0;
nodes[0] = root;
- begin = 0; end = 1;
+ begin = 0;
+ end = 1;
ncurdepth = 1;
- while (begin != end)
- {
+ while (begin != end) {
node = nodes[begin];
- ret = (*func)(inRequest, inOptions, inContext, clientData, node);
- if (ret == PR_FALSE)
- {
+ ret = (*func) (inRequest, inOptions, inContext, clientData, node);
+ if (ret == PR_FALSE) {
/* Abort */
break;
}
begin = MODINC(begin, 1024);
- for (i = 0; i < node->nchildren; i++)
- {
+ for (i = 0; i < node->nchildren; i++) {
nodes[end] = node->children[i];
end = MODINC(end, 1024);
}
/* Depth tracking. Do it only if walkTree is contrained by a maxdepth */
- if (maxdepth > 0 && --ncurdepth == 0)
- {
+ if (maxdepth > 0 && --ncurdepth == 0) {
/*
- ** No more children in current depth. The rest of the nodes
- ** we have in our list should be nodes in the depth below us.
- */
+ ** No more children in current depth. The rest of the nodes
+ ** we have in our list should be nodes in the depth below us.
+ */
ncurdepth = (begin < end) ? (end - begin) : (1024 - begin + end);
- if (++curdepth > maxdepth)
- {
+ if (++curdepth > maxdepth) {
/*
- ** Gone too deep. Stop.
- */
+ ** Gone too deep. Stop.
+ */
break;
}
}
@@ -743,10 +779,12 @@ void walkTree(STCategoryNode* root, STCategoryNodeProcessor func, STRequest* inR
return;
}
-int freeRule(STCategoryRule* rule)
+int
+freeRule(STCategoryRule * rule)
{
PRUint32 i;
- char *p = (char *)rule->categoryName;
+ char *p = (char *) rule->categoryName;
+
PR_FREEIF(p);
for (i = 0; i < rule->npats; i++)
@@ -756,43 +794,44 @@ int freeRule(STCategoryRule* rule)
return 0;
}
-void freeNodeRuns(STCategoryNode* root)
+void
+freeNodeRuns(STCategoryNode * root)
{
- walkTree(root, freeNodeRunsProcessor, NULL, NULL, NULL, NULL, 0);
+ walkTree(root, freeNodeRunsProcessor, NULL, NULL, NULL, NULL, 0);
}
-void freeNodeMap(STGlobals* g)
+void
+freeNodeMap(STGlobals * g)
{
PRUint32 i;
/* all nodes are in the map table. Just delete all of those. */
- for(i = 0; i < g->mNCategoryMap; i++)
- {
+ for (i = 0; i < g->mNCategoryMap; i++) {
free(g->mCategoryMap[i]->node);
free(g->mCategoryMap[i]);
}
free(g->mCategoryMap);
}
-int freeCategories(STGlobals* g)
+int
+freeCategories(STGlobals * g)
{
PRUint32 i;
/*
- ** walk the tree and free runs held in nodes
- */
+ ** walk the tree and free runs held in nodes
+ */
freeNodeRuns(&g->mCategoryRoot);
/*
- ** delete nodemap. This is the where nodes get deleted.
- */
+ ** delete nodemap. This is the where nodes get deleted.
+ */
freeNodeMap(g);
/*
- ** delete rule stuff
- */
- for (i = 0; i < g->mNRules; i++)
- {
+ ** delete rule stuff
+ */
+ for (i = 0; i < g->mNRules; i++) {
freeRule(g->mCategoryRules[i]);
}
free(g->mCategoryRules);
@@ -807,48 +846,56 @@ int freeCategories(STGlobals* g)
** categorize all the allocations of the run using the rules into
** a tree rooted at globls.mCategoryRoot
*/
-int categorizeRun(STOptions* inOptions, STContext* inContext, const STRun* aRun, STGlobals* g)
+int
+categorizeRun(STOptions * inOptions, STContext * inContext,
+ const STRun * aRun, STGlobals * g)
{
PRUint32 i;
+
#if defined(DEBUG_dp)
PRIntervalTime start = PR_IntervalNow();
+
fprintf(stderr, "DEBUG: categorizing run...\n");
#endif
/*
- ** First, cleanup our tree
- */
- walkTree(&g->mCategoryRoot, freeNodeRunProcessor, NULL, inOptions, inContext, NULL, 0);
+ ** 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);
+ if (g->mNCategoryMap > 0) {
+ for (i = 0; i < aRun->mAllocationCount; i++) {
+ categorizeAllocation(inOptions, inContext, aRun->mAllocations[i],
+ g);
}
}
/*
- ** the run is always going to be the one corresponding to the root node
- */
+ ** the run is always going to be the one corresponding to the root node
+ */
g->mCategoryRoot.runs[inContext->mIndex] = (STRun *) aRun;
g->mCategoryRoot.categoryName = ST_ROOT_CATEGORY_NAME;
#if defined(DEBUG_dp)
- fprintf(stderr, "DEBUG: categorizing ends: %dms [%d rules, %d allocations]\n",
- PR_IntervalToMilliseconds(PR_IntervalNow() - start), g->mNRules, aRun->mAllocationCount);
+ fprintf(stderr,
+ "DEBUG: categorizing ends: %dms [%d rules, %d allocations]\n",
+ PR_IntervalToMilliseconds(PR_IntervalNow() - start), g->mNRules,
+ aRun->mAllocationCount);
fprintf(stderr, "DEBUG: match : %dms [%d calls, %d rule-compares]\n",
- PR_IntervalToMilliseconds(_gMatchTime),
- _gMatchCount, _gMatchRules);
+ PR_IntervalToMilliseconds(_gMatchTime), _gMatchCount,
+ _gMatchRules);
#endif
/*
- ** sort the tree based on our sort criterion
- */
- walkTree(&g->mCategoryRoot, sortNodeProcessor, NULL, inOptions, inContext, NULL, 0);
+ ** sort the tree based on our sort criterion
+ */
+ walkTree(&g->mCategoryRoot, sortNodeProcessor, NULL, inOptions, inContext,
+ NULL, 0);
#if defined(DEBUG_dp)
- walkTree(&g->mCategoryRoot, printNodeProcessor, NULL, inOptions, inContext, &g->mCategoryRoot, 0);
+ walkTree(&g->mCategoryRoot, printNodeProcessor, NULL, inOptions,
+ inContext, &g->mCategoryRoot, 0);
#endif
return 0;
@@ -861,63 +908,70 @@ int categorizeRun(STOptions* inOptions, STContext* inContext, const STRun* aRun,
** Generate the category report - a list of all categories and details about each
** depth parameter controls how deep we traverse the category tree.
*/
-PRBool displayCategoryNodeProcessor(STRequest* inRequest, STOptions* inOptions, STContext* inContext, void* clientData, STCategoryNode* node)
+PRBool
+displayCategoryNodeProcessor(STRequest * inRequest, STOptions * inOptions,
+ STContext * inContext, void *clientData,
+ STCategoryNode * node)
{
- STCategoryNode* root = (STCategoryNode *) clientData;
+ STCategoryNode *root = (STCategoryNode *) clientData;
PRUint32 byteSize = 0, heapCost = 0, count = 0;
double percent = 0;
STOptions customOps;
- if (node->runs[inContext->mIndex])
- {
+ if (node->runs[inContext->mIndex]) {
/*
- ** Byte size
- */
- byteSize = node->runs[inContext->mIndex]->mStats[inContext->mIndex].mSize;
+ ** Byte size
+ */
+ byteSize =
+ node->runs[inContext->mIndex]->mStats[inContext->mIndex].mSize;
/*
- ** Composite count
- */
- count = node->runs[inContext->mIndex]->mStats[inContext->mIndex].mCompositeCount;
+ ** Composite count
+ */
+ count =
+ node->runs[inContext->mIndex]->mStats[inContext->mIndex].
+ mCompositeCount;
/*
- ** Heap operation cost
- **/
- heapCost = node->runs[inContext->mIndex]->mStats[inContext->mIndex].mHeapRuntimeCost;
+ ** Heap operation cost
+ **/
+ heapCost =
+ node->runs[inContext->mIndex]->mStats[inContext->mIndex].
+ mHeapRuntimeCost;
/*
- ** % of total size
- */
- if (root->runs[inContext->mIndex])
- {
- percent = ((double) byteSize) / root->runs[inContext->mIndex]->mStats[inContext->mIndex].mSize * 100;
+ ** % of total size
+ */
+ if (root->runs[inContext->mIndex]) {
+ percent =
+ ((double) byteSize) /
+ root->runs[inContext->mIndex]->mStats[inContext->mIndex].
+ mSize * 100;
}
}
- PR_fprintf(inRequest->mFD,
- "
\n"
- " ");
+ PR_fprintf(inRequest->mFD, " |
\n" " ");
/* a link to topcallsites report with focus on category */
memcpy(&customOps, inOptions, sizeof(customOps));
- PR_snprintf(customOps.mCategoryName, sizeof(customOps.mCategoryName), "%s", node->categoryName);
+ PR_snprintf(customOps.mCategoryName, sizeof(customOps.mCategoryName),
+ "%s", node->categoryName);
- htmlAnchor(inRequest, "top_callsites.html", node->categoryName, NULL, "category-callsites", &customOps);
+ htmlAnchor(inRequest, "top_callsites.html", node->categoryName, NULL,
+ "category-callsites", &customOps);
PR_fprintf(inRequest->mFD,
- " | \n"
- " %u | \n"
+ "\n" " %u | \n"
" %4.1f%% | \n"
- " %u | \n"
- " " ST_MICROVAL_FORMAT " | \n"
- "
\n",
- byteSize, percent, count,
- ST_MICROVAL_PRINTABLE(heapCost));
+ " %u | \n" " "
+ ST_MICROVAL_FORMAT " | \n" " \n", byteSize, percent,
+ count, ST_MICROVAL_PRINTABLE(heapCost));
return PR_TRUE;
}
-int displayCategoryReport(STRequest* inRequest, STCategoryNode *root, int depth)
+int
+displayCategoryReport(STRequest * inRequest, STCategoryNode * root, int depth)
{
PR_fprintf(inRequest->mFD,
"\n"
@@ -926,11 +980,10 @@ int displayCategoryReport(STRequest* inRequest, STCategoryNode *root, int depth)
" Composite Byte Size | \n"
" %% of Total Size | \n"
" Heap Object Count | \n"
- " Composite Heap Operations Seconds | \n"
- " \n"
- );
+ " Composite Heap Operations Seconds | \n" " \n");
- walkTree(root, displayCategoryNodeProcessor, inRequest, &inRequest->mOptions, inRequest->mContext, root, depth);
+ walkTree(root, displayCategoryNodeProcessor, inRequest,
+ &inRequest->mOptions, inRequest->mContext, root, depth);
PR_fprintf(inRequest->mFD, "
\n");
diff --git a/tools/trace-malloc/spacetrace.c b/tools/trace-malloc/spacetrace.c
index 11895cb0a92..dafa7e057a0 100644
--- a/tools/trace-malloc/spacetrace.c
+++ b/tools/trace-malloc/spacetrace.c
@@ -50,7 +50,7 @@
#include
#include
#if defined(XP_WIN32)
-#include /* _heapMin */
+#include /* _heapMin */
#endif
#if defined(HAVE_BOUTELL_GD)
@@ -86,27 +86,14 @@ STGlobals globals;
/*
** have the heap cleanup at opportune times, if possible.
*/
-void heapCompact(void)
+void
+heapCompact(void)
{
#if defined(XP_WIN32)
_heapmin();
#endif
}
-/*
-** showHelp
-**
-** Give simple command line help.
-** Returns !0 if the help was showed.
-*/
-int showHelp(void)
-{
- int retval = 0;
-
- if(PR_FALSE != globals.mCommandLineOptions.mHelp)
- {
- PR_fprintf(PR_STDOUT, "Usage:\t%s [OPTION]... [-|filename]\n\n", globals.mProgramName);
-
#define ST_CMD_OPTION_BOOL(option_name, option_genre, option_help) \
PR_fprintf(PR_STDOUT, "--%s\nDisabled by default.\n%s\n", #option_name, option_help);
#define ST_CMD_OPTION_STRING(option_name, option_genre, default_value, option_help) \
@@ -120,11 +107,27 @@ int showHelp(void)
#define ST_CMD_OPTION_UINT64(option_name, option_genre, default_value, multiplier, option_help) \
PR_fprintf(PR_STDOUT, "--%s=\nDefault value is %llu.\n%s\n", #option_name, default_value, option_help);
+/*
+** showHelp
+**
+** Give simple command line help.
+** Returns !0 if the help was showed.
+*/
+int
+showHelp(void)
+{
+ int retval = 0;
+
+ if (PR_FALSE != globals.mCommandLineOptions.mHelp) {
+ PR_fprintf(PR_STDOUT, "Usage:\t%s [OPTION]... [-|filename]\n\n",
+ globals.mProgramName);
+
+
#include "stoptions.h"
/*
- ** Showed something.
- */
+ ** Showed something.
+ */
retval = __LINE__;
}
@@ -137,7 +140,8 @@ int showHelp(void)
** Convert platform specific ticks to second units
** Returns 0 on success.
*/
-PRUint32 ticks2xsec(tmreader* aReader, PRUint32 aTicks, PRUint32 aResolution)
+PRUint32
+ticks2xsec(tmreader * aReader, PRUint32 aTicks, PRUint32 aResolution)
{
PRUint32 retval = 0;
PRUint64 bigone;
@@ -151,6 +155,7 @@ PRUint32 ticks2xsec(tmreader* aReader, PRUint32 aTicks, PRUint32 aResolution)
LL_L2UI(retval, bigone);
return retval;
}
+
#define ticks2msec(reader, ticks) ticks2xsec((reader), (ticks), 1000)
#define ticks2usec(reader, ticks) ticks2xsec((reader), (ticks), 1000000)
@@ -160,14 +165,15 @@ PRUint32 ticks2xsec(tmreader* aReader, PRUint32 aTicks, PRUint32 aResolution)
** Determine global settings for the application.
** Returns 0 on success.
*/
-int initOptions(int aArgCount, char** aArgArray)
+int
+initOptions(int aArgCount, char **aArgArray)
{
int retval = 0;
int traverse = 0;
/*
- ** Set the initial global default options.
- */
+ ** Set the initial global default options.
+ */
#define ST_CMD_OPTION_BOOL(option_name, option_genre, option_help) globals.mCommandLineOptions.m##option_name = PR_FALSE;
#define ST_CMD_OPTION_STRING(option_name, option_genre, default_value, option_help) PR_snprintf(globals.mCommandLineOptions.m##option_name, sizeof(globals.mCommandLineOptions.m##option_name), "%s", default_value);
#define ST_CMD_OPTION_STRING_ARRAY(option_name, option_genre, array_size, option_help) { int loop; for(loop = 0; loop < array_size; loop++) { globals.mCommandLineOptions.m##option_name[loop][0] = '\0'; } }
@@ -178,22 +184,19 @@ int initOptions(int aArgCount, char** aArgArray)
#include "stoptions.h"
/*
- ** Go through all arguments.
- ** Two dashes lead off an option.
- ** Any single dash leads off help, unless it is a lone dash (stdin).
- ** Anything else will be attempted as a file to be processed.
- */
- for(traverse = 1; traverse < aArgCount; traverse++)
- {
- if('-' == aArgArray[traverse][0] && '-' == aArgArray[traverse][1])
- {
- const char* option = &aArgArray[traverse][2];
+ ** Go through all arguments.
+ ** Two dashes lead off an option.
+ ** Any single dash leads off help, unless it is a lone dash (stdin).
+ ** Anything else will be attempted as a file to be processed.
+ */
+ for (traverse = 1; traverse < aArgCount; traverse++) {
+ if ('-' == aArgArray[traverse][0] && '-' == aArgArray[traverse][1]) {
+ const char *option = &aArgArray[traverse][2];
/*
- ** Initial if(0) needed to make "else if"s valid.
- */
- if(0)
- {
+ ** Initial if(0) needed to make "else if"s valid.
+ */
+ if (0) {
}
#define ST_CMD_OPTION_BOOL(option_name, option_genre, option_help) \
@@ -278,36 +281,36 @@ int initOptions(int aArgCount, char** aArgArray)
#include "stoptions.h"
/*
- ** If no match on options, this else will get hit.
- */
- else
- {
+ ** If no match on options, this else will get hit.
+ */
+ else {
REPORT_ERROR_MSG(__LINE__, option);
retval = __LINE__;
globals.mCommandLineOptions.mHelp = PR_TRUE;
}
}
- else if('-' == aArgArray[traverse][0] && '\0' != aArgArray[traverse][1])
- {
+ else if ('-' == aArgArray[traverse][0]
+ && '\0' != aArgArray[traverse][1]) {
/*
- ** Show help, bad/legacy option.
- */
+ ** Show help, bad/legacy option.
+ */
REPORT_ERROR_MSG(__LINE__, aArgArray[traverse]);
retval = __LINE__;
globals.mCommandLineOptions.mHelp = PR_TRUE;
}
- else
- {
+ else {
/*
- ** Default is same as FileName option, the file to process.
- */
- PR_snprintf(globals.mCommandLineOptions.mFileName, sizeof(globals.mCommandLineOptions.mFileName), "%s", aArgArray[traverse]);
+ ** Default is same as FileName option, the file to process.
+ */
+ PR_snprintf(globals.mCommandLineOptions.mFileName,
+ sizeof(globals.mCommandLineOptions.mFileName), "%s",
+ aArgArray[traverse]);
}
}
/*
- ** initalize the categories
- */
+ ** initalize the categories
+ */
initCategories(&globals);
return retval;
@@ -331,41 +334,37 @@ int initOptions(int aArgCount, char** aArgArray)
** trasparent (white) background
** incremental display
*/
-gdImagePtr createGraph(int* aTransparencyColor)
+gdImagePtr
+createGraph(int *aTransparencyColor)
{
gdImagePtr retval = NULL;
- if(NULL != aTransparencyColor)
- {
+ if (NULL != aTransparencyColor) {
*aTransparencyColor = -1;
retval = gdImageCreate(STGD_WIDTH, STGD_HEIGHT);
- if(NULL != retval)
- {
+ if (NULL != retval) {
/*
- ** Background color (first one).
- */
+ ** Background color (first one).
+ */
*aTransparencyColor = gdImageColorAllocate(retval, 255, 255, 255);
- if(-1 != *aTransparencyColor)
- {
+ if (-1 != *aTransparencyColor) {
/*
- ** As transparency.
- */
+ ** As transparency.
+ */
gdImageColorTransparent(retval, *aTransparencyColor);
}
/*
- ** And to set interlacing.
- */
+ ** And to set interlacing.
+ */
gdImageInterlace(retval, 1);
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, gdImageCreate);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, createGraph);
}
@@ -380,25 +379,27 @@ gdImagePtr createGraph(int* aTransparencyColor)
** This function mainly exists to simplify putitng all the pretty lace
** around a home made graph.
*/
-void drawGraph(gdImagePtr aImage, int aColor,
- const char* aGraphTitle,
- const char* aXAxisTitle,
- const char* aYAxisTitle,
- PRUint32 aXMarkCount,
- PRUint32* aXMarkPercents,
- const char** aXMarkTexts,
- PRUint32 aYMarkCount,
- PRUint32* aYMarkPercents,
- const char** aYMarkTexts,
- PRUint32 aLegendCount,
- int* aLegendColors, const char** aLegendTexts)
+void
+drawGraph(gdImagePtr aImage, int aColor,
+ const char *aGraphTitle,
+ const char *aXAxisTitle,
+ const char *aYAxisTitle,
+ PRUint32 aXMarkCount,
+ PRUint32 * aXMarkPercents,
+ const char **aXMarkTexts,
+ PRUint32 aYMarkCount,
+ PRUint32 * aYMarkPercents,
+ const char **aYMarkTexts,
+ PRUint32 aLegendCount,
+ int *aLegendColors, const char **aLegendTexts)
{
- if(NULL != aImage && NULL != aGraphTitle &&
- NULL != aXAxisTitle && NULL != aYAxisTitle &&
- (0 == aXMarkCount || (NULL != aXMarkPercents && NULL != aXMarkTexts)) &&
- (0 == aYMarkCount || (NULL != aYMarkPercents && NULL != aYMarkTexts)) &&
- (0 == aLegendCount || (NULL != aLegendColors && NULL != aLegendTexts)))
- {
+ if (NULL != aImage && NULL != aGraphTitle &&
+ NULL != aXAxisTitle && NULL != aYAxisTitle &&
+ (0 == aXMarkCount || (NULL != aXMarkPercents && NULL != aXMarkTexts))
+ && (0 == aYMarkCount
+ || (NULL != aYMarkPercents && NULL != aYMarkTexts))
+ && (0 == aLegendCount
+ || (NULL != aLegendColors && NULL != aLegendTexts))) {
int margin = 1;
PRUint32 traverse = 0;
PRUint32 target = 0;
@@ -408,8 +409,8 @@ void drawGraph(gdImagePtr aImage, int aColor,
int x2 = 0;
int y2 = 0;
time_t theTimeT = time(NULL);
- char* theTime = ctime(&theTimeT);
- const char* logo = "SpaceTrace";
+ char *theTime = ctime(&theTimeT);
+ const char *logo = "SpaceTrace";
gdFontPtr titleFont = gdFontMediumBold;
gdFontPtr markFont = gdFontTiny;
gdFontPtr dateFont = gdFontTiny;
@@ -418,21 +419,19 @@ void drawGraph(gdImagePtr aImage, int aColor,
gdFontPtr logoFont = gdFontTiny;
/*
- ** Fixup the color.
- ** Black by default.
- */
- if(-1 == aColor)
- {
+ ** Fixup the color.
+ ** Black by default.
+ */
+ if (-1 == aColor) {
aColor = gdImageColorAllocate(aImage, 0, 0, 0);
}
- if(-1 == aColor)
- {
+ if (-1 == aColor) {
aColor = gdImageColorClosest(aImage, 0, 0, 0);
}
/*
- ** Output the box.
- */
+ ** Output the box.
+ */
x1 = STGD_MARGIN - margin;
y1 = STGD_MARGIN - margin;
x2 = STGD_WIDTH - x1;
@@ -441,13 +440,14 @@ void drawGraph(gdImagePtr aImage, int aColor,
margin++;
/*
- ** Need to make small markings on the graph to indicate where the
- ** labels line up exactly.
- ** While we're at it, draw the label text.
- */
- for(traverse = 0; traverse < aXMarkCount; traverse++)
- {
- target = ((STGD_WIDTH - (STGD_MARGIN * 2)) * aXMarkPercents[traverse]) / 100;
+ ** Need to make small markings on the graph to indicate where the
+ ** labels line up exactly.
+ ** While we're at it, draw the label text.
+ */
+ for (traverse = 0; traverse < aXMarkCount; traverse++) {
+ target =
+ ((STGD_WIDTH -
+ (STGD_MARGIN * 2)) * aXMarkPercents[traverse]) / 100;
x1 = STGD_MARGIN + target;
y1 = STGD_MARGIN - margin;
@@ -459,16 +459,20 @@ void drawGraph(gdImagePtr aImage, int aColor,
y2 = STGD_HEIGHT - y2;
gdImageLine(aImage, x1, y1, x2, y2, aColor);
- if(NULL != aXMarkTexts[traverse])
- {
+ if (NULL != aXMarkTexts[traverse]) {
x1 = STGD_MARGIN + target - (markFont->h / 2);
- y1 = STGD_HEIGHT - STGD_MARGIN + margin + markSize + (strlen(aXMarkTexts[traverse]) * markFont->w);
- gdImageStringUp(aImage, markFont, x1, y1, (unsigned char*)aXMarkTexts[traverse], aColor);
+ y1 = STGD_HEIGHT - STGD_MARGIN + margin + markSize +
+ (strlen(aXMarkTexts[traverse]) * markFont->w);
+ gdImageStringUp(aImage, markFont, x1, y1,
+ (unsigned char *) aXMarkTexts[traverse],
+ aColor);
}
}
- for(traverse = 0; traverse < aYMarkCount; traverse++)
- {
- target = ((STGD_HEIGHT - (STGD_MARGIN * 2)) * (100 - aYMarkPercents[traverse])) / 100;
+ for (traverse = 0; traverse < aYMarkCount; traverse++) {
+ target =
+ ((STGD_HEIGHT - (STGD_MARGIN * 2)) * (100 -
+ aYMarkPercents
+ [traverse])) / 100;
x1 = STGD_MARGIN - margin;
y1 = STGD_MARGIN + target;
@@ -480,74 +484,80 @@ void drawGraph(gdImagePtr aImage, int aColor,
x2 = STGD_WIDTH - x2;
gdImageLine(aImage, x1, y1, x2, y2, aColor);
- if(NULL != aYMarkTexts[traverse])
- {
- x1 = STGD_MARGIN - margin - markSize - (strlen(aYMarkTexts[traverse]) * markFont->w);
+ if (NULL != aYMarkTexts[traverse]) {
+ x1 = STGD_MARGIN - margin - markSize -
+ (strlen(aYMarkTexts[traverse]) * markFont->w);
y1 = STGD_MARGIN + target - (markFont->h / 2);
- gdImageString(aImage, markFont, x1, y1, (unsigned char*)aYMarkTexts[traverse], aColor);
+ gdImageString(aImage, markFont, x1, y1,
+ (unsigned char *) aYMarkTexts[traverse],
+ aColor);
}
}
margin += markSize;
/*
- ** Title will be centered above the image.
- */
+ ** Title will be centered above the image.
+ */
x1 = (STGD_WIDTH / 2) - ((strlen(aGraphTitle) * titleFont->w) / 2);
y1 = ((STGD_MARGIN - margin) / 2) - (titleFont->h / 2);
- gdImageString(aImage, titleFont, x1, y1, (unsigned char*)aGraphTitle, aColor);
+ gdImageString(aImage, titleFont, x1, y1,
+ (unsigned char *) aGraphTitle, aColor);
/*
- ** Upper left will be the date.
- */
+ ** Upper left will be the date.
+ */
x1 = 0;
y1 = 0;
traverse = strlen(theTime) - 1;
- if(isspace(theTime[traverse]))
- {
+ if (isspace(theTime[traverse])) {
theTime[traverse] = '\0';
}
- gdImageString(aImage, dateFont, x1, y1, (unsigned char*)theTime, aColor);
+ gdImageString(aImage, dateFont, x1, y1, (unsigned char *) theTime,
+ aColor);
/*
- ** Lower right will be the logo.
- */
+ ** Lower right will be the logo.
+ */
x1 = STGD_WIDTH - (strlen(logo) * logoFont->w);
y1 = STGD_HEIGHT - logoFont->h;
- gdImageString(aImage, logoFont, x1, y1, (unsigned char*)logo, aColor);
+ gdImageString(aImage, logoFont, x1, y1, (unsigned char *) logo,
+ aColor);
/*
- ** X and Y axis titles
- */
+ ** X and Y axis titles
+ */
x1 = (STGD_WIDTH / 2) - ((strlen(aXAxisTitle) * axisFont->w) / 2);
y1 = STGD_HEIGHT - axisFont->h;
- gdImageString(aImage, axisFont, x1, y1, (unsigned char*)aXAxisTitle, aColor);
+ gdImageString(aImage, axisFont, x1, y1, (unsigned char *) aXAxisTitle,
+ aColor);
x1 = 0;
y1 = (STGD_HEIGHT / 2) + ((strlen(aYAxisTitle) * axisFont->w) / 2);
- gdImageStringUp(aImage, axisFont, x1, y1, (unsigned char*)aYAxisTitle, aColor);
+ gdImageStringUp(aImage, axisFont, x1, y1,
+ (unsigned char *) aYAxisTitle, aColor);
/*
- ** The legend.
- ** Centered on the right hand side, going up.
- */
- x1 = STGD_WIDTH - STGD_MARGIN + margin + (aLegendCount * legendFont->h) / 2;
+ ** The legend.
+ ** Centered on the right hand side, going up.
+ */
+ x1 = STGD_WIDTH - STGD_MARGIN + margin +
+ (aLegendCount * legendFont->h) / 2;
x2 = STGD_WIDTH - (aLegendCount * legendFont->h);
- if(x1 > x2)
- {
+ if (x1 > x2) {
x1 = x2;
}
y1 = 0;
- for(traverse = 0; traverse < aLegendCount; traverse++)
- {
- y2 = (STGD_HEIGHT / 2) + ((strlen(aLegendTexts[traverse]) * legendFont->w) / 2);
- if(y2 > y1)
- {
+ for (traverse = 0; traverse < aLegendCount; traverse++) {
+ y2 = (STGD_HEIGHT / 2) +
+ ((strlen(aLegendTexts[traverse]) * legendFont->w) / 2);
+ if (y2 > y1) {
y1 = y2;
}
}
- for(traverse = 0; traverse < aLegendCount; traverse++)
- {
- gdImageStringUp(aImage, legendFont, x1, y1, (unsigned char*)aLegendTexts[traverse], aLegendColors[traverse]);
+ for (traverse = 0; traverse < aLegendCount; traverse++) {
+ gdImageStringUp(aImage, legendFont, x1, y1,
+ (unsigned char *) aLegendTexts[traverse],
+ aLegendColors[traverse]);
x1 += legendFont->h;
}
}
@@ -561,9 +571,10 @@ void drawGraph(gdImagePtr aImage, int aColor,
**
** GD callback, used to write out the png.
*/
-int pngSink(void* aContext, const char* aBuffer, int aLen)
+int
+pngSink(void *aContext, const char *aBuffer, int aLen)
{
- return PR_Write((PRFileDesc*)aContext, aBuffer, aLen);
+ return PR_Write((PRFileDesc *) aContext, aBuffer, aLen);
}
#endif /* HAVE_BOUTELL_GD */
@@ -573,7 +584,8 @@ int pngSink(void* aContext, const char* aBuffer, int aLen)
** Formats a number with thousands separator. Dont free the result. Returns
** static data.
*/
-char *FormatNumber(PRInt32 num)
+char *
+FormatNumber(PRInt32 num)
{
static char buf[64];
char tmpbuf[64];
@@ -586,12 +598,9 @@ char *FormatNumber(PRInt32 num)
/* now insert the thousands separator */
mod3 = 0;
len = strlen(tmpbuf);
- while (len >= 0)
- {
- if (tmpbuf[len] >= '0' && tmpbuf[len] <= '9')
- {
- if (mod3 == 3)
- {
+ while (len >= 0) {
+ if (tmpbuf[len] >= '0' && tmpbuf[len] <= '9') {
+ if (mod3 == 3) {
buf[bufindex--] = ',';
mod3 = 0;
}
@@ -599,7 +608,7 @@ char *FormatNumber(PRInt32 num)
}
buf[bufindex--] = tmpbuf[len--];
}
- return buf+bufindex+1;
+ return buf + bufindex + 1;
}
/*
@@ -607,24 +616,23 @@ char *FormatNumber(PRInt32 num)
**
** Apply alignment and overhead to size to figure out actual byte size
*/
-PRUint32 actualByteSize(STOptions* inOptions, PRUint32 retval)
+PRUint32
+actualByteSize(STOptions * inOptions, PRUint32 retval)
{
/*
- ** Need to bump the result by our alignment and overhead.
- ** The idea here is that an allocation actually costs you more than you
- ** thought.
- **
- ** The msvcrt malloc has an alignment of 16 with an overhead of 8.
- ** The win32 HeapAlloc has an alignment of 8 with an overhead of 8.
- */
- if(0 != retval)
- {
+ ** Need to bump the result by our alignment and overhead.
+ ** The idea here is that an allocation actually costs you more than you
+ ** thought.
+ **
+ ** The msvcrt malloc has an alignment of 16 with an overhead of 8.
+ ** The win32 HeapAlloc has an alignment of 8 with an overhead of 8.
+ */
+ if (0 != retval) {
PRUint32 eval = 0;
PRUint32 over = 0;
eval = retval - 1;
- if(0 != inOptions->mAlignBy)
- {
+ if (0 != inOptions->mAlignBy) {
over = eval % inOptions->mAlignBy;
}
retval = eval + inOptions->mOverhead + inOptions->mAlignBy - over;
@@ -640,23 +648,22 @@ PRUint32 actualByteSize(STOptions* inOptions, PRUint32 retval)
** Might expand in the future to report size at a given time.
** For now, just use last relevant event.
*/
-PRUint32 byteSize(STOptions* inOptions, STAllocation* aAlloc)
+PRUint32
+byteSize(STOptions * inOptions, STAllocation * aAlloc)
{
PRUint32 retval = 0;
- if(NULL != aAlloc && 0 != aAlloc->mEventCount)
- {
+ if (NULL != aAlloc && 0 != aAlloc->mEventCount) {
PRUint32 index = aAlloc->mEventCount;
/*
- ** Generally, the size is the last event's size.
- */
- do
- {
+ ** Generally, the size is the last event's size.
+ */
+ do {
index--;
retval = aAlloc->mEvents[index].mHeapSize;
}
- while(0 == retval && 0 != index);
+ while (0 == retval && 0 != index);
}
return actualByteSize(inOptions, retval);
}
@@ -668,19 +675,22 @@ PRUint32 byteSize(STOptions* inOptions, STAllocation* aAlloc)
** Given an allocation, does a recalculation of Cost - weight, heapcount etc.
** and does the right thing to propogate the cost upwards.
*/
-int recalculateAllocationCost(STOptions* inOptions, STContext* inContext, STRun* aRun, STAllocation* aAllocation, PRBool updateParent)
+int
+recalculateAllocationCost(STOptions * inOptions, STContext * inContext,
+ STRun * aRun, STAllocation * aAllocation,
+ PRBool updateParent)
{
/*
- ** Now, see if they desire a callsite update.
- ** As mentioned previously, we decide if the run desires us to
- ** manipulate the callsite data only if it's stamp is set.
- ** We change all callsites and parent callsites to have that
- ** stamp as well, so as to mark them as being relevant to
- ** the current run in question.
- */
- if(NULL != inContext && 0 != aRun->mStats[inContext->mIndex].mStamp)
- {
- PRUint32 timeval = aAllocation->mMaxTimeval - aAllocation->mMinTimeval;
+ ** Now, see if they desire a callsite update.
+ ** As mentioned previously, we decide if the run desires us to
+ ** manipulate the callsite data only if it's stamp is set.
+ ** We change all callsites and parent callsites to have that
+ ** stamp as well, so as to mark them as being relevant to
+ ** the current run in question.
+ */
+ if (NULL != inContext && 0 != aRun->mStats[inContext->mIndex].mStamp) {
+ PRUint32 timeval =
+ aAllocation->mMaxTimeval - aAllocation->mMinTimeval;
PRUint32 size = byteSize(inOptions, aAllocation);
PRUint64 weight64 = LL_INIT(0, 0);
PRUint32 heapCost = aAllocation->mHeapRuntimeCost;
@@ -692,8 +702,8 @@ int recalculateAllocationCost(STOptions* inOptions, STContext* inContext, STRun*
LL_MUL(weight64, timeval64, size64);
/*
- ** First, update this run.
- */
+ ** First, update this run.
+ */
aRun->mStats[inContext->mIndex].mCompositeCount++;
aRun->mStats[inContext->mIndex].mHeapRuntimeCost += heapCost;
aRun->mStats[inContext->mIndex].mSize += size;
@@ -703,52 +713,48 @@ int recalculateAllocationCost(STOptions* inOptions, STContext* inContext, STRun*
aRun->mStats[inContext->mIndex].mWeight64, weight64);
/*
- ** Use the first event of the allocation to update the parent
- ** callsites.
- ** This has positive effect of not updating realloc callsites
- ** with the same data over and over again.
- */
- if(updateParent && 0 < aAllocation->mEventCount)
- {
- tmcallsite* callsite = aAllocation->mEvents[0].mCallsite;
- STRun* callsiteRun = NULL;
+ ** Use the first event of the allocation to update the parent
+ ** callsites.
+ ** This has positive effect of not updating realloc callsites
+ ** with the same data over and over again.
+ */
+ if (updateParent && 0 < aAllocation->mEventCount) {
+ tmcallsite *callsite = aAllocation->mEvents[0].mCallsite;
+ STRun *callsiteRun = NULL;
/*
- ** Go up parents till we drop.
- */
- while(NULL != callsite && NULL != callsite->method)
- {
+ ** Go up parents till we drop.
+ */
+ while (NULL != callsite && NULL != callsite->method) {
callsiteRun = CALLSITE_RUN(callsite);
- if(NULL != callsiteRun)
- {
+ if (NULL != callsiteRun) {
/*
- ** Do we init it?
- */
- if(callsiteRun->mStats[inContext->mIndex].mStamp !=
- aRun->mStats[inContext->mIndex].mStamp)
- {
+ ** Do we init it?
+ */
+ if (callsiteRun->mStats[inContext->mIndex].mStamp !=
+ aRun->mStats[inContext->mIndex].mStamp) {
memset(&callsiteRun->mStats[inContext->mIndex], 0,
sizeof(STCallsiteStats));
callsiteRun->mStats[inContext->mIndex].mStamp =
aRun->mStats[inContext->mIndex].mStamp;
}
-
+
/*
- ** Add the values.
- ** Note that if the allocation was ever realloced,
- ** we are actually recording the final size.
- ** Also, the composite count does not include
- ** calls to realloc (or free for that matter),
- ** but rather is simply a count of actual heap
- ** allocation objects, from which someone will
- ** draw conclusions regarding number of malloc
- ** and free calls.
- ** It is possible to generate the exact number
- ** of calls to free/malloc/realloc should the
- ** absolute need arise to count them individually,
- ** but I fear it will take mucho memory and this
- ** is perhaps good enough for now.
- */
+ ** Add the values.
+ ** Note that if the allocation was ever realloced,
+ ** we are actually recording the final size.
+ ** Also, the composite count does not include
+ ** calls to realloc (or free for that matter),
+ ** but rather is simply a count of actual heap
+ ** allocation objects, from which someone will
+ ** draw conclusions regarding number of malloc
+ ** and free calls.
+ ** It is possible to generate the exact number
+ ** of calls to free/malloc/realloc should the
+ ** absolute need arise to count them individually,
+ ** but I fear it will take mucho memory and this
+ ** is perhaps good enough for now.
+ */
callsiteRun->mStats[inContext->mIndex].mCompositeCount++;
callsiteRun->mStats[inContext->mIndex].mHeapRuntimeCost +=
heapCost;
@@ -760,7 +766,7 @@ int recalculateAllocationCost(STOptions* inOptions, STContext* inContext, STRun*
callsiteRun->mStats[inContext->mIndex].mWeight64,
weight64);
}
-
+
callsite = callsite->parent;
}
}
@@ -782,63 +788,60 @@ int recalculateAllocationCost(STOptions* inOptions, STContext* inContext, STRun*
** Returns !0 on success.
*/
int
-appendAllocation(STOptions* inOptions, STContext* inContext,
- STRun* aRun, STAllocation* aAllocation)
+appendAllocation(STOptions * inOptions, STContext * inContext,
+ STRun * aRun, STAllocation * aAllocation)
{
int retval = 0;
- if(NULL != aRun && NULL != aAllocation && NULL != inOptions)
- {
- STAllocation** expand = NULL;
+ if (NULL != aRun && NULL != aAllocation && NULL != inOptions) {
+ STAllocation **expand = NULL;
/*
- ** Expand the size of the array if needed.
- */
- expand = (STAllocation**)realloc(aRun->mAllocations,
- sizeof(STAllocation*) * (aRun->mAllocationCount + 1));
- if(NULL != expand)
- {
+ ** Expand the size of the array if needed.
+ */
+ expand = (STAllocation **) realloc(aRun->mAllocations,
+ sizeof(STAllocation *) *
+ (aRun->mAllocationCount + 1));
+ if (NULL != expand) {
/*
- ** Reassign in case of pointer move.
- */
+ ** Reassign in case of pointer move.
+ */
aRun->mAllocations = expand;
/*
- ** Stick the allocation in.
- */
+ ** Stick the allocation in.
+ */
aRun->mAllocations[aRun->mAllocationCount] = aAllocation;
/*
- ** If this is the global run, we need to let the allocation
- ** track the index back to us.
- */
- if(&globals.mRun == aRun)
- {
+ ** If this is the global run, we need to let the allocation
+ ** track the index back to us.
+ */
+ if (&globals.mRun == aRun) {
aAllocation->mRunIndex = aRun->mAllocationCount;
}
/*
- ** Increase the count.
- */
+ ** Increase the count.
+ */
aRun->mAllocationCount++;
/*
- ** We're good.
- */
+ ** We're good.
+ */
retval = __LINE__;
/*
- ** update allocation cost
- */
- recalculateAllocationCost(inOptions, inContext, aRun, aAllocation, PR_TRUE);
+ ** update allocation cost
+ */
+ recalculateAllocationCost(inOptions, inContext, aRun, aAllocation,
+ PR_TRUE);
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, appendAllocation);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, appendAllocation);
}
@@ -852,47 +855,42 @@ appendAllocation(STOptions* inOptions, STContext* inContext,
**
** Returns 0 if there is no match.
*/
-int hasCallsiteMatch(tmcallsite* aCallsite, const char* aMatch, int aDirection)
+int
+hasCallsiteMatch(tmcallsite * aCallsite, const char *aMatch, int aDirection)
{
int retval = 0;
- if(NULL != aCallsite && NULL != aCallsite->method &&
- NULL != aMatch && '\0' != *aMatch)
- {
- const char* methodName = NULL;
+ if (NULL != aCallsite && NULL != aCallsite->method &&
+ NULL != aMatch && '\0' != *aMatch) {
+ const char *methodName = NULL;
- do
- {
+ do {
methodName = tmmethodnode_name(aCallsite->method);
- if(NULL != methodName && NULL != strstr(methodName, aMatch))
- {
+ if (NULL != methodName && NULL != strstr(methodName, aMatch)) {
/*
- ** Contains the text.
- */
+ ** Contains the text.
+ */
retval = __LINE__;
break;
}
- else
- {
- switch(aDirection)
- {
- case ST_FOLLOW_SIBLINGS:
- aCallsite = aCallsite->siblings;
- break;
- case ST_FOLLOW_PARENTS:
- aCallsite = aCallsite->parent;
- break;
- default:
- aCallsite = NULL;
- REPORT_ERROR(__LINE__, hasCallsiteMatch);
- break;
+ else {
+ switch (aDirection) {
+ case ST_FOLLOW_SIBLINGS:
+ aCallsite = aCallsite->siblings;
+ break;
+ case ST_FOLLOW_PARENTS:
+ aCallsite = aCallsite->parent;
+ break;
+ default:
+ aCallsite = NULL;
+ REPORT_ERROR(__LINE__, hasCallsiteMatch);
+ break;
}
}
}
- while(NULL != aCallsite && NULL != aCallsite->method);
+ while (NULL != aCallsite && NULL != aCallsite->method);
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, hasCallsiteMatch);
}
@@ -914,27 +912,26 @@ int hasCallsiteMatch(tmcallsite* aCallsite, const char* aMatch, int aDirection)
** Returns !0 on error, though aOutRun may contain a partial data set.
*/
int
-harvestRun(const STRun* aInRun, STRun* aOutRun,
- STOptions* aOptions, STContext* inContext)
+harvestRun(const STRun * aInRun, STRun * aOutRun,
+ STOptions * aOptions, STContext * inContext)
{
int retval = 0;
#if defined(DEBUG_dp)
PRIntervalTime start = PR_IntervalNow();
+
fprintf(stderr, "DEBUG: harvesting run...\n");
#endif
- if(NULL != aInRun && NULL != aOutRun && aInRun != aOutRun && NULL != aOptions && NULL != inContext)
- {
+ if (NULL != aInRun && NULL != aOutRun && aInRun != aOutRun
+ && NULL != aOptions && NULL != inContext) {
PRUint32 traverse = 0;
- STAllocation* current = NULL;
+ STAllocation *current = NULL;
- for(traverse = 0;
- 0 == retval && traverse < aInRun->mAllocationCount; traverse++)
- {
+ for (traverse = 0;
+ 0 == retval && traverse < aInRun->mAllocationCount; traverse++) {
current = aInRun->mAllocations[traverse];
- if(NULL != current)
- {
+ if (NULL != current) {
PRUint32 lifetime = 0;
PRUint32 bytesize = 0;
PRUint64 weight64 = LL_INIT(0, 0);
@@ -945,112 +942,101 @@ harvestRun(const STRun* aInRun, STRun* aOutRun,
PRBool matched = PR_FALSE;
/*
- ** Use this as an opportune time to fixup a memory
- ** leaked timeval, so as to not completely skew
- ** the weights.
- */
- if(ST_TIMEVAL_MAX == current->mMaxTimeval)
- {
+ ** Use this as an opportune time to fixup a memory
+ ** leaked timeval, so as to not completely skew
+ ** the weights.
+ */
+ if (ST_TIMEVAL_MAX == current->mMaxTimeval) {
current->mMaxTimeval = globals.mMaxTimeval;
}
/*
- ** Check allocation timeval restrictions.
- ** We have to slide the recorded timevals to be zero
- ** based, so that the comparisons make sense.
- */
+ ** Check allocation timeval restrictions.
+ ** We have to slide the recorded timevals to be zero
+ ** based, so that the comparisons make sense.
+ */
if ((aOptions->mAllocationTimevalMin >
(current->mMinTimeval - globals.mMinTimeval)) ||
(aOptions->mAllocationTimevalMax <
- (current->mMinTimeval - globals.mMinTimeval)))
- {
+ (current->mMinTimeval - globals.mMinTimeval))) {
continue;
}
/*
- ** Check timeval restrictions.
- ** We have to slide the recorded timevals to be zero
- ** based, so that the comparisons make sense.
- */
+ ** Check timeval restrictions.
+ ** We have to slide the recorded timevals to be zero
+ ** based, so that the comparisons make sense.
+ */
if ((aOptions->mTimevalMin >
(current->mMinTimeval - globals.mMinTimeval)) ||
(aOptions->mTimevalMax <
- (current->mMinTimeval - globals.mMinTimeval)))
- {
+ (current->mMinTimeval - globals.mMinTimeval))) {
continue;
}
/*
- ** Check lifetime restrictions.
- */
+ ** Check lifetime restrictions.
+ */
lifetime = current->mMaxTimeval - current->mMinTimeval;
if ((lifetime < aOptions->mLifetimeMin) ||
- (lifetime > aOptions->mLifetimeMax))
- {
+ (lifetime > aOptions->mLifetimeMax)) {
continue;
}
/*
- ** Check byte size restrictions.
- */
+ ** Check byte size restrictions.
+ */
bytesize = byteSize(aOptions, current);
if ((bytesize < aOptions->mSizeMin) ||
- (bytesize > aOptions->mSizeMax))
- {
+ (bytesize > aOptions->mSizeMax)) {
continue;
}
/*
- ** Check weight restrictions.
- */
+ ** Check weight restrictions.
+ */
LL_UI2L(bytesize64, bytesize);
LL_UI2L(lifetime64, lifetime);
LL_MUL(weight64, bytesize64, lifetime64);
- if(LL_UCMP(weight64, <, aOptions->mWeightMin64) ||
- LL_UCMP(weight64, >, aOptions->mWeightMax64))
- {
+ if (LL_UCMP(weight64, <, aOptions->mWeightMin64) ||
+ LL_UCMP(weight64, >, aOptions->mWeightMax64)) {
continue;
}
/*
- ** Possibly restrict the callsite by text.
- ** Do this last, as it is a heavier check.
- **
- ** One day, we may need to expand the logic to check for
- ** events beyond the initial allocation event.
- */
- for(looper = 0; ST_SUBSTRING_MATCH_MAX > looper; looper++)
- {
- if('\0' != aOptions->mRestrictText[looper][0])
- {
- if(0 == hasCallsiteMatch(current->mEvents[0].mCallsite,
- aOptions->mRestrictText[looper],
- ST_FOLLOW_PARENTS))
- {
+ ** Possibly restrict the callsite by text.
+ ** Do this last, as it is a heavier check.
+ **
+ ** One day, we may need to expand the logic to check for
+ ** events beyond the initial allocation event.
+ */
+ for (looper = 0; ST_SUBSTRING_MATCH_MAX > looper; looper++) {
+ if ('\0' != aOptions->mRestrictText[looper][0]) {
+ if (0 ==
+ hasCallsiteMatch(current->mEvents[0].mCallsite,
+ aOptions->mRestrictText[looper],
+ ST_FOLLOW_PARENTS)) {
break;
}
}
- else
- {
+ else {
matched = PR_TRUE;
break;
}
}
- if(ST_SUBSTRING_MATCH_MAX == looper)
- {
+ if (ST_SUBSTRING_MATCH_MAX == looper) {
matched = PR_TRUE;
}
- if(PR_FALSE == matched)
- {
+ if (PR_FALSE == matched) {
continue;
}
/*
- ** You get here, we add to the run.
- */
- appendRes = appendAllocation(aOptions, inContext, aOutRun, current);
- if(0 == appendRes)
- {
+ ** You get here, we add to the run.
+ */
+ appendRes =
+ appendAllocation(aOptions, inContext, aOutRun, current);
+ if (0 == appendRes) {
retval = __LINE__;
REPORT_ERROR(__LINE__, appendAllocation);
}
@@ -1060,7 +1046,8 @@ harvestRun(const STRun* aInRun, STRun* aOutRun,
#if defined(DEBUG_dp)
fprintf(stderr, "DEBUG: harvesting ends: %dms [%d allocations]\n",
- PR_IntervalToMilliseconds(PR_IntervalNow() - start), aInRun->mAllocationCount);
+ PR_IntervalToMilliseconds(PR_IntervalNow() - start),
+ aInRun->mAllocationCount);
#endif
return retval;
}
@@ -1071,13 +1058,15 @@ harvestRun(const STRun* aInRun, STRun* aOutRun,
** Goes over all allocations of a run and recalculates and propogates
** the allocation costs - weight, heapcount, size
*/
-int recalculateRunCost(STOptions* inOptions, STContext* inContext, STRun* aRun)
+int
+recalculateRunCost(STOptions * inOptions, STContext * inContext, STRun * aRun)
{
PRUint32 traverse = 0;
- STAllocation* current = NULL;
+ STAllocation *current = NULL;
#if defined(DEBUG_dp)
PRIntervalTime start = PR_IntervalNow();
+
fprintf(stderr, "DEBUG: recalculateRunCost...\n");
#endif
@@ -1090,18 +1079,18 @@ int recalculateRunCost(STOptions* inOptions, STContext* inContext, STRun* aRun)
/* reset timestamp to force propogation of cost */
aRun->mStats[inContext->mIndex].mStamp = PR_IntervalNow();
- for(traverse = 0; traverse < aRun->mAllocationCount; traverse++)
- {
+ for (traverse = 0; traverse < aRun->mAllocationCount; traverse++) {
current = aRun->mAllocations[traverse];
- if(NULL != current)
- {
- recalculateAllocationCost(inOptions, inContext, aRun, current, PR_TRUE);
+ if (NULL != current) {
+ recalculateAllocationCost(inOptions, inContext, aRun, current,
+ PR_TRUE);
}
}
#if defined(DEBUG_dp)
fprintf(stderr, "DEBUG: recalculateRunCost ends: %dms [%d allocations]\n",
- PR_IntervalToMilliseconds(PR_IntervalNow() - start), aRun->mAllocationCount);
+ PR_IntervalToMilliseconds(PR_IntervalNow() - start),
+ aRun->mAllocationCount);
#endif
return 0;
@@ -1114,29 +1103,27 @@ int recalculateRunCost(STOptions* inOptions, STContext* inContext, STRun* aRun)
** qsort callback.
** Compare the allocations as specified by the options.
*/
-int compareAllocations(const void* aAlloc1, const void* aAlloc2, void* aContext)
+int
+compareAllocations(const void *aAlloc1, const void *aAlloc2, void *aContext)
{
int retval = 0;
- STOptions* inOptions = (STOptions*)aContext;
+ STOptions *inOptions = (STOptions *) aContext;
- if(NULL != aAlloc1 && NULL != aAlloc2 && NULL != inOptions)
- {
- STAllocation* alloc1 = *((STAllocation**)aAlloc1);
- STAllocation* alloc2 = *((STAllocation**)aAlloc2);
+ if (NULL != aAlloc1 && NULL != aAlloc2 && NULL != inOptions) {
+ STAllocation *alloc1 = *((STAllocation **) aAlloc1);
+ STAllocation *alloc2 = *((STAllocation **) aAlloc2);
- if(NULL != alloc1 && NULL != alloc2)
- {
+ if (NULL != alloc1 && NULL != alloc2) {
/*
- ** Logic determined by pref/option.
- */
- switch(inOptions->mOrderBy)
- {
- case ST_COUNT:
- /*
- ** "By count" on a single allocation means nothing,
- ** fall through to weight.
- */
- case ST_WEIGHT:
+ ** Logic determined by pref/option.
+ */
+ switch (inOptions->mOrderBy) {
+ case ST_COUNT:
+ /*
+ ** "By count" on a single allocation means nothing,
+ ** fall through to weight.
+ */
+ case ST_WEIGHT:
{
PRUint64 weight164 = LL_INIT(0, 0);
PRUint64 weight264 = LL_INIT(0, 0);
@@ -1146,72 +1133,68 @@ int compareAllocations(const void* aAlloc1, const void* aAlloc2, void* aContext)
PRUint64 timeval264 = LL_INIT(0, 0);
LL_UI2L(bytesize164, byteSize(inOptions, alloc1));
- LL_UI2L(timeval164, (alloc1->mMaxTimeval - alloc1->mMinTimeval));
+ LL_UI2L(timeval164,
+ (alloc1->mMaxTimeval - alloc1->mMinTimeval));
LL_MUL(weight164, bytesize164, timeval164);
LL_UI2L(bytesize264, byteSize(inOptions, alloc2));
- LL_UI2L(timeval264, (alloc2->mMaxTimeval - alloc2->mMinTimeval));
+ LL_UI2L(timeval264,
+ (alloc2->mMaxTimeval - alloc2->mMinTimeval));
LL_MUL(weight264, bytesize264, timeval264);
- if(LL_UCMP(weight164, <, weight264))
- {
+ if (LL_UCMP(weight164, <, weight264)) {
retval = __LINE__;
}
- else if(LL_UCMP(weight164, >, weight264))
- {
- retval = - __LINE__;
+ else if (LL_UCMP(weight164, >, weight264)) {
+ retval = -__LINE__;
}
}
break;
- case ST_SIZE:
+ case ST_SIZE:
{
PRUint32 size1 = byteSize(inOptions, alloc1);
PRUint32 size2 = byteSize(inOptions, alloc2);
- if(size1 < size2)
- {
+ if (size1 < size2) {
retval = __LINE__;
}
- else if(size1 > size2)
- {
- retval = - __LINE__;
+ else if (size1 > size2) {
+ retval = -__LINE__;
}
}
break;
- case ST_TIMEVAL:
+ case ST_TIMEVAL:
{
- PRUint32 timeval1 = (alloc1->mMaxTimeval - alloc1->mMinTimeval);
- PRUint32 timeval2 = (alloc2->mMaxTimeval - alloc2->mMinTimeval);
+ PRUint32 timeval1 =
+ (alloc1->mMaxTimeval - alloc1->mMinTimeval);
+ PRUint32 timeval2 =
+ (alloc2->mMaxTimeval - alloc2->mMinTimeval);
- if(timeval1 < timeval2)
- {
+ if (timeval1 < timeval2) {
retval = __LINE__;
}
- else if(timeval1 > timeval2)
- {
- retval = - __LINE__;
+ else if (timeval1 > timeval2) {
+ retval = -__LINE__;
}
}
break;
- case ST_HEAPCOST:
+ case ST_HEAPCOST:
{
PRUint32 cost1 = alloc1->mHeapRuntimeCost;
PRUint32 cost2 = alloc2->mHeapRuntimeCost;
- if(cost1 < cost2)
- {
+ if (cost1 < cost2) {
retval = __LINE__;
}
- else if(cost1 > cost2)
- {
- retval = - __LINE__;
+ else if (cost1 > cost2) {
+ retval = -__LINE__;
}
}
break;
- default:
+ default:
{
REPORT_ERROR(__LINE__, compareAllocations);
}
@@ -1229,19 +1212,19 @@ int compareAllocations(const void* aAlloc1, const void* aAlloc2, void* aContext)
** Given a run, sort it in the manner specified by the options.
** Returns !0 on failure.
*/
-int sortRun(STOptions* inOptions, STRun* aRun)
+int
+sortRun(STOptions * inOptions, STRun * aRun)
{
int retval = 0;
- if(NULL != aRun && NULL != inOptions)
- {
- if(NULL != aRun->mAllocations && 0 < aRun->mAllocationCount)
- {
- NS_QuickSort(aRun->mAllocations, aRun->mAllocationCount, sizeof(STAllocation*), compareAllocations, inOptions);
+ if (NULL != aRun && NULL != inOptions) {
+ if (NULL != aRun->mAllocations && 0 < aRun->mAllocationCount) {
+ NS_QuickSort(aRun->mAllocations, aRun->mAllocationCount,
+ sizeof(STAllocation *), compareAllocations,
+ inOptions);
}
}
- else
- {
+ else {
retval = __LINE__;
REPORT_ERROR(__LINE__, sortRun);
}
@@ -1262,23 +1245,22 @@ int sortRun(STOptions* inOptions, STRun* aRun)
**
** Returns NULL on failure.
*/
-STRun* createRun(STContext* inContext, PRUint32 aStamp)
+STRun *
+createRun(STContext * inContext, PRUint32 aStamp)
{
- STRun* retval = NULL;
+ STRun *retval = NULL;
- retval = (STRun*)calloc(1, sizeof(STRun));
- if(NULL != retval)
- {
- retval->mStats = (STCallsiteStats*)calloc(globals.mCommandLineOptions.mContexts, sizeof(STCallsiteStats));
- if(NULL != retval->mStats)
- {
- if(NULL != inContext)
- {
+ retval = (STRun *) calloc(1, sizeof(STRun));
+ if (NULL != retval) {
+ retval->mStats =
+ (STCallsiteStats *) calloc(globals.mCommandLineOptions.mContexts,
+ sizeof(STCallsiteStats));
+ if (NULL != retval->mStats) {
+ if (NULL != inContext) {
retval->mStats[inContext->mIndex].mStamp = aStamp;
}
}
- else
- {
+ else {
free(retval);
retval = NULL;
}
@@ -1292,23 +1274,21 @@ STRun* createRun(STContext* inContext, PRUint32 aStamp)
**
** Free off the run and the associated data.
*/
-void freeRun(STRun* aRun)
+void
+freeRun(STRun * aRun)
{
- if(NULL != aRun)
- {
- if(NULL != aRun->mAllocations)
- {
+ if (NULL != aRun) {
+ if (NULL != aRun->mAllocations) {
/*
- ** We do not free the allocations themselves.
- ** They are likely pointed to by at least 2 other existing
- ** runs.
- */
+ ** We do not free the allocations themselves.
+ ** They are likely pointed to by at least 2 other existing
+ ** runs.
+ */
free(aRun->mAllocations);
aRun->mAllocations = NULL;
}
- if(NULL != aRun->mStats)
- {
+ if (NULL != aRun->mStats) {
free(aRun->mStats);
aRun->mStats = NULL;
}
@@ -1325,72 +1305,67 @@ void freeRun(STRun* aRun)
** Returns NULL on failure.
** Must call freeRun() with the new STRun.
*/
-STRun* createRunFromGlobal(STOptions* inOptions, STContext* inContext)
+STRun *
+createRunFromGlobal(STOptions * inOptions, STContext * inContext)
{
- STRun* retval = NULL;
+ STRun *retval = NULL;
- if(NULL != inOptions && NULL != inContext)
- {
+ if (NULL != inOptions && NULL != inContext) {
/*
- ** We stamp the run.
- ** As things are appended to it, it realizes that it should stamp the
- ** callsite backtrace with the information as well.
- ** In this manner, we can provide meaningful callsite data.
- */
+ ** We stamp the run.
+ ** As things are appended to it, it realizes that it should stamp the
+ ** callsite backtrace with the information as well.
+ ** In this manner, we can provide meaningful callsite data.
+ */
retval = createRun(inContext, PR_IntervalNow());
-
- if(NULL != retval)
- {
- STCategoryNode* node = NULL;
+
+ if (NULL != retval) {
+ STCategoryNode *node = NULL;
int failure = 0;
- int harvestRes = harvestRun(&globals.mRun, retval, inOptions, inContext);
- if(0 == harvestRes)
- {
+ int harvestRes =
+ harvestRun(&globals.mRun, retval, inOptions, inContext);
+ if (0 == harvestRes) {
int sortRes = sortRun(inOptions, retval);
- if(0 != sortRes)
- {
+
+ if (0 != sortRes) {
failure = __LINE__;
}
}
- else
- {
+ else {
failure = __LINE__;
}
-
-
- if(0 != failure)
- {
+
+
+ if (0 != failure) {
freeRun(retval);
retval = NULL;
-
+
REPORT_ERROR(failure, createRunFromGlobal);
}
-
+
/*
- ** Categorize the run.
- */
+ ** Categorize the run.
+ */
failure = categorizeRun(inOptions, inContext, retval, &globals);
- if (0 != failure)
- {
+ if (0 != failure) {
REPORT_ERROR(__LINE__, categorizeRun);
}
-
+
/*
- ** if we are focussing on a category, return that run instead of
- ** the harvested run. Make sure to recalculate cost.
- */
+ ** if we are focussing on a category, return that run instead of
+ ** the harvested run. Make sure to recalculate cost.
+ */
node = findCategoryNode(inOptions->mCategoryName, &globals);
- if (node)
- {
+ if (node) {
/* Recalculate cost of run */
- recalculateRunCost(inOptions, inContext, node->runs[inContext->mIndex]);
-
+ recalculateRunCost(inOptions, inContext,
+ node->runs[inContext->mIndex]);
+
retval = node->runs[inContext->mIndex];
}
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, createRunFromGlobal);
}
@@ -1407,66 +1382,62 @@ STRun* createRunFromGlobal(STOptions* inOptions, STContext* inContext)
**
** Returns the allocation on success, otherwise NULL.
*/
-STAllocation* getLiveAllocationByHeapID(STRun* aRun, PRUint32 aHeapID)
+STAllocation *
+getLiveAllocationByHeapID(STRun * aRun, PRUint32 aHeapID)
{
- STAllocation* retval = NULL;
+ STAllocation *retval = NULL;
- if(NULL != aRun && 0 != aHeapID)
- {
+ if (NULL != aRun && 0 != aHeapID) {
PRUint32 traverse = aRun->mAllocationCount;
- STAllocation* eval = NULL;
+ STAllocation *eval = NULL;
/*
- ** Go through in reverse order.
- ** Stop when we have a return value.
- */
- while(0 < traverse && NULL == retval)
- {
+ ** Go through in reverse order.
+ ** Stop when we have a return value.
+ */
+ while (0 < traverse && NULL == retval) {
/*
- ** Back up one to align with zero based index.
- */
+ ** Back up one to align with zero based index.
+ */
traverse--;
/*
- ** Take the pointer math out of further operations.
- */
+ ** Take the pointer math out of further operations.
+ */
eval = aRun->mAllocations[traverse];
/*
- ** Take a look at the events in reverse order.
- ** Basically the last event must NOT be a free.
- ** The last event must NOT be a realloc of size zero (free).
- ** Otherwise, try to match up the heapID of the event.
- */
- if(0 != eval->mEventCount)
- {
- STAllocEvent* event = eval->mEvents + (eval->mEventCount - 1);
+ ** Take a look at the events in reverse order.
+ ** Basically the last event must NOT be a free.
+ ** The last event must NOT be a realloc of size zero (free).
+ ** Otherwise, try to match up the heapID of the event.
+ */
+ if (0 != eval->mEventCount) {
+ STAllocEvent *event = eval->mEvents + (eval->mEventCount - 1);
- switch(event->mEventType)
- {
- case TM_EVENT_FREE:
+ switch (event->mEventType) {
+ case TM_EVENT_FREE:
{
/*
- ** No freed allocation can match.
- */
+ ** No freed allocation can match.
+ */
}
break;
-
- case TM_EVENT_REALLOC:
- case TM_EVENT_CALLOC:
- case TM_EVENT_MALLOC:
+
+ case TM_EVENT_REALLOC:
+ case TM_EVENT_CALLOC:
+ case TM_EVENT_MALLOC:
{
/*
- ** Heap IDs must match.
- */
- if(aHeapID == event->mHeapID)
- {
+ ** Heap IDs must match.
+ */
+ if (aHeapID == event->mHeapID) {
retval = eval;
}
}
break;
- default:
+ default:
{
REPORT_ERROR(__LINE__, getAllocationByHeapID);
}
@@ -1475,8 +1446,7 @@ STAllocation* getLiveAllocationByHeapID(STRun* aRun, PRUint32 aHeapID)
}
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, getAllocationByHeapID);
}
@@ -1489,38 +1459,41 @@ STAllocation* getLiveAllocationByHeapID(STRun* aRun, PRUint32 aHeapID)
** Given an allocation, append a new event to it's lifetime.
** Returns the new event on success, otherwise NULL.
*/
-STAllocEvent* appendEvent(STAllocation* aAllocation, PRUint32 aTimeval, char aEventType, PRUint32 aHeapID, PRUint32 aHeapSize, tmcallsite* aCallsite)
+STAllocEvent *
+appendEvent(STAllocation * aAllocation, PRUint32 aTimeval, char aEventType,
+ PRUint32 aHeapID, PRUint32 aHeapSize, tmcallsite * aCallsite)
{
- STAllocEvent* retval = NULL;
+ STAllocEvent *retval = NULL;
- if(NULL != aAllocation && NULL != aCallsite)
- {
- STAllocEvent* expand = NULL;
+ if (NULL != aAllocation && NULL != aCallsite) {
+ STAllocEvent *expand = NULL;
/*
- ** Expand the allocation's event array.
- */
- expand = (STAllocEvent*)realloc(aAllocation->mEvents, sizeof(STAllocEvent) * (aAllocation->mEventCount + 1));
- if(NULL != expand)
- {
+ ** Expand the allocation's event array.
+ */
+ expand =
+ (STAllocEvent *) realloc(aAllocation->mEvents,
+ sizeof(STAllocEvent) *
+ (aAllocation->mEventCount + 1));
+ if (NULL != expand) {
/*
- ** Reassign in case of pointer move.
- */
+ ** Reassign in case of pointer move.
+ */
aAllocation->mEvents = expand;
/*
- ** Remove the pointer math from rest of code.
- */
+ ** Remove the pointer math from rest of code.
+ */
retval = aAllocation->mEvents + aAllocation->mEventCount;
/*
- ** Increase event array count.
- */
+ ** Increase event array count.
+ */
aAllocation->mEventCount++;
/*
- ** Fill in the event.
- */
+ ** Fill in the event.
+ */
retval->mTimeval = aTimeval;
retval->mEventType = aEventType;
retval->mHeapID = aHeapID;
@@ -1528,32 +1501,28 @@ STAllocEvent* appendEvent(STAllocation* aAllocation, PRUint32 aTimeval, char aEv
retval->mCallsite = aCallsite;
/*
- ** Allocation may need to update idea of lifetime.
- ** See allocationTracker to see mMinTimeval inited to ST_TIMEVAL_MAX.
- */
- if(aAllocation->mMinTimeval > aTimeval)
- {
+ ** Allocation may need to update idea of lifetime.
+ ** See allocationTracker to see mMinTimeval inited to ST_TIMEVAL_MAX.
+ */
+ if (aAllocation->mMinTimeval > aTimeval) {
aAllocation->mMinTimeval = aTimeval;
}
/*
- ** This a free event?
- ** Can only set max timeval on a free.
- ** Otherwise, mMaxTimeval remains ST_TIMEVAL_MAX.
- ** Set in allocationTracker.
- */
- if(TM_EVENT_FREE == aEventType)
- {
+ ** This a free event?
+ ** Can only set max timeval on a free.
+ ** Otherwise, mMaxTimeval remains ST_TIMEVAL_MAX.
+ ** Set in allocationTracker.
+ */
+ if (TM_EVENT_FREE == aEventType) {
aAllocation->mMaxTimeval = aTimeval;
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, appendEvent);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, appendEvent);
}
@@ -1567,33 +1536,30 @@ STAllocEvent* appendEvent(STAllocation* aAllocation, PRUint32 aTimeval, char aEv
** This is really nothing more than a pointer comparison loop.
** Returns !0 if the run has the allocation.
*/
-int hasAllocation(STRun* aRun, STAllocation* aTestFor)
+int
+hasAllocation(STRun * aRun, STAllocation * aTestFor)
{
int retval = 0;
- if(NULL != aRun && NULL != aTestFor)
- {
+ if (NULL != aRun && NULL != aTestFor) {
PRUint32 traverse = aRun->mAllocationCount;
/*
- ** Go through reverse, in the hopes it exists nearer the end.
- */
- while(0 < traverse)
- {
+ ** Go through reverse, in the hopes it exists nearer the end.
+ */
+ while (0 < traverse) {
/*
- ** Back up.
- */
+ ** Back up.
+ */
traverse--;
- if(aTestFor == aRun->mAllocations[traverse])
- {
+ if (aTestFor == aRun->mAllocations[traverse]) {
retval = __LINE__;
break;
}
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, hasAllocation);
}
@@ -1609,145 +1575,142 @@ int hasAllocation(STRun* aRun, STAllocation* aTestFor)
** Returns a pointer to the allocation on success.
** Return NULL on failure.
*/
-STAllocation* allocationTracker(PRUint32 aTimeval, char aType, PRUint32 aHeapRuntimeCost, tmcallsite* aCallsite, PRUint32 aHeapID, PRUint32 aSize, tmcallsite* aOldCallsite, PRUint32 aOldHeapID, PRUint32 aOldSize)
+STAllocation *
+allocationTracker(PRUint32 aTimeval, char aType, PRUint32 aHeapRuntimeCost,
+ tmcallsite * aCallsite, PRUint32 aHeapID, PRUint32 aSize,
+ tmcallsite * aOldCallsite, PRUint32 aOldHeapID,
+ PRUint32 aOldSize)
{
- STAllocation* retval = NULL;
+ STAllocation *retval = NULL;
static int compactor = 1;
const int frequency = 10000;
PRUint32 actualSize, actualOldSize = 0;
+
actualSize = actualByteSize(&globals.mCommandLineOptions, aSize);
if (aOldSize)
- actualOldSize = actualByteSize(&globals.mCommandLineOptions, aOldSize);
+ actualOldSize =
+ actualByteSize(&globals.mCommandLineOptions, aOldSize);
- if(NULL != aCallsite)
- {
+ if (NULL != aCallsite) {
int newAllocation = 0;
- tmcallsite* searchCallsite = NULL;
+ tmcallsite *searchCallsite = NULL;
PRUint32 searchHeapID = 0;
- STAllocation* allocation = NULL;
+ STAllocation *allocation = NULL;
/*
- ** Global operation ID increases.
- */
+ ** Global operation ID increases.
+ */
globals.mOperationCount++;
/*
- ** Fix up the timevals if needed.
- */
- if(aTimeval < globals.mMinTimeval)
- {
+ ** Fix up the timevals if needed.
+ */
+ if (aTimeval < globals.mMinTimeval) {
globals.mMinTimeval = aTimeval;
}
- if(aTimeval > globals.mMaxTimeval)
- {
+ if (aTimeval > globals.mMaxTimeval) {
globals.mMaxTimeval = aTimeval;
}
- switch(aType)
- {
- case TM_EVENT_FREE:
+ switch (aType) {
+ case TM_EVENT_FREE:
{
/*
- ** Update the global counter.
- */
+ ** Update the global counter.
+ */
globals.mFreeCount++;
/*
- ** Update our peak memory used counter
- */
+ ** Update our peak memory used counter
+ */
globals.mMemoryUsed -= actualSize;
/*
- ** Not a new allocation, will need to search passed in site
- ** for the original allocation.
- */
+ ** Not a new allocation, will need to search passed in site
+ ** for the original allocation.
+ */
searchCallsite = aCallsite;
searchHeapID = aHeapID;
}
break;
- case TM_EVENT_MALLOC:
+ case TM_EVENT_MALLOC:
{
/*
- ** Update the global counter.
- */
+ ** Update the global counter.
+ */
globals.mMallocCount++;
/*
- ** Update our peak memory used counter
- */
+ ** Update our peak memory used counter
+ */
globals.mMemoryUsed += actualSize;
- if (globals.mMemoryUsed > globals.mPeakMemoryUsed)
- {
+ if (globals.mMemoryUsed > globals.mPeakMemoryUsed) {
globals.mPeakMemoryUsed = globals.mMemoryUsed;
}
/*
- ** This will be a new allocation.
- */
+ ** This will be a new allocation.
+ */
newAllocation = __LINE__;
}
break;
- case TM_EVENT_CALLOC:
+ case TM_EVENT_CALLOC:
{
/*
- ** Update the global counter.
- */
+ ** Update the global counter.
+ */
globals.mCallocCount++;
/*
- ** Update our peak memory used counter
- */
+ ** Update our peak memory used counter
+ */
globals.mMemoryUsed += actualSize;
- if (globals.mMemoryUsed > globals.mPeakMemoryUsed)
- {
+ if (globals.mMemoryUsed > globals.mPeakMemoryUsed) {
globals.mPeakMemoryUsed = globals.mMemoryUsed;
}
/*
- ** This will be a new allocation.
- */
+ ** This will be a new allocation.
+ */
newAllocation = __LINE__;
}
break;
- case TM_EVENT_REALLOC:
+ case TM_EVENT_REALLOC:
{
/*
- ** Update the global counter.
- */
+ ** Update the global counter.
+ */
globals.mReallocCount++;
/*
- ** Update our peak memory used counter
- */
+ ** Update our peak memory used counter
+ */
globals.mMemoryUsed += actualSize - actualOldSize;
- if (globals.mMemoryUsed > globals.mPeakMemoryUsed)
- {
+ if (globals.mMemoryUsed > globals.mPeakMemoryUsed) {
globals.mPeakMemoryUsed = globals.mMemoryUsed;
}
/*
- ** This might be a new allocation.
- */
- if(NULL == aOldCallsite)
- {
+ ** This might be a new allocation.
+ */
+ if (NULL == aOldCallsite) {
newAllocation = __LINE__;
}
- else
- {
+ else {
/*
- ** Need to search for the original callsite for the
- ** index to the allocation.
- */
+ ** Need to search for the original callsite for the
+ ** index to the allocation.
+ */
searchCallsite = aOldCallsite;
searchHeapID = aOldHeapID;
}
}
break;
- default:
+ default:
{
REPORT_ERROR(__LINE__, allocationTracker);
}
@@ -1755,145 +1718,141 @@ STAllocation* allocationTracker(PRUint32 aTimeval, char aType, PRUint32 aHeapRun
}
/*
- ** We are either modifying an existing allocation or we are creating
- ** a new one.
- */
- if(0 != newAllocation)
- {
- allocation = (STAllocation*)calloc(1, sizeof(STAllocation));
- if(NULL != allocation)
- {
+ ** We are either modifying an existing allocation or we are creating
+ ** a new one.
+ */
+ if (0 != newAllocation) {
+ allocation = (STAllocation *) calloc(1, sizeof(STAllocation));
+ if (NULL != allocation) {
/*
- ** Fixup the min timeval so if logic later will just work.
- */
+ ** Fixup the min timeval so if logic later will just work.
+ */
allocation->mMinTimeval = ST_TIMEVAL_MAX;
allocation->mMaxTimeval = ST_TIMEVAL_MAX;
}
}
- else if(NULL != searchCallsite && NULL != CALLSITE_RUN(searchCallsite) && 0 != searchHeapID)
- {
+ else if (NULL != searchCallsite
+ && NULL != CALLSITE_RUN(searchCallsite)
+ && 0 != searchHeapID) {
/*
- ** We know what to search for, and we reduce what we search
- ** by only looking for those allocations at a known callsite.
- */
- allocation = getLiveAllocationByHeapID(CALLSITE_RUN(searchCallsite), searchHeapID);
+ ** We know what to search for, and we reduce what we search
+ ** by only looking for those allocations at a known callsite.
+ */
+ allocation =
+ getLiveAllocationByHeapID(CALLSITE_RUN(searchCallsite),
+ searchHeapID);
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, allocationTracker);
}
- if(NULL != allocation)
- {
- STAllocEvent* appendResult = NULL;
+ if (NULL != allocation) {
+ STAllocEvent *appendResult = NULL;
/*
- ** Record the amount of time this allocation event took.
- */
+ ** Record the amount of time this allocation event took.
+ */
allocation->mHeapRuntimeCost += aHeapRuntimeCost;
/*
- ** Now that we have an allocation, we need to make sure it has
- ** the proper event.
- */
- appendResult = appendEvent(allocation, aTimeval, aType, aHeapID, aSize, aCallsite);
- if(NULL != appendResult)
- {
- if(0 != newAllocation)
- {
+ ** Now that we have an allocation, we need to make sure it has
+ ** the proper event.
+ */
+ appendResult =
+ appendEvent(allocation, aTimeval, aType, aHeapID, aSize,
+ aCallsite);
+ if (NULL != appendResult) {
+ if (0 != newAllocation) {
int runAppendResult = 0;
int callsiteAppendResult = 0;
/*
- ** A new allocation needs to be added to the global run.
- ** A new allocation needs to be added to the callsite.
- */
- runAppendResult = appendAllocation(&globals.mCommandLineOptions, NULL, &globals.mRun, allocation);
- callsiteAppendResult = appendAllocation(&globals.mCommandLineOptions, NULL, CALLSITE_RUN(aCallsite), allocation);
- if(0 != runAppendResult && 0 != callsiteAppendResult)
- {
+ ** A new allocation needs to be added to the global run.
+ ** A new allocation needs to be added to the callsite.
+ */
+ runAppendResult =
+ appendAllocation(&globals.mCommandLineOptions, NULL,
+ &globals.mRun, allocation);
+ callsiteAppendResult =
+ appendAllocation(&globals.mCommandLineOptions, NULL,
+ CALLSITE_RUN(aCallsite), allocation);
+ if (0 != runAppendResult && 0 != callsiteAppendResult) {
/*
- ** Success.
- */
+ ** Success.
+ */
retval = allocation;
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, appendAllocation);
}
}
- else
- {
+ else {
/*
- ** An existing allocation, if a realloc situation,
- ** may need to be added to the new callsite.
- ** This can only occur if the new and old callsites
- ** differ.
- ** Even then, a brute force check will need to be made
- ** to ensure the allocation was not added twice;
- ** consider a realloc scenario where two different
- ** call stacks bump the allocation back and forth.
- */
- if(aCallsite != searchCallsite)
- {
+ ** An existing allocation, if a realloc situation,
+ ** may need to be added to the new callsite.
+ ** This can only occur if the new and old callsites
+ ** differ.
+ ** Even then, a brute force check will need to be made
+ ** to ensure the allocation was not added twice;
+ ** consider a realloc scenario where two different
+ ** call stacks bump the allocation back and forth.
+ */
+ if (aCallsite != searchCallsite) {
int found = 0;
- found = hasAllocation(CALLSITE_RUN(aCallsite), allocation);
- if(0 == found)
- {
+ found =
+ hasAllocation(CALLSITE_RUN(aCallsite),
+ allocation);
+ if (0 == found) {
int appendResult = 0;
- appendResult = appendAllocation(&globals.mCommandLineOptions, NULL, CALLSITE_RUN(aCallsite), allocation);
- if(0 != appendResult)
- {
+ appendResult =
+ appendAllocation(&globals.mCommandLineOptions,
+ NULL,
+ CALLSITE_RUN(aCallsite),
+ allocation);
+ if (0 != appendResult) {
/*
- ** Success.
- */
+ ** Success.
+ */
retval = allocation;
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, appendAllocation);
}
}
- else
- {
+ else {
/*
- ** Already there.
- */
+ ** Already there.
+ */
retval = allocation;
}
}
- else
- {
+ else {
/*
- ** Success.
- */
+ ** Success.
+ */
retval = allocation;
}
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, appendEvent);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, allocationTracker);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, allocationTracker);
}
/*
- ** Compact the heap a bit if you can.
- */
+ ** Compact the heap a bit if you can.
+ */
compactor++;
- if(0 == (compactor % frequency))
- {
+ if (0 == (compactor % frequency)) {
heapCompact();
}
@@ -1906,34 +1865,36 @@ STAllocation* allocationTracker(PRUint32 aTimeval, char aType, PRUint32 aHeapRun
** An allocation event has dropped in on us.
** We need to do the right thing and track it.
*/
-void trackEvent(PRUint32 aTimeval, char aType, PRUint32 aHeapRuntimeCost, tmcallsite* aCallsite, PRUint32 aHeapID, PRUint32 aSize, tmcallsite* aOldCallsite, PRUint32 aOldHeapID, PRUint32 aOldSize)
+void
+trackEvent(PRUint32 aTimeval, char aType, PRUint32 aHeapRuntimeCost,
+ tmcallsite * aCallsite, PRUint32 aHeapID, PRUint32 aSize,
+ tmcallsite * aOldCallsite, PRUint32 aOldHeapID, PRUint32 aOldSize)
{
- if(NULL != aCallsite)
- {
+ if (NULL != aCallsite) {
/*
- ** Verify the old callsite just in case.
- */
- if(NULL != CALLSITE_RUN(aCallsite) && (NULL == aOldCallsite || NULL != CALLSITE_RUN(aOldCallsite)))
- {
- STAllocation* allocation = NULL;
+ ** Verify the old callsite just in case.
+ */
+ if (NULL != CALLSITE_RUN(aCallsite)
+ && (NULL == aOldCallsite || NULL != CALLSITE_RUN(aOldCallsite))) {
+ STAllocation *allocation = NULL;
/*
- ** Add to the allocation tracking code.
- */
- allocation = allocationTracker(aTimeval, aType, aHeapRuntimeCost, aCallsite, aHeapID, aSize, aOldCallsite, aOldHeapID, aOldSize);
-
- if(NULL == allocation)
- {
+ ** Add to the allocation tracking code.
+ */
+ allocation =
+ allocationTracker(aTimeval, aType, aHeapRuntimeCost,
+ aCallsite, aHeapID, aSize, aOldCallsite,
+ aOldHeapID, aOldSize);
+
+ if (NULL == allocation) {
REPORT_ERROR(__LINE__, allocationTracker);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, trackEvent);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, trackEvent);
}
}
@@ -1944,132 +1905,130 @@ void trackEvent(PRUint32 aTimeval, char aType, PRUint32 aHeapRuntimeCost, tmcall
** Callback from the tmreader_eventloop function.
** Simply tries to sort out what we desire to know.
*/
-void tmEventHandler(tmreader* aReader, tmevent* aEvent)
+void
+tmEventHandler(tmreader * aReader, tmevent * aEvent)
{
- if(NULL != aReader && NULL != aEvent)
- {
- switch(aEvent->type)
- {
+ if (NULL != aReader && NULL != aEvent) {
+ switch (aEvent->type) {
/*
- ** Events we ignore.
- */
- case TM_EVENT_LIBRARY:
- case TM_EVENT_METHOD:
- case TM_EVENT_STATS:
- case TM_EVENT_TIMESTAMP:
- case TM_EVENT_FILENAME:
- break;
+ ** Events we ignore.
+ */
+ case TM_EVENT_LIBRARY:
+ case TM_EVENT_METHOD:
+ case TM_EVENT_STATS:
+ case TM_EVENT_TIMESTAMP:
+ case TM_EVENT_FILENAME:
+ break;
/*
- ** Allocation events need to be tracked.
- */
- case TM_EVENT_MALLOC:
- case TM_EVENT_CALLOC:
- case TM_EVENT_REALLOC:
- case TM_EVENT_FREE:
+ ** Allocation events need to be tracked.
+ */
+ case TM_EVENT_MALLOC:
+ case TM_EVENT_CALLOC:
+ case TM_EVENT_REALLOC:
+ case TM_EVENT_FREE:
{
PRUint32 oldptr = 0;
PRUint32 oldsize = 0;
- tmcallsite* callsite = NULL;
- tmcallsite* oldcallsite = NULL;
+ tmcallsite *callsite = NULL;
+ tmcallsite *oldcallsite = NULL;
- if(TM_EVENT_REALLOC == aEvent->type)
- {
+ if (TM_EVENT_REALLOC == aEvent->type) {
/*
- ** Only care about old arguments if there were any.
- */
- if(0 != aEvent->u.alloc.oldserial)
- {
+ ** Only care about old arguments if there were any.
+ */
+ if (0 != aEvent->u.alloc.oldserial) {
oldptr = aEvent->u.alloc.oldptr;
oldsize = aEvent->u.alloc.oldsize;
- oldcallsite = tmreader_callsite(aReader, aEvent->u.alloc.oldserial);
- if(NULL == oldcallsite)
- {
+ oldcallsite =
+ tmreader_callsite(aReader,
+ aEvent->u.alloc.oldserial);
+ if (NULL == oldcallsite) {
REPORT_ERROR(__LINE__, tmreader_callsite);
}
}
}
callsite = tmreader_callsite(aReader, aEvent->serial);
- if(NULL != callsite)
- {
+ if (NULL != callsite) {
/*
- ** Verify a callsite run is there.
- ** If not, we are ignoring this callsite.
- */
- if(NULL != CALLSITE_RUN(callsite))
- {
+ ** Verify a callsite run is there.
+ ** If not, we are ignoring this callsite.
+ */
+ if (NULL != CALLSITE_RUN(callsite)) {
char eventType = aEvent->type;
PRUint32 eventSize = aEvent->u.alloc.size;
-
+
/*
- ** Play a nasty trick on reallocs of size zero.
- ** They are to become free events, adjust the size accordingly.
- ** This allows me to avoid all types of special case code.
- */
- if(0 == aEvent->u.alloc.size && TM_EVENT_REALLOC == aEvent->type)
- {
+ ** Play a nasty trick on reallocs of size zero.
+ ** They are to become free events, adjust the size accordingly.
+ ** This allows me to avoid all types of special case code.
+ */
+ if (0 == aEvent->u.alloc.size
+ && TM_EVENT_REALLOC == aEvent->type) {
eventType = TM_EVENT_FREE;
- if(0 != aEvent->u.alloc.oldserial)
- {
+ if (0 != aEvent->u.alloc.oldserial) {
eventSize = aEvent->u.alloc.oldsize;
}
}
- trackEvent(ticks2msec(aReader, aEvent->u.alloc.interval), eventType, ticks2usec(aReader, aEvent->u.alloc.cost), callsite, aEvent->u.alloc.ptr, eventSize, oldcallsite, oldptr, oldsize);
+ trackEvent(ticks2msec
+ (aReader, aEvent->u.alloc.interval),
+ eventType, ticks2usec(aReader,
+ aEvent->u.alloc.
+ cost), callsite,
+ aEvent->u.alloc.ptr, eventSize,
+ oldcallsite, oldptr, oldsize);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, tmreader_callsite);
}
}
break;
/*
- ** Callsite, set up the callsite run if it does not exist.
- */
- case TM_EVENT_CALLSITE:
+ ** Callsite, set up the callsite run if it does not exist.
+ */
+ case TM_EVENT_CALLSITE:
{
- tmcallsite* callsite = tmreader_callsite(aReader, aEvent->serial);
+ tmcallsite *callsite =
+ tmreader_callsite(aReader, aEvent->serial);
- if(NULL != callsite)
- {
- if(NULL == CALLSITE_RUN(callsite))
- {
+ if (NULL != callsite) {
+ if (NULL == CALLSITE_RUN(callsite)) {
int createrun = __LINE__;
#if defined(MOZILLA_CLIENT)
/*
- ** For a mozilla spacetrace, ignore this particular
- ** callsite as it is just noise, and causes us to
- ** use a lot of memory.
- **
- ** This callsite is present on the linux build,
- ** not sure if the other platforms have it.
- */
- if(0 != hasCallsiteMatch(callsite, "g_main_is_running", ST_FOLLOW_PARENTS))
- {
+ ** For a mozilla spacetrace, ignore this particular
+ ** callsite as it is just noise, and causes us to
+ ** use a lot of memory.
+ **
+ ** This callsite is present on the linux build,
+ ** not sure if the other platforms have it.
+ */
+ if (0 !=
+ hasCallsiteMatch(callsite, "g_main_is_running",
+ ST_FOLLOW_PARENTS)) {
createrun = 0;
}
#endif /* MOZILLA_CLIENT */
- if(0 != createrun)
- {
+ if (0 != createrun) {
callsite->data = createRun(NULL, 0);
}
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, tmreader_callsite);
}
}
break;
/*
- ** Unhandled events should not be allowed.
- */
- default:
+ ** Unhandled events should not be allowed.
+ */
+ default:
{
REPORT_ERROR(__LINE__, tmEventHandler);
}
@@ -2083,10 +2042,10 @@ void tmEventHandler(tmreader* aReader, tmevent* aEvent)
**
** Output option get data.
*/
-void optionGetDataOut(PRFileDesc* inFD, STOptions* inOptions)
+void
+optionGetDataOut(PRFileDesc * inFD, STOptions * inOptions)
{
- if(NULL != inFD && NULL != inOptions)
- {
+ if (NULL != inFD && NULL != inOptions) {
int mark = 0;
#define ST_WEB_OPTION_BOOL(option_name, option_genre, option_help) \
@@ -2102,7 +2061,7 @@ void optionGetDataOut(PRFileDesc* inFD, STOptions* inOptions)
PR_fprintf(inFD, "%s%s=%s", (0 == mark++) ? "?" : "&", #option_name, inOptions->m##option_name[loop]); \
} \
}
-#define ST_WEB_OPTION_STRING_PTR_ARRAY(option_name, option_genre, option_help) /* no implementation */
+#define ST_WEB_OPTION_STRING_PTR_ARRAY(option_name, option_genre, option_help) /* no implementation */
#define ST_WEB_OPTION_UINT32(option_name, option_genre, default_value, multiplier, option_help) \
PR_fprintf(inFD, "%s%s=%u", (0 == mark++) ? "?" : "&", #option_name, inOptions->m##option_name / multiplier);
#define ST_WEB_OPTION_UINT64(option_name, option_genre, default_value, multiplier, option_help) \
@@ -2124,80 +2083,71 @@ void optionGetDataOut(PRFileDesc* inFD, STOptions* inOptions)
**
** Output an HTML anchor, or just the text depending on the mode.
*/
-void htmlAnchor(STRequest* inRequest,
- const char* aHref,
- const char* aText,
- const char* aTarget,
- const char* aClass,
- STOptions* inOptions)
+void
+htmlAnchor(STRequest * inRequest,
+ const char *aHref,
+ const char *aText,
+ const char *aTarget, const char *aClass, STOptions * inOptions)
{
- if(NULL != aHref && '\0' != *aHref && NULL != aText && '\0' != *aText)
- {
+ if (NULL != aHref && '\0' != *aHref && NULL != aText && '\0' != *aText) {
int anchorLive = 1;
/*
- ** In batch mode, we need to verify the anchor is live.
- */
- if(0 != inRequest->mOptions.mBatchRequestCount)
- {
+ ** In batch mode, we need to verify the anchor is live.
+ */
+ if (0 != inRequest->mOptions.mBatchRequestCount) {
PRUint32 loop = 0;
int comparison = 1;
-
- for(loop = 0; loop < inRequest->mOptions.mBatchRequestCount; loop++)
- {
- comparison = strcmp(aHref, inRequest->mOptions.mBatchRequest[loop]);
- if(0 == comparison)
- {
+
+ for (loop = 0; loop < inRequest->mOptions.mBatchRequestCount;
+ loop++) {
+ comparison =
+ strcmp(aHref, inRequest->mOptions.mBatchRequest[loop]);
+ if (0 == comparison) {
break;
}
}
-
+
/*
- ** Did we find it?
- */
- if(0 == comparison)
- {
+ ** Did we find it?
+ */
+ if (0 == comparison) {
anchorLive = 0;
}
}
/*
- ** In any mode, don't make an href to the current page.
- */
- if(0 != anchorLive && NULL != inRequest->mGetFileName)
- {
- if(0 == strcmp(aHref, inRequest->mGetFileName))
- {
+ ** In any mode, don't make an href to the current page.
+ */
+ if (0 != anchorLive && NULL != inRequest->mGetFileName) {
+ if (0 == strcmp(aHref, inRequest->mGetFileName)) {
anchorLive = 0;
}
}
-
+
/*
- ** Do the right thing.
- */
- if(0 != anchorLive)
- {
+ ** Do the right thing.
+ */
+ if (0 != anchorLive) {
PR_fprintf(inRequest->mFD, "mFD, "target=\"%s\" ", aTarget);
}
PR_fprintf(inRequest->mFD, "href=\"./%s", aHref);
/*
- ** The options, if desired, get appended as form data.
- */
+ ** The options, if desired, get appended as form data.
+ */
optionGetDataOut(inRequest->mFD, inOptions);
PR_fprintf(inRequest->mFD, "\">%s\n", aText);
}
- else
- {
- PR_fprintf(inRequest->mFD, "%s\n", aClass, aText);
+ else {
+ PR_fprintf(inRequest->mFD, "%s\n",
+ aClass, aText);
}
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, htmlAnchor);
}
}
@@ -2207,23 +2157,25 @@ void htmlAnchor(STRequest* inRequest,
**
** Output an html achor that will resolve to the allocation in question.
*/
-void htmlAllocationAnchor(STRequest* inRequest, STAllocation* aAllocation, const char* aText)
+void
+htmlAllocationAnchor(STRequest * inRequest, STAllocation * aAllocation,
+ const char *aText)
{
- if(NULL != aAllocation && NULL != aText && '\0' != *aText)
- {
+ if (NULL != aAllocation && NULL != aText && '\0' != *aText) {
char buffer[128];
/*
- ** This is a total hack.
- ** The filename contains the index of the allocation in globals.mRun.
- ** Safer than using the raw pointer value....
- */
- PR_snprintf(buffer, sizeof(buffer), "allocation_%u.html", aAllocation->mRunIndex);
+ ** This is a total hack.
+ ** The filename contains the index of the allocation in globals.mRun.
+ ** Safer than using the raw pointer value....
+ */
+ PR_snprintf(buffer, sizeof(buffer), "allocation_%u.html",
+ aAllocation->mRunIndex);
- htmlAnchor(inRequest, buffer, aText, NULL, "allocation", &inRequest->mOptions);
+ htmlAnchor(inRequest, buffer, aText, NULL, "allocation",
+ &inRequest->mOptions);
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, htmlAllocationAnchor);
}
}
@@ -2234,25 +2186,23 @@ void htmlAllocationAnchor(STRequest* inRequest, STAllocation* aAllocation, const
** Easy way to get a readable/short name.
** NULL if not present, not resolvable.
*/
-const char* resolveSourceFile(tmmethodnode* aMethod)
+const char *
+resolveSourceFile(tmmethodnode * aMethod)
{
- const char* retval = NULL;
+ const char *retval = NULL;
- if(NULL != aMethod)
- {
- const char* methodSays = NULL;
+ if (NULL != aMethod) {
+ const char *methodSays = NULL;
methodSays = aMethod->sourcefile;
- if(NULL != methodSays && '\0' != methodSays[0] && 0 != strcmp("noname", methodSays))
- {
+ if (NULL != methodSays && '\0' != methodSays[0]
+ && 0 != strcmp("noname", methodSays)) {
retval = strrchr(methodSays, '/');
- if(NULL != retval)
- {
+ if (NULL != retval) {
retval++;
}
- else
- {
+ else {
retval = methodSays;
}
}
@@ -2270,92 +2220,103 @@ const char* resolveSourceFile(tmmethodnode* aMethod)
** RealName determines wether or not we crawl our parents until the point
** we no longer match stats.
*/
-void htmlCallsiteAnchor(STRequest* inRequest, tmcallsite* aCallsite, const char* aText, int aRealName)
+void
+htmlCallsiteAnchor(STRequest * inRequest, tmcallsite * aCallsite,
+ const char *aText, int aRealName)
{
- if(NULL != aCallsite)
- {
+ if (NULL != aCallsite) {
char textBuf[512];
char hrefBuf[128];
- tmcallsite* namesite = aCallsite;
+ tmcallsite *namesite = aCallsite;
/*
- ** Should we use a different name?
- */
- if(0 == aRealName && NULL != namesite->parent && NULL != namesite->parent->method)
- {
- STRun* myRun = NULL;
- STRun* upRun = NULL;
+ ** Should we use a different name?
+ */
+ if (0 == aRealName && NULL != namesite->parent
+ && NULL != namesite->parent->method) {
+ STRun *myRun = NULL;
+ STRun *upRun = NULL;
- do
- {
+ do {
myRun = CALLSITE_RUN(namesite);
upRun = CALLSITE_RUN(namesite->parent);
-
- if(0 != memcmp(&myRun->mStats[inRequest->mContext->mIndex], &upRun->mStats[inRequest->mContext->mIndex], sizeof(STCallsiteStats)))
- {
+
+ if (0 !=
+ memcmp(&myRun->mStats[inRequest->mContext->mIndex],
+ &upRun->mStats[inRequest->mContext->mIndex],
+ sizeof(STCallsiteStats))) {
/*
- ** Doesn't match, stop.
- */
+ ** Doesn't match, stop.
+ */
break;
}
- else
- {
+ else {
/*
- ** Matches, keep going up.
- */
+ ** Matches, keep going up.
+ */
namesite = namesite->parent;
}
}
- while(NULL != namesite->parent && NULL != namesite->parent->method);
+ while (NULL != namesite->parent
+ && NULL != namesite->parent->method);
}
/*
- ** If no text, provide our own.
- */
- if(NULL == aText || '\0' == *aText)
- {
- const char* methodName = NULL;
- const char* sourceFile = NULL;
+ ** If no text, provide our own.
+ */
+ if (NULL == aText || '\0' == *aText) {
+ const char *methodName = NULL;
+ const char *sourceFile = NULL;
- if(NULL != namesite->method)
- {
+ if (NULL != namesite->method) {
methodName = tmmethodnode_name(namesite->method);
}
- else
- {
+ else {
methodName = "==NONAME==";
}
/*
- ** Decide which format to use to identify the callsite.
- ** If we can detect availability, hook up the filename with lxr information.
- */
+ ** Decide which format to use to identify the callsite.
+ ** If we can detect availability, hook up the filename with lxr information.
+ */
sourceFile = resolveSourceFile(namesite->method);
- if(NULL != sourceFile && 0 == strncmp("mozilla/", namesite->method->sourcefile, 8))
- {
+ if (NULL != sourceFile
+ && 0 == strncmp("mozilla/", namesite->method->sourcefile,
+ 8)) {
char lxrHREFBuf[512];
- PR_snprintf(lxrHREFBuf, sizeof(lxrHREFBuf), " [%s:%u]", namesite->method->sourcefile + 8, namesite->method->linenumber, sourceFile, namesite->method->linenumber);
- PR_snprintf(textBuf, sizeof(textBuf), "%s%s", methodName, lxrHREFBuf);
+ PR_snprintf(lxrHREFBuf, sizeof(lxrHREFBuf),
+ " [%s:%u]",
+ namesite->method->sourcefile + 8,
+ namesite->method->linenumber, sourceFile,
+ namesite->method->linenumber);
+ PR_snprintf(textBuf, sizeof(textBuf),
+ "%s%s",
+ methodName, lxrHREFBuf);
}
- else if(NULL != sourceFile)
- {
- PR_snprintf(textBuf, sizeof(textBuf), "%s []", methodName, sourceFile, namesite->method->linenumber);
+ else if (NULL != sourceFile) {
+ PR_snprintf(textBuf, sizeof(textBuf),
+ "%s []",
+ methodName, sourceFile,
+ namesite->method->linenumber);
}
- else
- {
- PR_snprintf(textBuf, sizeof(textBuf), "%s []", methodName, namesite->offset, (PRUint32)namesite->entry.key);
+ else {
+ PR_snprintf(textBuf, sizeof(textBuf),
+ "%s []",
+ methodName, namesite->offset,
+ (PRUint32) namesite->entry.key);
}
aText = textBuf;
}
- PR_snprintf(hrefBuf, sizeof(hrefBuf), "callsite_%u.html", (PRUint32)aCallsite->entry.key);
+ PR_snprintf(hrefBuf, sizeof(hrefBuf), "callsite_%u.html",
+ (PRUint32) aCallsite->entry.key);
- htmlAnchor(inRequest, hrefBuf, aText, NULL, "callsite", &inRequest->mOptions);
+ htmlAnchor(inRequest, hrefBuf, aText, NULL, "callsite",
+ &inRequest->mOptions);
}
- else
- {
+ else {
REPORT_ERROR(__LINE__, htmlCallsiteAnchor);
}
}
@@ -2365,7 +2326,8 @@ void htmlCallsiteAnchor(STRequest* inRequest, tmcallsite* aCallsite, const char*
**
** Output a standard header in the report files.
*/
-void htmlHeader(STRequest* inRequest, const char* aTitle)
+void
+htmlHeader(STRequest * inRequest, const char *aTitle)
{
PR_fprintf(inRequest->mFD,
"\n"
@@ -2379,20 +2341,22 @@ void htmlHeader(STRequest* inRequest, const char* aTitle)
"\n"
"Category:\n"
"%s\n",
- aTitle,
- inRequest->mOptions.mCategoryName);
+ aTitle, inRequest->mOptions.mCategoryName);
- PR_fprintf(inRequest->mFD,"\n");
+ PR_fprintf(inRequest->mFD, "\n");
- PR_fprintf(inRequest->mFD,"\n");
+ PR_fprintf(inRequest->mFD, "\n");
- PR_fprintf(inRequest->mFD,"\n"); /* class=navigate */
+ PR_fprintf(inRequest->mFD, "\n"); /* class=navigate */
- PR_fprintf(inRequest->mFD, "\n\n");
+ PR_fprintf(inRequest->mFD,
+ "\n\n");
}
/*
@@ -2400,16 +2364,14 @@ void htmlHeader(STRequest* inRequest, const char* aTitle)
**
** Output a standard footer in the report file.
*/
-void htmlFooter(STRequest* inRequest)
+void
+htmlFooter(STRequest * inRequest)
{
PR_fprintf(inRequest->mFD,
-"\n"
-"\n"
-"\n"
-"