1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is tmreader.h/tmreader.c code, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 2000
22 * the Initial Developer. All Rights Reserved.
25 * Brendan Eich, 7-July-2000
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
45 #include "nsTraceMalloc.h"
50 typedef struct tmreader tmreader
;
51 typedef struct tmevent tmevent
;
52 typedef struct tmcounts tmcounts
;
53 typedef struct tmallcounts tmallcounts
;
54 typedef struct tmgraphlink tmgraphlink
;
55 typedef struct tmgraphedge tmgraphedge
;
56 typedef struct tmgraphnode tmgraphnode
;
57 typedef struct tmcallsite tmcallsite
;
58 typedef struct tmmethodnode tmmethodnode
;
78 uint32 interval
; /* in ticks */
84 uint32 cost
; /* in ticks */
88 uint32 calltree_maxkids_parent
;
89 uint32 calltree_maxstack_top
;
95 uint32 direct
; /* things allocated by this node's code */
96 uint32 total
; /* direct + things from all descendents */
105 PLHashEntry entry
; /* key is serial or name, value must be name */
108 tmgraphnode
*up
; /* parent in supergraph, e.g., JS for JS_*() */
109 tmgraphnode
*down
; /* subgraph kids, declining bytes.total order */
110 tmgraphnode
*next
; /* next kid in supergraph node's down list */
111 int low
; /* 0 or lowest current tree walk level */
114 double sqsum
; /* sum of squared bytes.direct */
115 int sort
; /* sorted index in node table, -1 if no table */
118 struct tmmethodnode
{
119 tmgraphnode graphnode
;
124 #define tmgraphnode_name(node) ((char*) (node)->entry.value)
125 #define tmmethodnode_name(node) ((char*) (node)->graphnode.entry.value)
127 #define tmlibrary_serial(lib) ((uint32) (lib)->entry.key)
128 #define tmcomponent_name(comp) ((const char*) (comp)->entry.key)
129 #define filename_name(hashentry) ((char*)hashentry->value)
131 /* Half a graphedge, not including per-edge allocation stats. */
133 tmgraphlink
*next
; /* next fanning out from or into a node */
134 tmgraphnode
*node
; /* the other node (to if OUT, from if IN) */
138 * It's safe to downcast a "from" tmgraphlink (one linked from a node's out
139 * pointer) to tmgraphedge. To go from an "out" (linked via tmgraphedge.from)
140 * or "in" (linked via tmgraphedge.to) list link to its containing edge, use
141 * TM_LINK_TO_EDGE(link, which).
144 tmgraphlink links
[2];
149 /* Indices into tmgraphedge.links -- out must come first. */
150 #define TM_EDGE_OUT_LINK 0
151 #define TM_EDGE_IN_LINK 1
153 #define TM_LINK_TO_EDGE(link,which) ((tmgraphedge*) &(link)[-(which)])
156 PLHashEntry entry
; /* key is site serial number */
157 tmcallsite
*parent
; /* calling site */
158 tmcallsite
*siblings
; /* other sites reached from parent */
159 tmcallsite
*kids
; /* sites reached from here */
160 tmmethodnode
*method
; /* method node in tmr->methods graph */
161 uint32 offset
; /* pc offset from start of method */
164 void *data
; /* tmreader clients can stick arbitrary
165 * data onto a callsite.
172 PLHashTable
*libraries
;
173 PLHashTable
*filenames
;
174 PLHashTable
*components
;
175 PLHashTable
*methods
;
176 PLHashTable
*callsites
;
178 tmcallsite calltree_root
;
182 typedef void (*tmeventhandler
)(tmreader
*tmr
, tmevent
*event
);
184 /* The tmreader constructor and destructor. */
185 extern tmreader
*tmreader_new(const char *program
, void *data
);
186 extern void tmreader_destroy(tmreader
*tmr
);
189 * Return -1 on permanent fatal error, 0 if filename can't be opened or is not
190 * a trace-malloc logfile, and 1 on success.
192 extern int tmreader_eventloop(tmreader
*tmr
, const char *filename
,
193 tmeventhandler eventhandler
);
195 /* Map serial number or name to graphnode or callsite. */
196 extern tmgraphnode
*tmreader_library(tmreader
*tmr
, uint32 serial
);
197 extern tmgraphnode
*tmreader_filename(tmreader
*tmr
, uint32 serial
);
198 extern tmgraphnode
*tmreader_component(tmreader
*tmr
, const char *name
);
199 extern tmmethodnode
*tmreader_method(tmreader
*tmr
, uint32 serial
);
200 extern tmcallsite
*tmreader_callsite(tmreader
*tmr
, uint32 serial
);
203 * Connect node 'from' to node 'to' with an edge, if there isn't one already
204 * connecting the nodes. Add site's allocation stats to the edge only if we
205 * create the edge, or if we find that it exists, but that to->low is zero or
206 * less than from->low.
208 * If the callsite tree already totals allocation costs (tmcounts.total for
209 * each site includes tmcounts.direct for that site, plus tmcounts.total for
210 * all kid sites), then the node->low watermarks should be set from the tree
211 * level when walking the callsite tree, and should be set to non-zero values
212 * only if zero (the root is at level 0). A low watermark should be cleared
213 * when the tree walk unwinds past the level at which it was set non-zero.
215 * Return 0 on error (malloc failure) and 1 on success.
217 extern int tmgraphnode_connect(tmgraphnode
*from
, tmgraphnode
*to
,
222 #endif /* tmreader_h___ */