1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include "nsTraceMalloc.h"
17 typedef struct tmreader tmreader
;
18 typedef struct tmevent tmevent
;
19 typedef struct tmcounts tmcounts
;
20 typedef struct tmallcounts tmallcounts
;
21 typedef struct tmgraphlink tmgraphlink
;
22 typedef struct tmgraphedge tmgraphedge
;
23 typedef struct tmgraphnode tmgraphnode
;
24 typedef struct tmcallsite tmcallsite
;
25 typedef struct tmmethodnode tmmethodnode
;
45 uint32_t interval
; /* in ticks */
51 uint32_t cost
; /* in ticks */
55 uint32_t calltree_maxkids_parent
;
56 uint32_t calltree_maxstack_top
;
62 uint32_t direct
; /* things allocated by this node's code */
63 uint32_t total
; /* direct + things from all descendents */
72 PLHashEntry entry
; /* key is serial or name, value must be name */
75 tmgraphnode
*up
; /* parent in supergraph, e.g., JS for JS_*() */
76 tmgraphnode
*down
; /* subgraph kids, declining bytes.total order */
77 tmgraphnode
*next
; /* next kid in supergraph node's down list */
78 int low
; /* 0 or lowest current tree walk level */
81 double sqsum
; /* sum of squared bytes.direct */
82 int sort
; /* sorted index in node table, -1 if no table */
86 tmgraphnode graphnode
;
91 #define tmgraphnode_name(node) ((char*) (node)->entry.value)
92 #define tmmethodnode_name(node) ((char*) (node)->graphnode.entry.value)
94 #define tmlibrary_serial(lib) ((uint32_t) (lib)->entry.key)
95 #define tmcomponent_name(comp) ((const char*) (comp)->entry.key)
96 #define filename_name(hashentry) ((char*)hashentry->value)
98 /* Half a graphedge, not including per-edge allocation stats. */
100 tmgraphlink
*next
; /* next fanning out from or into a node */
101 tmgraphnode
*node
; /* the other node (to if OUT, from if IN) */
105 * It's safe to downcast a "from" tmgraphlink (one linked from a node's out
106 * pointer) to tmgraphedge. To go from an "out" (linked via tmgraphedge.from)
107 * or "in" (linked via tmgraphedge.to) list link to its containing edge, use
108 * TM_LINK_TO_EDGE(link, which).
111 tmgraphlink links
[2];
116 /* Indices into tmgraphedge.links -- out must come first. */
117 #define TM_EDGE_OUT_LINK 0
118 #define TM_EDGE_IN_LINK 1
120 #define TM_LINK_TO_EDGE(link,which) ((tmgraphedge*) &(link)[-(which)])
123 PLHashEntry entry
; /* key is site serial number */
124 tmcallsite
*parent
; /* calling site */
125 tmcallsite
*siblings
; /* other sites reached from parent */
126 tmcallsite
*kids
; /* sites reached from here */
127 tmmethodnode
*method
; /* method node in tmr->methods graph */
128 uint32_t offset
; /* pc offset from start of method */
131 void *data
; /* tmreader clients can stick arbitrary
132 * data onto a callsite.
139 PLHashTable
*libraries
;
140 PLHashTable
*filenames
;
141 PLHashTable
*components
;
142 PLHashTable
*methods
;
143 PLHashTable
*callsites
;
145 tmcallsite calltree_root
;
146 uint32_t ticksPerSec
;
149 typedef void (*tmeventhandler
)(tmreader
*tmr
, tmevent
*event
);
151 /* The tmreader constructor and destructor. */
152 extern tmreader
*tmreader_new(const char *program
, void *data
);
153 extern void tmreader_destroy(tmreader
*tmr
);
156 * Return -1 on permanent fatal error, 0 if filename can't be opened or is not
157 * a trace-malloc logfile, and 1 on success.
159 extern int tmreader_eventloop(tmreader
*tmr
, const char *filename
,
160 tmeventhandler eventhandler
);
162 /* Map serial number or name to graphnode or callsite. */
163 extern tmgraphnode
*tmreader_library(tmreader
*tmr
, uint32_t serial
);
164 extern tmgraphnode
*tmreader_filename(tmreader
*tmr
, uint32_t serial
);
165 extern tmgraphnode
*tmreader_component(tmreader
*tmr
, const char *name
);
166 extern tmmethodnode
*tmreader_method(tmreader
*tmr
, uint32_t serial
);
167 extern tmcallsite
*tmreader_callsite(tmreader
*tmr
, uint32_t serial
);
170 * Connect node 'from' to node 'to' with an edge, if there isn't one already
171 * connecting the nodes. Add site's allocation stats to the edge only if we
172 * create the edge, or if we find that it exists, but that to->low is zero or
173 * less than from->low.
175 * If the callsite tree already totals allocation costs (tmcounts.total for
176 * each site includes tmcounts.direct for that site, plus tmcounts.total for
177 * all kid sites), then the node->low watermarks should be set from the tree
178 * level when walking the callsite tree, and should be set to non-zero values
179 * only if zero (the root is at level 0). A low watermark should be cleared
180 * when the tree walk unwinds past the level at which it was set non-zero.
182 * Return 0 on error (malloc failure) and 1 on success.
184 extern int tmgraphnode_connect(tmgraphnode
*from
, tmgraphnode
*to
,
191 #endif /* tmreader_h___ */