1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SGS_GPROF_H
#define _SGS_GPROF_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <elf.h>
#include "sparc.h"
#include "gelf.h"
#include "monv.h"
#include "sgs.h"
/*
* who am i, for error messages.
*/
extern char *whoami;
/*
* booleans
*/
typedef Boolean bool;
/*
* Alignment related constants
*/
#define PGSZ 4096
#define STRUCT_ALIGN 8
/*
* Macros related to structure alignment
*/
#define FLOOR(x, align) (((Address) x) & ~((align) - 1l))
#define CEIL(x, align) FLOOR(((Address) x) + (align) - 1l, align)
#define PROFHDR_SZ (CEIL(sizeof (ProfHeader), STRUCT_ALIGN))
#define PROFMODLIST_SZ (CEIL(sizeof (ProfModuleList), STRUCT_ALIGN))
#define PROFMOD_SZ (CEIL(sizeof (ProfModule), STRUCT_ALIGN))
#define PROFBUF_SZ (CEIL(sizeof (ProfBuffer), STRUCT_ALIGN))
#define PROFCGRAPH_SZ (CEIL(sizeof (ProfCallGraph), STRUCT_ALIGN))
#define PROFFUNC_SZ (CEIL(sizeof (ProfFunction), STRUCT_ALIGN))
#define HDR_FILLER (PROFHDR_SZ - sizeof (ProfHeader))
#define MODLIST_FILLER (PROFMODLIST_SZ - sizeof (ProfModuleList))
#define MOD_FILLER (PROFMOD_SZ - sizeof (ProfModule))
#define BUF_FILLER (PROFBUF_SZ - sizeof (ProfBuffer))
#define CGRAPH_FILLER (PROFCGRAPH_SZ - sizeof (ProfCallGraph))
#define FUNC_FILLER (PROFFUNC_SZ - sizeof (ProfFunction))
/*
* ticks per second
*/
extern long hz;
typedef short UNIT; /* unit of profiling */
typedef unsigned short unsigned_UNIT; /* to remove warnings from gprof.c */
extern char *a_outname;
extern char *prog_name; /* keep the program name for error messages */
#define A_OUTNAME "a.out"
typedef unsigned long long pctype;
typedef uint32_t pctype32;
typedef size_t sztype;
/*
* Type definition for the arc count.
*/
typedef long long actype;
typedef int32_t actype32;
extern char *gmonname;
#define GMONNAME "gmon.out"
#define GMONSUM "gmon.sum"
/*
* Special symbols used for profiling of shared libraries through
* the run-time linker.
*/
#define PRF_ETEXT "_etext"
#define PRF_EXTSYM "<external>"
#define PRF_MEMTERM "_END_OF_VIRTUAL_MEMORY"
#define PRF_SYMCNT 3
/*
* Special symbol needed to determine the program exec's end addr.
* Note that since this symbol doesn't get added to the nameslist,
* it doesn't have to be counted in PRF_SYMCNT
*/
#define PRF_END "_end"
/*
* blurbs on the flat and graph profiles.
*/
#define FLAT_BLURB "/usr/share/lib/ccs/gprof.flat.blurb"
#define CALLG_BLURB "/usr/share/lib/ccs/gprof.callg.blurb"
/*
* a raw arc,
* with pointers to the calling site and the called site
* and a count.
*/
struct rawarc {
pctype raw_frompc;
pctype raw_selfpc;
actype raw_count;
};
struct rawarc32 {
pctype32 raw_frompc;
pctype32 raw_selfpc;
actype32 raw_count;
};
/*
* a constructed arc,
* with pointers to the namelist entry of the parent and the child,
* a count of how many times this arc was traversed,
* and pointers to the next parent of this child and
* the next child of this parent.
*/
struct arcstruct {
struct nl *arc_parentp; /* pointer to parent's nl entry */
struct nl *arc_childp; /* pointer to child's nl entry */
actype arc_count; /* how calls from parent to child */
double arc_time; /* time inherited along arc */
double arc_childtime; /* childtime inherited along arc */
struct arcstruct *arc_parentlist; /* parents-of-this-child list */
struct arcstruct *arc_childlist; /* children-of-this-parent list */
};
typedef struct arcstruct arctype;
/*
* Additions for new-style gmon.out
*/
extern bool old_style; /* gmon.out versioned/non-versioned ? */
/*
* Executable file info.
*
* All info that is required to identify a file or see if it has changed
* relative to another file.
*/
struct fl_info {
dev_t dev; /* device associated with this file */
ino_t ino; /* i-number of this file */
time_t mtime; /* last modified time of this file */
off_t size; /* size of file */
};
typedef struct fl_info fl_info_t;
/*
* Saved file info.
*/
extern fl_info_t aout_info; /* saved file info for program exec */
extern fl_info_t gmonout_info; /* current gmonout's info */
/*
* Module info.
*/
struct mod_info {
struct mod_info *next; /* ptr to next in the modules list */
char *name; /* name of this module */
int id; /* id, used while printing */
bool active; /* is this module active or not ? */
struct nl *nl; /* ptr to nameslist for this module */
struct nl *npe; /* virtual end of module's namelist */
sztype nname; /* number of funcs in this module */
GElf_Addr txt_origin; /* module's start as given in file */
GElf_Addr data_end; /* module's end addr as in file */
Address load_base; /* actual pcaddr where modl's loaded */
Address load_end; /* actual pcaddr where modl ends */
};
typedef struct mod_info mod_info_t;
extern sztype total_names; /* from all modules */
/*
* List of shared object modules. Note that this always includes the
* program executable as the first element.
*/
extern mod_info_t modules;
extern sztype n_modules;
/*
* The symbol table;
* for each external in the specified file we gather
* its address, the number of calls and compute its share of cpu time.
*/
struct nl {
char *name; /* the name */
mod_info_t *module; /* module to which this belongs */
pctype value; /* the pc entry point */
pctype svalue; /* entry point aligned to histograms */
unsigned long sz; /* function size */
unsigned char syminfo; /* sym info */
size_t nticks; /* ticks in this routine */
double time; /* ticks in this routine as double */
double childtime; /* cumulative ticks in children */
actype ncall; /* how many times called */
actype selfcalls; /* how many calls to self */
double propfraction; /* what % of time propagates */
double propself; /* how much self time propagates */
double propchild; /* how much child time propagates */
bool printflag; /* should this be printed? */
int index; /* index in the graph list */
int toporder; /* graph call chain top-sort order */
int cycleno; /* internal number of cycle on */
struct nl *cyclehead; /* pointer to head of cycle */
struct nl *cnext; /* pointer to next member of cycle */
arctype *parents; /* list of caller arcs */
arctype *children; /* list of callee arcs */
unsigned long ncallers; /* no. of callers - dumpsum use only */
};
typedef struct nl nltype;
/*
* flag which marks a nl entry as topologically ``busy''
* flag which marks a nl entry as topologically ``not_numbered''
*/
#define DFN_BUSY -1
#define DFN_NAN 0
/*
* namelist entries for cycle headers.
* the number of discovered cycles.
*/
extern nltype *cyclenl; /* cycle header namelist */
extern int ncycle; /* number of cycles discovered */
/*
* The header on the gmon.out file.
* old-style gmon.out consists of one of these headers,
* and then an array of ncnt samples
* representing the discretized program counter values.
* this should be a struct phdr, but since everything is done
* as UNITs, this is in UNITs too.
*/
struct hdr {
pctype lowpc;
pctype highpc;
pctype ncnt;
};
struct hdr32 {
pctype32 lowpc;
pctype32 highpc;
pctype32 ncnt;
};
extern struct hdr h; /* header of profiled data */
extern int debug;
extern int number_funcs_toprint;
/*
* Each discretized pc sample has
* a count of the number of samples in its range
*/
extern unsigned short *samples;
extern pctype s_lowpc; /* lowpc from profile file in o-s gmon.out */
extern pctype s_highpc; /* highpc from profile file in o-s gmon.out */
extern sztype sampbytes; /* number of bytes of samples in o-s gmon.out */
extern sztype nsamples; /* number of samples for old-style gmon.out */
extern double actime; /* accumulated time thus far for putprofline */
extern double totime; /* total time for all routines */
extern double printtime; /* total of time being printed */
extern double scale; /* scale factor converting samples to pc */
/* values: each sample covers scale bytes */
/* -- all this is for old-style gmon.out only */
extern unsigned char *textspace; /* text space of a.out in core */
extern bool first_file; /* for difference option */
/*
* Total number of pcsamples read so far (across gmon.out's)
*/
extern Size n_pcsamples;
/*
* option flags, from a to z.
*/
extern bool aflag; /* suppress static functions */
extern bool bflag; /* blurbs, too */
extern bool Bflag; /* big pc's (i.e. 64 bits) */
extern bool cflag; /* discovered call graph, too */
extern bool Cflag; /* gprofing c++ -- need demangling */
extern bool dflag; /* debugging options */
extern bool Dflag; /* difference option */
extern bool eflag; /* specific functions excluded */
extern bool Eflag; /* functions excluded with time */
extern bool fflag; /* specific functions requested */
extern bool Fflag; /* functions requested with time */
extern bool lflag; /* exclude LOCAL syms in output */
extern bool sflag; /* sum multiple gmon.out files */
extern bool zflag; /* zero time/called functions, too */
extern bool nflag; /* print only n functions in report */
extern bool rflag; /* profiling input generated by */
/* run-time linker */
/*
* structure for various string lists
*/
struct stringlist {
struct stringlist *next;
char *string;
};
extern struct stringlist *elist;
extern struct stringlist *Elist;
extern struct stringlist *flist;
extern struct stringlist *Flist;
/*
* function declarations
*/
void addlist(struct stringlist *, char *);
void addarc(nltype *, nltype *, actype);
int arccmp(arctype *, arctype *);
arctype *arclookup(nltype *, nltype *);
void printblurb(char *);
void dfn(nltype *);
bool dfn_busy(nltype *);
void dfn_findcycle(nltype *);
bool dfn_numbered(nltype *);
void dfn_post_visit(nltype *);
void dfn_pre_visit(nltype *);
void dfn_self_cycle(nltype *);
nltype **doarcs(void);
void done(void);
void findcalls(nltype *, pctype, pctype);
void flatprofheader(void);
void flatprofline(nltype *);
bool is_shared_obj(char *);
void getnfile(char *);
void process_namelist(mod_info_t *);
void gprofheader(void);
void gprofline(nltype *);
int pc_cmp(const void *arg1, const void *arg2);
int membercmp(nltype *, nltype *);
nltype *nllookup(mod_info_t *, pctype, pctype *);
bool onlist(struct stringlist *, char *);
void printchildren(nltype *);
void printcycle(nltype *);
void printgprof(nltype **);
void printindex(void);
void printmembers(nltype *);
void printmodules(void);
void printname(nltype *);
void printparents(nltype *);
void printprof(void);
void sortchildren(nltype *);
void sortmembers(nltype *);
void sortparents(nltype *);
int timecmp(const void *arg1, const void *arg2);
int totalcmp(const void *arg1, const void *arg2);
#define LESSTHAN -1
#define EQUALTO 0
#define GREATERTHAN 1
/*
* Macros related to debug messages.
*/
#define DFNDEBUG 0x0001
#define CYCLEDEBUG 0x0002
#define ARCDEBUG 0x0004
#define TALLYDEBUG 0x0008
#define TIMEDEBUG 0x0010
#define SAMPLEDEBUG 0x0020
#define ELFDEBUG 0x0040
#define CALLSDEBUG 0x0080
#define LOOKUPDEBUG 0x0100
#define PROPDEBUG 0x0200
#define ANYDEBUG 0x0400
#define MONOUTDEBUG 0x0800
#define MODULEDEBUG 0x1000
#define CGRAPHDEBUG 0x2000
#define PCSMPLDEBUG 0x4000
#ifdef __cplusplus
}
#endif
#endif /* _SGS_GPROF_H */
|