/* Copyright (c) 1982 Regents of the University of California */
static char sccsid
[] = "@(#)kgmon.c 4.1 82/06/21";
* froms is actually a bunch of unsigned shorts indexing tos
char *system
= "/vmunix";
char *kmemf
= "/dev/kmem";
fprintf(stderr
, "%s: no namelist\n", system
);
fprintf(stderr
, "cannot open ");
"%s opened read-only, data may be inconsistent\n",
off
= nl
[N_SYSMAP
].n_value
& 0x7fffffff;
nl
[N_SYSSIZE
].n_value
*= 4;
Sysmap
= (struct pte
*)malloc(nl
[N_SYSSIZE
].n_value
);
read(kmem
, Sysmap
, nl
[N_SYSSIZE
].n_value
);
turnonoff(PROFILING_OFF
);
fd
= creat("gmon.out", 0666);
klseek(kmem
, (off_t
)sbuf
, 0);
for (i
= ssiz
; i
> 0; i
-= BUFSIZ
) {
read(kmem
, buf
, i
< BUFSIZ
? i
: BUFSIZ
);
write(fd
, buf
, i
< BUFSIZ
? i
: BUFSIZ
);
s_textsize
= kfetch(N_S_TEXTSIZE
);
froms
= (u_short
*)malloc(s_textsize
);
kfroms
= kfetch(N_FROMS
);
for (i
= 0; i
< s_textsize
; i
+= BUFSIZ
) {
k
= read(kmem
, ((char *)(froms
)) + i
, j
);
fprintf(stderr
, "read tos: loc %d, request %d, got %d",
tos
= (struct tostruct
*)malloc(s_textsize
);
for (i
= 0; i
< s_textsize
; i
+= BUFSIZ
) {
k
= read(kmem
, ((char *)(tos
)) + i
, j
);
fprintf(stderr
, "read tos: loc %d, request %d, got %d",
s_lowpc
= (char *)kfetch(N_S_LOWPC
);
fprintf(stderr
, "s_lowpc 0x%x, s_textsize 0x%x\n",
for (fromindex
= 0; fromindex
< s_textsize
>>1; fromindex
++) {
if (froms
[fromindex
] == 0)
frompc
= (u_long
)s_lowpc
+ (fromindex
<<1);
for (toindex
= froms
[fromindex
]; toindex
!= 0;
toindex
= tos
[toindex
].link
) {
"[mcleanup] frompc 0x%x selfpc 0x%x count %d\n" ,
frompc
, tos
[toindex
].selfpc
, tos
[toindex
].count
);
rawarc
.raw_frompc
= frompc
;
rawarc
.raw_selfpc
= (u_long
)tos
[toindex
].selfpc
;
rawarc
.raw_count
= tos
[toindex
].count
;
write(fd
, &rawarc
, sizeof (rawarc
));
if ((off
= nl
[N_PROFILING
].n_value
) == 0) {
printf("profiling: not defined in kernel\n");
write(kmem
, (char *)&onoff
, sizeof (onoff
));
if ((off
= nl
[index
].n_value
) == 0) {
printf("%s: not defined in kernel\n", nl
[index
].n_name
);
if (klseek(kmem
, off
, 0) == -1) {
if (read(kmem
, (char *)&value
, sizeof (value
)) != sizeof (value
)) {
base
= Sysmap
[base
>> 9].pg_pfnum
* 512 + (base
& 0x1ff);
return (lseek(fd
, base
, off
));