2000-04-20 08:55:26 +04:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is nsTraceMalloc.c/bloatblame.c code, released
|
|
|
|
* April 19, 2000.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 2000 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brendan Eich, 14-April-2000
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* terms of the GNU Public License (the "GPL"), in which case the
|
|
|
|
* provisions of the GPL are applicable instead of those above.
|
|
|
|
* If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of the GPL and not to allow others to use your
|
|
|
|
* version of this file under the MPL, indicate your decision by
|
|
|
|
* deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this
|
|
|
|
* file under either the MPL or the GPL.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2000-06-01 07:23:19 +04:00
|
|
|
#ifdef HAVE_GETOPT_H
|
2000-04-20 08:55:26 +04:00
|
|
|
#include <getopt.h>
|
2000-06-28 10:42:29 +04:00
|
|
|
#else
|
|
|
|
extern int getopt(int argc, char *const *argv, const char *shortopts);
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
2000-06-01 07:23:19 +04:00
|
|
|
#endif
|
2000-04-25 03:52:27 +04:00
|
|
|
#include <math.h>
|
2000-04-20 08:55:26 +04:00
|
|
|
#include <time.h>
|
2000-04-27 08:02:22 +04:00
|
|
|
#include <sys/stat.h>
|
2000-04-20 08:55:26 +04:00
|
|
|
#include "prtypes.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "plhash.h"
|
|
|
|
#include "nsTraceMalloc.h"
|
2000-07-09 12:53:46 +04:00
|
|
|
#include "tmreader.h"
|
2000-04-20 08:55:26 +04:00
|
|
|
|
|
|
|
static char *program;
|
|
|
|
static int sort_by_direct = 0;
|
2000-06-28 10:42:29 +04:00
|
|
|
static int js_mode = 0;
|
2000-04-20 08:55:26 +04:00
|
|
|
static int do_tree_dump = 0;
|
2000-06-28 10:42:29 +04:00
|
|
|
static int unified_output = 0;
|
2000-04-23 09:04:58 +04:00
|
|
|
static char *function_dump = NULL;
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
static uint32 min_subtotal = 0;
|
2000-04-20 08:55:26 +04:00
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
static void compute_callsite_totals(tmcallsite *site)
|
2000-04-20 08:55:26 +04:00
|
|
|
{
|
2000-07-09 12:53:46 +04:00
|
|
|
tmcallsite *kid;
|
2000-04-21 12:47:00 +04:00
|
|
|
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
site->allocs.bytes.total += site->allocs.bytes.direct;
|
|
|
|
site->allocs.calls.total += site->allocs.calls.direct;
|
2000-04-21 12:47:00 +04:00
|
|
|
for (kid = site->kids; kid; kid = kid->siblings) {
|
|
|
|
compute_callsite_totals(kid);
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
site->allocs.bytes.total += kid->allocs.bytes.total;
|
|
|
|
site->allocs.calls.total += kid->allocs.calls.total;
|
2000-04-21 12:47:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
static void walk_callsite_tree(tmcallsite *site, int level, int kidnum, FILE *fp)
|
2000-04-20 08:55:26 +04:00
|
|
|
{
|
2000-07-09 12:53:46 +04:00
|
|
|
tmcallsite *parent;
|
|
|
|
tmgraphnode *meth, *pmeth, *comp, *pcomp, *lib, *plib;
|
2000-04-22 01:38:18 +04:00
|
|
|
int old_meth_low, old_comp_low, old_lib_low, nkids;
|
2000-07-09 12:53:46 +04:00
|
|
|
tmcallsite *kid;
|
2000-04-20 08:55:26 +04:00
|
|
|
|
|
|
|
parent = site->parent;
|
|
|
|
meth = comp = lib = NULL;
|
|
|
|
if (parent) {
|
|
|
|
meth = site->method;
|
|
|
|
if (meth) {
|
|
|
|
pmeth = parent->method;
|
|
|
|
if (pmeth && pmeth != meth) {
|
2000-04-25 03:52:27 +04:00
|
|
|
if (!meth->low) {
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
meth->allocs.bytes.total += site->allocs.bytes.total;
|
|
|
|
meth->allocs.calls.total += site->allocs.calls.total;
|
2000-04-25 03:52:27 +04:00
|
|
|
}
|
2000-07-26 06:19:27 +04:00
|
|
|
if (!tmgraphnode_connect(pmeth, meth, site))
|
|
|
|
goto bad;
|
2000-04-20 08:55:26 +04:00
|
|
|
|
|
|
|
comp = meth->up;
|
|
|
|
if (comp) {
|
|
|
|
pcomp = pmeth->up;
|
|
|
|
if (pcomp && pcomp != comp) {
|
2000-04-25 03:52:27 +04:00
|
|
|
if (!comp->low) {
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
comp->allocs.bytes.total
|
|
|
|
+= site->allocs.bytes.total;
|
|
|
|
comp->allocs.calls.total
|
|
|
|
+= site->allocs.calls.total;
|
2000-04-25 03:52:27 +04:00
|
|
|
}
|
2000-07-26 06:19:27 +04:00
|
|
|
if (!tmgraphnode_connect(pcomp, comp, site))
|
|
|
|
goto bad;
|
2000-04-20 08:55:26 +04:00
|
|
|
|
|
|
|
lib = comp->up;
|
|
|
|
if (lib) {
|
|
|
|
plib = pcomp->up;
|
|
|
|
if (plib && plib != lib) {
|
2000-04-25 03:52:27 +04:00
|
|
|
if (!lib->low) {
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
lib->allocs.bytes.total
|
|
|
|
+= site->allocs.bytes.total;
|
|
|
|
lib->allocs.calls.total
|
|
|
|
+= site->allocs.calls.total;
|
2000-04-25 03:52:27 +04:00
|
|
|
}
|
2000-07-26 06:19:27 +04:00
|
|
|
if (!tmgraphnode_connect(plib, lib, site))
|
|
|
|
goto bad;
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
2000-04-22 01:38:18 +04:00
|
|
|
old_lib_low = lib->low;
|
|
|
|
if (!old_lib_low)
|
|
|
|
lib->low = level;
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-22 01:38:18 +04:00
|
|
|
old_comp_low = comp->low;
|
|
|
|
if (!old_comp_low)
|
|
|
|
comp->low = level;
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-22 01:38:18 +04:00
|
|
|
old_meth_low = meth->low;
|
|
|
|
if (!old_meth_low)
|
|
|
|
meth->low = level;
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_tree_dump) {
|
2000-04-21 07:01:09 +04:00
|
|
|
fprintf(fp, "%c%*s%3d %3d %s %lu %ld\n",
|
2000-04-20 08:55:26 +04:00
|
|
|
site->kids ? '+' : '-', level, "", level, kidnum,
|
2000-07-09 12:53:46 +04:00
|
|
|
meth ? tmgraphnode_name(meth) : "???",
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
(unsigned long)site->allocs.bytes.direct,
|
|
|
|
(long)site->allocs.bytes.total);
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
nkids = 0;
|
2000-06-21 22:03:34 +04:00
|
|
|
level++;
|
2000-04-20 08:55:26 +04:00
|
|
|
for (kid = site->kids; kid; kid = kid->siblings) {
|
2000-06-21 22:03:34 +04:00
|
|
|
walk_callsite_tree(kid, level, nkids, fp);
|
2000-04-20 08:55:26 +04:00
|
|
|
nkids++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meth) {
|
2000-04-22 01:38:18 +04:00
|
|
|
if (!old_meth_low)
|
|
|
|
meth->low = 0;
|
2000-04-20 08:55:26 +04:00
|
|
|
if (comp) {
|
2000-04-22 01:38:18 +04:00
|
|
|
if (!old_comp_low)
|
|
|
|
comp->low = 0;
|
|
|
|
if (lib) {
|
|
|
|
if (!old_lib_low)
|
|
|
|
lib->low = 0;
|
|
|
|
}
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
}
|
2000-07-26 06:19:27 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
perror(program);
|
|
|
|
exit(1);
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
/*
|
|
|
|
* Linked list bubble-sort (waterson and brendan went bald hacking this).
|
|
|
|
*
|
|
|
|
* Sort the list in non-increasing order, using the expression passed as the
|
|
|
|
* 'lessthan' formal macro parameter. This expression should use 'curr' as
|
|
|
|
* the pointer to the current node (of type nodetype) and 'next' as the next
|
|
|
|
* node pointer. It should return true if curr is less than next, and false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
#define BUBBLE_SORT_LINKED_LIST(listp, nodetype, lessthan) \
|
2000-06-28 10:42:29 +04:00
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
nodetype *curr, **currp, *next, **nextp, *tmp; \
|
|
|
|
\
|
|
|
|
currp = listp; \
|
|
|
|
while ((curr = *currp) != NULL && curr->next) { \
|
|
|
|
nextp = &curr->next; \
|
|
|
|
while ((next = *nextp) != NULL) { \
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
if (lessthan) { \
|
2000-06-28 10:42:29 +04:00
|
|
|
tmp = curr->next; \
|
|
|
|
*currp = tmp; \
|
|
|
|
if (tmp == next) { \
|
|
|
|
PR_ASSERT(nextp == &curr->next); \
|
|
|
|
curr->next = next->next; \
|
|
|
|
next->next = curr; \
|
|
|
|
} else { \
|
|
|
|
*nextp = next->next; \
|
|
|
|
curr->next = next->next; \
|
|
|
|
next->next = tmp; \
|
|
|
|
*currp = next; \
|
|
|
|
*nextp = curr; \
|
|
|
|
nextp = &curr->next; \
|
|
|
|
} \
|
|
|
|
curr = next; \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
nextp = &next->next; \
|
|
|
|
} \
|
|
|
|
currp = &curr->next; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2000-04-20 08:55:26 +04:00
|
|
|
static PRIntn tabulate_node(PLHashEntry *he, PRIntn i, void *arg)
|
|
|
|
{
|
2000-07-09 12:53:46 +04:00
|
|
|
tmgraphnode *node = (tmgraphnode*) he;
|
|
|
|
tmgraphnode **table = (tmgraphnode**) arg;
|
2000-04-20 08:55:26 +04:00
|
|
|
|
2000-06-28 10:42:29 +04:00
|
|
|
table[i] = node;
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
BUBBLE_SORT_LINKED_LIST(&node->down, tmgraphnode,
|
|
|
|
(curr->allocs.bytes.total < next->allocs.bytes.total));
|
2000-04-20 08:55:26 +04:00
|
|
|
return HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort in reverse size order, so biggest node comes first. */
|
|
|
|
static int node_table_compare(const void *p1, const void *p2)
|
|
|
|
{
|
2000-07-09 12:53:46 +04:00
|
|
|
const tmgraphnode *node1, *node2;
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
uint32 key1, key2;
|
2000-04-20 08:55:26 +04:00
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
node1 = *(const tmgraphnode**) p1;
|
|
|
|
node2 = *(const tmgraphnode**) p2;
|
2000-04-20 08:55:26 +04:00
|
|
|
if (sort_by_direct) {
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
key1 = node1->allocs.bytes.direct;
|
|
|
|
key2 = node2->allocs.bytes.direct;
|
2000-04-20 08:55:26 +04:00
|
|
|
} else {
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
key1 = node1->allocs.bytes.total;
|
|
|
|
key2 = node2->allocs.bytes.total;
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
return (key2 < key1) ? -1 : (key2 > key1) ? 1 : 0;
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
|
2000-04-25 03:52:27 +04:00
|
|
|
static int mean_size_compare(const void *p1, const void *p2)
|
|
|
|
{
|
2000-07-09 12:53:46 +04:00
|
|
|
const tmgraphnode *node1, *node2;
|
2000-04-25 03:52:27 +04:00
|
|
|
double div1, div2, key1, key2;
|
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
node1 = *(const tmgraphnode**) p1;
|
|
|
|
node2 = *(const tmgraphnode**) p2;
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
div1 = (double)node1->allocs.calls.direct;
|
|
|
|
div2 = (double)node2->allocs.calls.direct;
|
2000-04-25 03:52:27 +04:00
|
|
|
if (div1 == 0 || div2 == 0)
|
|
|
|
return div2 - div1;
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
key1 = (double)node1->allocs.bytes.direct / div1;
|
|
|
|
key2 = (double)node2->allocs.bytes.direct / div2;
|
2000-04-25 03:52:27 +04:00
|
|
|
if (key1 < key2)
|
|
|
|
return 1;
|
|
|
|
if (key1 > key2)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-20 08:55:26 +04:00
|
|
|
static const char *prettybig(uint32 num, char *buf, size_t limit)
|
|
|
|
{
|
2000-04-21 07:01:09 +04:00
|
|
|
if (num >= 1000000000)
|
|
|
|
PR_snprintf(buf, limit, "%1.2fG", (double) num / 1e9);
|
|
|
|
else if (num >= 1000000)
|
2000-04-20 08:55:26 +04:00
|
|
|
PR_snprintf(buf, limit, "%1.2fM", (double) num / 1e6);
|
2000-04-21 07:01:09 +04:00
|
|
|
else if (num >= 1000)
|
2000-04-20 08:55:26 +04:00
|
|
|
PR_snprintf(buf, limit, "%1.2fK", (double) num / 1e3);
|
|
|
|
else
|
|
|
|
PR_snprintf(buf, limit, "%lu", (unsigned long) num);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
static double percent(uint32 num, uint32 total)
|
2000-04-20 08:55:26 +04:00
|
|
|
{
|
|
|
|
if (num == 0)
|
|
|
|
return 0.0;
|
|
|
|
return ((double) num * 100) / (double) total;
|
|
|
|
}
|
|
|
|
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
static void sort_graphlink_list(tmgraphlink **listp, int which)
|
2000-04-20 08:55:26 +04:00
|
|
|
{
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
BUBBLE_SORT_LINKED_LIST(listp, tmgraphlink,
|
|
|
|
(TM_LINK_TO_EDGE(curr, which)->allocs.bytes.total
|
|
|
|
< TM_LINK_TO_EDGE(next, which)->allocs.bytes.total));
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
static void dump_graphlink_list(tmgraphlink *list, int which, const char *name,
|
|
|
|
FILE *fp)
|
2000-04-20 08:55:26 +04:00
|
|
|
{
|
2000-07-09 12:53:46 +04:00
|
|
|
tmcounts bytes;
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
tmgraphlink *link;
|
2000-07-09 12:53:46 +04:00
|
|
|
tmgraphedge *edge;
|
2000-04-27 08:02:22 +04:00
|
|
|
char buf[16];
|
2000-04-20 08:55:26 +04:00
|
|
|
|
2000-06-28 10:42:29 +04:00
|
|
|
bytes.direct = bytes.total = 0;
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
for (link = list; link; link = link->next) {
|
|
|
|
edge = TM_LINK_TO_EDGE(link, which);
|
|
|
|
bytes.direct += edge->allocs.bytes.direct;
|
|
|
|
bytes.total += edge->allocs.bytes.total;
|
2000-06-28 10:42:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (js_mode) {
|
|
|
|
fprintf(fp,
|
|
|
|
" %s:{dbytes:%ld, tbytes:%ld, edges:[\n",
|
|
|
|
name, (long) bytes.direct, (long) bytes.total);
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
for (link = list; link; link = link->next) {
|
|
|
|
edge = TM_LINK_TO_EDGE(link, which);
|
2000-06-28 10:42:29 +04:00
|
|
|
fprintf(fp,
|
|
|
|
" {node:%d, dbytes:%ld, tbytes:%ld},\n",
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
link->node->sort,
|
|
|
|
(long) edge->allocs.bytes.direct,
|
|
|
|
(long) edge->allocs.bytes.total);
|
2000-06-28 10:42:29 +04:00
|
|
|
}
|
|
|
|
fputs(" ]},\n", fp);
|
|
|
|
} else {
|
|
|
|
fputs("<td valign=top>", fp);
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
for (link = list; link; link = link->next) {
|
|
|
|
edge = TM_LINK_TO_EDGE(link, which);
|
2000-06-28 10:42:29 +04:00
|
|
|
fprintf(fp,
|
|
|
|
"<a href='#%s'>%s (%1.2f%%)</a>\n",
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
tmgraphnode_name(link->node),
|
|
|
|
prettybig(edge->allocs.bytes.total, buf, sizeof buf),
|
|
|
|
percent(edge->allocs.bytes.total, bytes.total));
|
2000-06-28 10:42:29 +04:00
|
|
|
}
|
|
|
|
fputs("</td>", fp);
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
static void dump_graph(tmreader *tmr, PLHashTable *hashtbl, const char *varname,
|
2000-06-28 10:42:29 +04:00
|
|
|
const char *title, FILE *fp)
|
2000-04-20 08:55:26 +04:00
|
|
|
{
|
|
|
|
uint32 i, count;
|
2000-07-09 12:53:46 +04:00
|
|
|
tmgraphnode **table, *node;
|
2000-04-25 03:52:27 +04:00
|
|
|
char *name;
|
|
|
|
size_t namelen;
|
|
|
|
char buf1[16], buf2[16], buf3[16], buf4[16];
|
|
|
|
static char NA[] = "N/A";
|
2000-04-20 08:55:26 +04:00
|
|
|
|
|
|
|
count = hashtbl->nentries;
|
2000-07-09 12:53:46 +04:00
|
|
|
table = (tmgraphnode**) malloc(count * sizeof(tmgraphnode*));
|
2000-04-20 08:55:26 +04:00
|
|
|
if (!table) {
|
|
|
|
perror(program);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
PL_HashTableEnumerateEntries(hashtbl, tabulate_node, table);
|
2000-07-09 12:53:46 +04:00
|
|
|
qsort(table, count, sizeof(tmgraphnode*), node_table_compare);
|
2000-06-28 10:42:29 +04:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
table[i]->sort = i;
|
2000-04-20 08:55:26 +04:00
|
|
|
|
2000-06-28 10:42:29 +04:00
|
|
|
if (js_mode) {
|
|
|
|
fprintf(fp,
|
|
|
|
"var %s = {\n name:'%s', title:'%s', nodes:[\n",
|
|
|
|
varname, varname, title);
|
|
|
|
} else {
|
|
|
|
fprintf(fp,
|
|
|
|
"<table border=1>\n"
|
|
|
|
"<tr>"
|
|
|
|
"<th>%s</th>"
|
|
|
|
"<th>Down</th>"
|
|
|
|
"<th>Next</th>"
|
|
|
|
"<th>Total/Direct (percents)</th>"
|
|
|
|
"<th>Allocations</th>"
|
|
|
|
"<th>Fan-in</th>"
|
|
|
|
"<th>Fan-out</th>"
|
|
|
|
"</tr>\n",
|
|
|
|
title);
|
|
|
|
}
|
2000-04-20 08:55:26 +04:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
/* Don't bother with truly puny nodes. */
|
2000-04-23 09:04:58 +04:00
|
|
|
node = table[i];
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
if (node->allocs.bytes.total < min_subtotal)
|
2000-04-20 08:55:26 +04:00
|
|
|
break;
|
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
name = tmgraphnode_name(node);
|
2000-06-28 10:42:29 +04:00
|
|
|
if (js_mode) {
|
|
|
|
fprintf(fp,
|
|
|
|
" {name:'%s', dbytes:%ld, tbytes:%ld,"
|
|
|
|
" dallocs:%ld, tallocs:%ld,\n",
|
|
|
|
name,
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
(long) node->allocs.bytes.direct,
|
|
|
|
(long) node->allocs.bytes.total,
|
|
|
|
(long) node->allocs.calls.direct,
|
|
|
|
(long) node->allocs.calls.total);
|
2000-06-28 10:42:29 +04:00
|
|
|
} else {
|
|
|
|
namelen = strlen(name);
|
|
|
|
fprintf(fp,
|
|
|
|
"<tr>"
|
|
|
|
"<td valign=top><a name='%s'>%.*s%s</a></td>",
|
|
|
|
name,
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
(namelen > 40) ? 40 : (int)namelen, name,
|
|
|
|
(namelen > 40) ? "<i>...</i>" : "");
|
2000-06-28 10:42:29 +04:00
|
|
|
if (node->down) {
|
|
|
|
fprintf(fp,
|
|
|
|
"<td valign=top><a href='#%s'><i>down</i></a></td>",
|
2000-07-09 12:53:46 +04:00
|
|
|
tmgraphnode_name(node->down));
|
2000-06-28 10:42:29 +04:00
|
|
|
} else {
|
|
|
|
fputs("<td></td>", fp);
|
|
|
|
}
|
|
|
|
if (node->next) {
|
|
|
|
fprintf(fp,
|
|
|
|
"<td valign=top><a href='#%s'><i>next</i></a></td>",
|
2000-07-09 12:53:46 +04:00
|
|
|
tmgraphnode_name(node->next));
|
2000-06-28 10:42:29 +04:00
|
|
|
} else {
|
|
|
|
fputs("<td></td>", fp);
|
|
|
|
}
|
|
|
|
fprintf(fp,
|
|
|
|
"<td valign=top>%s/%s (%1.2f%%/%1.2f%%)</td>"
|
|
|
|
"<td valign=top>%s/%s (%1.2f%%/%1.2f%%)</td>",
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
prettybig(node->allocs.bytes.total, buf1, sizeof buf1),
|
|
|
|
prettybig(node->allocs.bytes.direct, buf2, sizeof buf2),
|
|
|
|
percent(node->allocs.bytes.total,
|
|
|
|
tmr->calltree_root.allocs.bytes.total),
|
|
|
|
percent(node->allocs.bytes.direct,
|
|
|
|
tmr->calltree_root.allocs.bytes.total),
|
|
|
|
prettybig(node->allocs.calls.total, buf3, sizeof buf3),
|
|
|
|
prettybig(node->allocs.calls.direct, buf4, sizeof buf4),
|
|
|
|
percent(node->allocs.calls.total,
|
|
|
|
tmr->calltree_root.allocs.calls.total),
|
|
|
|
percent(node->allocs.calls.direct,
|
|
|
|
tmr->calltree_root.allocs.calls.total));
|
2000-06-28 10:42:29 +04:00
|
|
|
}
|
2000-04-20 08:55:26 +04:00
|
|
|
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
/* NB: we must use 'fin' because 'in' is a JS keyword! */
|
|
|
|
sort_graphlink_list(&node->in, TM_EDGE_IN_LINK);
|
|
|
|
dump_graphlink_list(node->in, TM_EDGE_IN_LINK, "fin", fp);
|
|
|
|
sort_graphlink_list(&node->out, TM_EDGE_OUT_LINK);
|
|
|
|
dump_graphlink_list(node->out, TM_EDGE_OUT_LINK, "out", fp);
|
2000-04-20 08:55:26 +04:00
|
|
|
|
2000-06-28 10:42:29 +04:00
|
|
|
if (js_mode)
|
|
|
|
fputs(" },\n", fp);
|
|
|
|
else
|
|
|
|
fputs("</tr>\n", fp);
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
|
2000-06-28 10:42:29 +04:00
|
|
|
if (js_mode) {
|
|
|
|
fputs("]};\n", fp);
|
|
|
|
} else {
|
|
|
|
fputs("</table>\n<hr>\n", fp);
|
2000-04-25 03:52:27 +04:00
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
qsort(table, count, sizeof(tmgraphnode*), mean_size_compare);
|
2000-04-25 03:52:27 +04:00
|
|
|
|
|
|
|
fprintf(fp,
|
2000-06-28 10:42:29 +04:00
|
|
|
"<table border=1>\n"
|
|
|
|
"<tr><th colspan=4>Direct Allocators</th></tr>\n"
|
|
|
|
"<tr>"
|
|
|
|
"<th>%s</th>"
|
|
|
|
"<th>Mean Size</th>"
|
|
|
|
"<th>StdDev</th>"
|
|
|
|
"<th>Allocations<th>"
|
|
|
|
"</tr>\n",
|
|
|
|
title);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
double allocs, bytes, mean, variance, sigma;
|
|
|
|
|
|
|
|
node = table[i];
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
allocs = (double)node->allocs.calls.direct;
|
2000-06-28 10:42:29 +04:00
|
|
|
if (!allocs)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Compute direct-size mean and standard deviation. */
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
bytes = (double)node->allocs.bytes.direct;
|
2000-06-28 10:42:29 +04:00
|
|
|
mean = bytes / allocs;
|
|
|
|
variance = allocs * node->sqsum - bytes * bytes;
|
|
|
|
if (variance < 0 || allocs == 1)
|
|
|
|
variance = 0;
|
|
|
|
else
|
|
|
|
variance /= allocs * (allocs - 1);
|
|
|
|
sigma = sqrt(variance);
|
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
name = tmgraphnode_name(node);
|
2000-06-28 10:42:29 +04:00
|
|
|
namelen = strlen(name);
|
|
|
|
fprintf(fp,
|
|
|
|
"<tr>"
|
|
|
|
"<td valign=top>%.*s%s</td>"
|
|
|
|
"<td valign=top>%s</td>"
|
|
|
|
"<td valign=top>%s</td>"
|
|
|
|
"<td valign=top>%s</td>"
|
|
|
|
"</tr>\n",
|
|
|
|
(namelen > 65) ? 45 : (int)namelen, name,
|
|
|
|
(namelen > 65) ? "<i>...</i>" : "",
|
|
|
|
prettybig((uint32)mean, buf1, sizeof buf1),
|
|
|
|
prettybig((uint32)sigma, buf2, sizeof buf2),
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
prettybig(node->allocs.calls.direct, buf3, sizeof buf3));
|
2000-06-28 10:42:29 +04:00
|
|
|
}
|
|
|
|
fputs("</table>\n", fp);
|
2000-04-25 03:52:27 +04:00
|
|
|
}
|
|
|
|
|
2000-04-20 08:55:26 +04:00
|
|
|
free((void*) table);
|
|
|
|
}
|
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
static void my_tmevent_handler(tmreader *tmr, tmevent *event)
|
2000-04-20 08:55:26 +04:00
|
|
|
{
|
2000-07-09 12:53:46 +04:00
|
|
|
switch (event->type) {
|
2000-07-22 00:42:15 +04:00
|
|
|
case TM_EVENT_STATS:
|
2000-07-09 12:53:46 +04:00
|
|
|
if (js_mode)
|
2000-04-20 08:55:26 +04:00
|
|
|
break;
|
2000-07-09 12:53:46 +04:00
|
|
|
fprintf(stdout,
|
|
|
|
"<p><table border=1>"
|
|
|
|
"<tr><th>Counter</th><th>Value</th></tr>\n"
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
"<tr><td>maximum actual stack depth</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>maximum callsite tree depth</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>number of parent callsites</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>maximum kids per parent</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>hits looking for a kid</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>misses looking for a kid</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>steps over other kids</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>callsite recurrences</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>number of stack backtraces</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>backtrace failures</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>backtrace malloc failures</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>backtrace dladdr failures</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>malloc calls</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>malloc failures</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>calloc calls</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>calloc failures</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>realloc calls</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>realloc failures</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>free calls</td><td align=right>%lu</td></tr>\n"
|
|
|
|
"<tr><td>free(null) calls</td><td align=right>%lu</td></tr>\n"
|
2000-07-09 12:53:46 +04:00
|
|
|
"</table>",
|
|
|
|
(unsigned long) event->u.stats.tmstats.calltree_maxstack,
|
|
|
|
(unsigned long) event->u.stats.tmstats.calltree_maxdepth,
|
|
|
|
(unsigned long) event->u.stats.tmstats.calltree_parents,
|
|
|
|
(unsigned long) event->u.stats.tmstats.calltree_maxkids,
|
|
|
|
(unsigned long) event->u.stats.tmstats.calltree_kidhits,
|
|
|
|
(unsigned long) event->u.stats.tmstats.calltree_kidmisses,
|
|
|
|
(unsigned long) event->u.stats.tmstats.calltree_kidsteps,
|
|
|
|
(unsigned long) event->u.stats.tmstats.callsite_recurrences,
|
|
|
|
(unsigned long) event->u.stats.tmstats.backtrace_calls,
|
|
|
|
(unsigned long) event->u.stats.tmstats.backtrace_failures,
|
|
|
|
(unsigned long) event->u.stats.tmstats.btmalloc_failures,
|
|
|
|
(unsigned long) event->u.stats.tmstats.dladdr_failures,
|
|
|
|
(unsigned long) event->u.stats.tmstats.malloc_calls,
|
|
|
|
(unsigned long) event->u.stats.tmstats.malloc_failures,
|
|
|
|
(unsigned long) event->u.stats.tmstats.calloc_calls,
|
|
|
|
(unsigned long) event->u.stats.tmstats.calloc_failures,
|
|
|
|
(unsigned long) event->u.stats.tmstats.realloc_calls,
|
|
|
|
(unsigned long) event->u.stats.tmstats.realloc_failures,
|
|
|
|
(unsigned long) event->u.stats.tmstats.free_calls,
|
|
|
|
(unsigned long) event->u.stats.tmstats.null_free_calls);
|
|
|
|
|
|
|
|
if (event->u.stats.calltree_maxkids_parent) {
|
|
|
|
tmcallsite *site =
|
2000-07-22 00:42:15 +04:00
|
|
|
tmreader_callsite(tmr, event->u.stats.calltree_maxkids_parent);
|
2000-07-09 12:53:46 +04:00
|
|
|
if (site && site->method) {
|
|
|
|
fprintf(stdout, "<p>callsite with the most kids: %s</p>",
|
|
|
|
tmgraphnode_name(site->method));
|
2000-04-27 08:02:22 +04:00
|
|
|
}
|
2000-07-09 12:53:46 +04:00
|
|
|
}
|
2000-04-27 08:02:22 +04:00
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
if (event->u.stats.calltree_maxstack_top) {
|
|
|
|
tmcallsite *site =
|
2000-07-22 00:42:15 +04:00
|
|
|
tmreader_callsite(tmr, event->u.stats.calltree_maxstack_top);
|
2000-07-09 12:53:46 +04:00
|
|
|
fputs("<p>deepest callsite tree path:\n"
|
|
|
|
"<table border=1>\n"
|
|
|
|
"<tr><th>Method</th><th>Offset</th></tr>\n",
|
|
|
|
stdout);
|
|
|
|
while (site) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"<tr><td>%s</td><td>0x%08lX</td></tr>\n",
|
|
|
|
site->method ? tmgraphnode_name(site->method) : "???",
|
|
|
|
(unsigned long) site->offset);
|
|
|
|
site = site->parent;
|
2000-04-27 08:02:22 +04:00
|
|
|
}
|
2000-07-09 12:53:46 +04:00
|
|
|
fputs("</table>\n<hr>\n", stdout);
|
2000-04-27 08:02:22 +04:00
|
|
|
}
|
2000-07-09 12:53:46 +04:00
|
|
|
break;
|
2000-04-27 08:02:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2000-07-22 00:42:15 +04:00
|
|
|
int c, i, j, rv;
|
2000-07-09 12:53:46 +04:00
|
|
|
tmreader *tmr;
|
2000-04-27 08:02:22 +04:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
program = *argv;
|
2000-07-09 12:53:46 +04:00
|
|
|
tmr = tmreader_new(program, NULL);
|
|
|
|
if (!tmr) {
|
2000-04-27 08:02:22 +04:00
|
|
|
perror(program);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-06-28 10:42:29 +04:00
|
|
|
while ((c = getopt(argc, argv, "djtuf:m:")) != EOF) {
|
2000-04-27 08:02:22 +04:00
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
sort_by_direct = 1;
|
|
|
|
break;
|
2000-06-28 10:42:29 +04:00
|
|
|
case 'j':
|
|
|
|
js_mode = 1;
|
|
|
|
break;
|
2000-04-27 08:02:22 +04:00
|
|
|
case 't':
|
|
|
|
do_tree_dump = 1;
|
|
|
|
break;
|
2000-06-28 10:42:29 +04:00
|
|
|
case 'u':
|
|
|
|
unified_output = 1;
|
|
|
|
break;
|
2000-04-27 08:02:22 +04:00
|
|
|
case 'f':
|
|
|
|
function_dump = optarg;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
min_subtotal = atoi(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr,
|
2000-07-09 12:53:46 +04:00
|
|
|
"usage: %s [-dtu] [-f function-dump-filename] [-m min] [output.html]\n",
|
2000-04-27 08:02:22 +04:00
|
|
|
program);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-28 10:42:29 +04:00
|
|
|
if (!js_mode) {
|
|
|
|
time_t start = time(NULL);
|
|
|
|
|
|
|
|
fprintf(stdout,
|
|
|
|
"<script language=\"JavaScript\">\n"
|
|
|
|
"function onload() {\n"
|
|
|
|
" document.links[0].__proto__.onmouseover = new Function("
|
|
|
|
"\"window.status ="
|
|
|
|
" this.href.substring(this.href.lastIndexOf('#') + 1)\");\n"
|
|
|
|
"}\n"
|
|
|
|
"</script>\n");
|
|
|
|
fprintf(stdout, "%s starting at %s", program, ctime(&start));
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2000-04-27 08:02:22 +04:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (argc == 0) {
|
2000-07-22 00:42:15 +04:00
|
|
|
if (tmreader_eventloop(tmr, "-", my_tmevent_handler) <= 0)
|
|
|
|
exit(1);
|
2000-04-27 08:02:22 +04:00
|
|
|
} else {
|
2000-07-22 00:42:15 +04:00
|
|
|
for (i = j = 0; i < argc; i++) {
|
2000-04-27 08:02:22 +04:00
|
|
|
fp = fopen(argv[i], "r");
|
|
|
|
if (!fp) {
|
|
|
|
fprintf(stderr, "%s: can't open %s: %s\n",
|
|
|
|
program, argv[i], strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-07-22 00:42:15 +04:00
|
|
|
rv = tmreader_eventloop(tmr, argv[i], my_tmevent_handler);
|
|
|
|
if (rv < 0)
|
|
|
|
exit(1);
|
|
|
|
if (rv > 0)
|
|
|
|
j++;
|
2000-04-27 08:02:22 +04:00
|
|
|
fclose(fp);
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
2000-07-22 00:42:15 +04:00
|
|
|
if (j == 0)
|
|
|
|
exit(1);
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
compute_callsite_totals(&tmr->calltree_root);
|
|
|
|
walk_callsite_tree(&tmr->calltree_root, 0, 0, stdout);
|
2000-04-20 08:55:26 +04:00
|
|
|
|
2000-06-28 10:42:29 +04:00
|
|
|
if (js_mode) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"<script language='javascript'>\n"
|
|
|
|
"// direct and total byte and allocator-call counts\n"
|
|
|
|
"var dbytes = %ld, tbytes = %ld,"
|
|
|
|
" dallocs = %ld, tallocs = %ld;\n",
|
- Remove <unistd.h> include from bloatblame, it's no longer needed and the link(2) prototype it drags in was causing warnings whenever I used a local variable named 'link'.
- Use uint32 for all quantities, and double for all differences, so that we can overflow without breaking deltas such as (busy == allocs - frees). This doesn't help sorting, however: if one of the sort keys has overflowed past 0 just a bit, while the other is a very large unsigned number, beware.
- Separate graph link (half an edge, structurally speaking -- no per-edge stats) from graph edge, so that an edge is two links and some stats. This avoids bloat and copying in connect_nodes (which is soon to become generic and move to tmreader.[ch]).
- Factor data structures better: we now have {allocs,frees} x {bytes,calls} x {direct, total}, declaring the second set as struct tmallcounts and the third as tmcounts. So, for example, total number of calls to allocators would be allocs.calls.total; bytes freed directly by a graphnode (library, component, or method) would be frees.bytes.direct.
- Teach tmreader_eventloop about 'F' (TM_EVENT_FREE) events: it now updates the direct free byte and call counts for a method, its component, and its library when it reads the event. Of course, bloatblame ignores this info, because it is concerned only with bloat (total memory allocated).
- Right-align numbers in the first (trace-malloc stats) table.
2000-07-26 04:24:08 +04:00
|
|
|
(long) tmr->calltree_root.allocs.bytes.direct,
|
|
|
|
(long) tmr->calltree_root.allocs.bytes.total,
|
|
|
|
(long) tmr->calltree_root.allocs.calls.direct,
|
|
|
|
(long) tmr->calltree_root.allocs.calls.total);
|
2000-06-28 10:42:29 +04:00
|
|
|
}
|
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
dump_graph(tmr, tmr->libraries, "libraries", "Library", stdout);
|
2000-06-28 10:42:29 +04:00
|
|
|
if (!js_mode)
|
|
|
|
fputs("<hr>\n", stdout);
|
2000-04-27 08:02:22 +04:00
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
dump_graph(tmr, tmr->components, "classes", "Class or Component", stdout);
|
2000-06-28 10:42:29 +04:00
|
|
|
if (js_mode || unified_output || function_dump) {
|
|
|
|
if (js_mode || unified_output || strcmp(function_dump, "-") == 0) {
|
2000-04-27 08:02:22 +04:00
|
|
|
fp = stdout;
|
2000-06-28 10:42:29 +04:00
|
|
|
if (!js_mode)
|
|
|
|
fputs("<hr>\n", fp);
|
2000-04-27 08:02:22 +04:00
|
|
|
} else {
|
2000-06-28 10:42:29 +04:00
|
|
|
struct stat sb, fsb;
|
|
|
|
|
|
|
|
fstat(fileno(stdout), &sb);
|
|
|
|
if (stat(function_dump, &fsb) == 0 &&
|
|
|
|
fsb.st_dev == sb.st_dev && fsb.st_ino == sb.st_ino) {
|
|
|
|
fp = stdout;
|
|
|
|
fputs("<hr>\n", fp);
|
|
|
|
} else {
|
|
|
|
fp = fopen(function_dump, "w");
|
|
|
|
if (!fp) {
|
|
|
|
fprintf(stderr, "%s: can't open %s: %s\n",
|
|
|
|
program, function_dump, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-04-27 08:02:22 +04:00
|
|
|
}
|
2000-04-23 09:04:58 +04:00
|
|
|
}
|
2000-06-28 10:42:29 +04:00
|
|
|
|
2000-07-09 12:53:46 +04:00
|
|
|
dump_graph(tmr, tmr->methods, "methods", "Function or Method", fp);
|
2000-04-27 08:02:22 +04:00
|
|
|
if (fp != stdout)
|
|
|
|
fclose(fp);
|
2000-06-28 10:42:29 +04:00
|
|
|
|
|
|
|
if (js_mode) {
|
|
|
|
fputs("function viewnode(graph, index) {\n"
|
|
|
|
" view.location = viewsrc();\n"
|
|
|
|
"}\n"
|
|
|
|
"function viewnodelink(graph, index) {\n"
|
|
|
|
" var node = graph.nodes[index];\n"
|
|
|
|
" return '<a href=\"javascript:viewnode('"
|
|
|
|
" + graph.name.quote() + ', ' + node.sort"
|
|
|
|
" + ')\" onmouseover=' + node.name.quote() + '>'"
|
|
|
|
" + node.name + '</a>';\n"
|
|
|
|
"}\n"
|
|
|
|
"function search(expr) {\n"
|
|
|
|
" var re = new RegExp(expr);\n"
|
|
|
|
" var src = '';\n"
|
|
|
|
" var graphs = [libraries, classes, methods]\n"
|
|
|
|
" var nodes;\n"
|
|
|
|
" for (var n = 0; n < (nodes = graphs[n].nodes).length; n++) {\n"
|
|
|
|
" for (var i = 0; i < nodes.length; i++) {\n"
|
|
|
|
" if (re.test(nodes[i].name))\n"
|
|
|
|
" src += viewnodelink(graph, i) + '\\n';\n"
|
|
|
|
" }\n"
|
|
|
|
" }\n"
|
|
|
|
" view.location = viewsrc();\n"
|
|
|
|
"}\n"
|
|
|
|
"function ctrlsrc() {\n"
|
|
|
|
" return \"<form>\\n"
|
|
|
|
"search: <input size=40 onchange='search(this.value)'>\\n"
|
|
|
|
"</form>\\n\";\n"
|
|
|
|
"}\n"
|
|
|
|
"function viewsrc() {\n"
|
|
|
|
" return 'hiiiii'\n"
|
|
|
|
"}\n"
|
|
|
|
"</script>\n"
|
|
|
|
"<frameset rows='10%,*'>\n"
|
|
|
|
" <frame name='ctrl' src='javascript:top.ctrlsrc()'>\n"
|
|
|
|
" <frame name='view' src='javascript:top.viewsrc()'>\n"
|
|
|
|
"</frameset>\n",
|
|
|
|
stdout);
|
|
|
|
}
|
2000-04-23 09:04:58 +04:00
|
|
|
}
|
2000-04-20 08:55:26 +04:00
|
|
|
|
2000-04-27 08:02:22 +04:00
|
|
|
exit(0);
|
2000-04-20 08:55:26 +04:00
|
|
|
}
|