* Print execution profile
typedef short UNIT
; /* unit of profiling */
int timcmp(), valcmp(), cntcmp();
if(**argv
>= '0' && **argv
<= '9') {
if(highpc
<= lowpc
|| highpc
> 100)
ransca
= 100./(highpc
-lowpc
);
ranoff
= 2040. + 40.8*lowpc
*ransca
;
if((nfile
=fopen(namfil
,"r"))==NULL
) {
fprintf(stderr
, "%s: not found\n", namfil
);
fread(&xbuf
, 1, sizeof(xbuf
), nfile
);
if (xbuf
.a_magic
!=A_MAGIC1
&& xbuf
.a_magic
!=A_MAGIC2
&& xbuf
.a_magic
!=A_MAGIC3
) {
fprintf(stderr
, "%s: bad format\n", namfil
);
symoff
= (long)xbuf
.a_text
+ xbuf
.a_data
+ xbuf
.a_trsize
+ xbuf
.a_drsize
;
fseek(nfile
, symoff
+sizeof(xbuf
), 0);
if((pfile
= fopen("mon.out","r")) == NULL
) {
fprintf(stderr
, "No mon.out\n");
fstat(fileno(pfile
), &stbuf
);
fread(&h
, sizeof(struct hdr
), 1, pfile
);
lowpc
= h
.lowpc
- (UNIT
*)0;
highpc
= h
.highpc
- (UNIT
*)0;
bufs
= stbuf
.st_size
- sizeof(struct hdr
) - h
.ncount
*sizeof(struct cnt
);
fread(cbuf
, sizeof(struct cnt
), h
.ncount
, pfile
);
for (nname
= 0; xbuf
.a_syms
> 0; xbuf
.a_syms
-= sizeof(struct nlist
)) {
fread(&nbuf
, sizeof(nbuf
), 1, nfile
);
if (nbuf
.n_type
!=N_TEXT
&& nbuf
.n_type
!=N_TEXT
+N_EXT
)
if (aflg
==0 && nbuf
.n_type
!=N_TEXT
+N_EXT
)
npe
->value
= nbuf
.n_value
/sizeof(UNIT
);
npe
->name
[i
] = nbuf
.n_name
[i
];
fprintf(stderr
, "%s: no symbols\n", namfil
);
cp
= &cbuf
[h
.ncount
]; while ((--cp
)->cvalue
==0); ++cp
; h
.ncount
=cp
-cbuf
;
for (;--cp
>=cbuf
;) cp
->cvalue
/= sizeof(UNIT
);
qsort(cbuf
, h
.ncount
, sizeof(struct cnt
), cntcmp
);
qsort(nl
, nname
, sizeof(struct nl
), valcmp
);
cp
= &cbuf
[h
.ncount
-1]; np
= npe
;
if (cp
<cbuf
|| np
->value
> cp
->cvalue
) continue;
while (cp
>=cbuf
&& cp
->cvalue
- np
->value
>11) --cp
;
if (cp
->cvalue
>= np
->value
) {np
->ncall
= cp
->cncall
; --cp
;}
scale
/= bufs
/sizeof(UNIT
);
fread(&ccnt
, sizeof(ccnt
), 1, pfile
);
pch
= lowpc
+ scale
*(i
+1);
for (j
=0; j
<nname
; j
++) {
if (pcl
>= nl
[j
+1].value
)
overlap
=(min(pch
,nl
[j
+1].value
)-max(pcl
,nl
[j
].value
));
if (overlap
>0) nl
[j
].time
+= overlap
*time
/scale
;
fprintf(stderr
, "No time accumulated\n");
space(-2048, -2048, 2048, 2048);
line(-2040, -2040, -2040, 2040);
line(-2040, 2040-i
*408, 0, 2040-i
*408);
scale
= (4080.*ransca
)/(bufs
/sizeof(UNIT
));
fclose(pfile
); /*to turn off eof*/
pfile
= fopen("mon.out", "r");
fread(&ccnt
, sizeof(ccnt
), 1, pfile
);
lastsx
=- 2000.*time
/totime
;
if(lasty
>= -2040. && ty
<= 2040.) {
line((int)tx
, (int)ty
, (int)lastsx
, (int)lasty
);
if (ccnt
!=0 || lastx
!=0.0) {
lastx
= -time
*2000./maxtime
;
line(0, (int)ty
, (int)tx
, (int)ty
);
scale
= (4080.*ransca
)/(highpc
-lowpc
);
for(np
= nl
; np
<npe
; np
++) {
lasty
= ranoff
- (np
->value
- lowpc
)*scale
;
if(lasty
>= -2040. && lasty
<= 2040.) {
line(0, (int)lasty
, 50, (int)lasty
);
line((int)(lastx
-50),(int)lasty
,(int)lastx
,(int)lasty
);
point((int)(lastx
+30), (int)(lasty
+10));
printf(" name %%time cumsecs #call ms/call\n");
qsort(nl
, nname
, sizeof(struct nl
), timcmp
);
for (np
= nl
; np
<npe
-1; np
++) {
printf("%8.8s%6.1f%9.2f", np
->name
, 100*time
, actime
/60);
printf("%7ld", np
->ncall
);
printf(" %8.2f\n", np
->time
/(np
->ncall
*.06));
return(p1
->value
- p2
->value
);
return(p1
->cvalue
- p2
->cvalue
);