* Copyright (c) 1983, 1992 The Regents of the University of California.
* %sccs.include.redist.c%
#if !defined(lint) && defined(LIBC_SCCS)
static char sccsid
[] = "@(#)gmon.c 5.11 (Berkeley) %G%";
extern char *minbrk
asm ("minbrk");
struct gmonparam _gmonparam
= { GMON_PROF_OFF
};
/* see profil(2) where this is describe (incorrectly) */
#define SCALE_1_TO_1 0x10000L
#define ERR(s) write(2, s, sizeof(s))
static struct gmonhdr gmonhdr
;
monstartup(lowpc
, highpc
)
struct clockinfo clockinfo
;
struct gmonparam
*p
= &_gmonparam
;
* round lowpc and highpc to multiples of the density we're using
* so the rest of the scaling (here and in gprof) stays in ints.
lowpc
= ROUNDDOWN(lowpc
, HISTFRACTION
* sizeof(HISTCOUNTER
));
highpc
= ROUNDUP(highpc
, HISTFRACTION
* sizeof(HISTCOUNTER
));
p
->textsize
= highpc
- lowpc
;
ssiz
= p
->textsize
/ HISTFRACTION
;
fsize
= p
->textsize
/ HASHFRACTION
;
tsize
= p
->textsize
* ARCDENSITY
/ 100;
else if (tsize
> MAXARCS
)
tsize
*= sizeof(struct tostruct
);
cp
= sbrk(ssiz
+ fsize
+ tsize
);
ERR("monstartup: out of memory\n");
bzero(cp
, ssiz
+ fsize
+ tsize
);
p
->tos
= (struct tostruct
*)cp
;
p
->froms
= (u_short
*)cp
;
s_scale
= ((float)ssiz
/ o
) * SCALE_1_TO_1
;
#else /* avoid floating point */
s_scale
= 0x10000 / quot
;
s_scale
= 0x1000000 / (o
/ (ssiz
>> 8));
s_scale
= 0x1000000 / ((o
<< 8) / ssiz
);
size
= sizeof(clockinfo
);
if (getkerninfo(KINFO_CLOCKRATE
, &clockinfo
, &size
, 0) < 0)
clockinfo
.profhz
= hertz();
else if (clockinfo
.profhz
== 0) {
clockinfo
.profhz
= clockinfo
.hz
;
clockinfo
.profhz
= hertz();
hdr
= (struct gmonhdr
*)&gmonhdr
;
hdr
->ncnt
= ssiz
+ sizeof(gmonhdr
);
hdr
->version
= GMONVERSION
;
hdr
->profrate
= clockinfo
.profhz
;
struct gmonparam
*p
= &_gmonparam
;
if (p
->state
== GMON_PROF_ERROR
)
ERR("_mcleanup: tos overflow\n");
fd
= creat("gmon.out", 0666);
perror("mcount: gmon.out");
fprintf(stderr
, "[mcleanup] sbuf 0x%x ssiz %d\n", sbuf
, ssiz
);
write(fd
, (char *)&gmonhdr
, sizeof(gmonhdr
));
endfrom
= p
->textsize
/ (HASHFRACTION
* sizeof(*p
->froms
));
for (fromindex
= 0; fromindex
< endfrom
; fromindex
++) {
if (p
->froms
[fromindex
] == 0)
frompc
+= fromindex
* HASHFRACTION
* sizeof(*p
->froms
);
for (toindex
= p
->froms
[fromindex
]; toindex
!= 0;
toindex
= p
->tos
[toindex
].link
) {
"[mcleanup] frompc 0x%x selfpc 0x%x count %d\n" ,
frompc
, p
->tos
[toindex
].selfpc
,
rawarc
.raw_frompc
= frompc
;
rawarc
.raw_selfpc
= p
->tos
[toindex
].selfpc
;
rawarc
.raw_count
= p
->tos
[toindex
].count
;
write(fd
, &rawarc
, sizeof rawarc
);
* profiling is what mcount checks to see if
* all the data structures are ready.
struct gmonparam
*p
= &_gmonparam
;
profil(sbuf
, ssiz
, (int)p
->lowpc
, s_scale
);
profil((char *)0, 0, 0, 0);
p
->state
= GMON_PROF_OFF
;
* discover the tick frequency of the machine
* if something goes wrong, we return 0, an impossible hertz.
tim
.it_interval
.tv_sec
= 0;
tim
.it_interval
.tv_usec
= 1;
tim
.it_value
.tv_usec
= 0;
setitimer(ITIMER_REAL
, &tim
, 0);
setitimer(ITIMER_REAL
, 0, &tim
);
if (tim
.it_interval
.tv_usec
< 2)
return (1000000 / tim
.it_interval
.tv_usec
);