BSD 4 development
[unix-history] / .ref-BSD-3 / usr / src / cmd / px / stats.c
CommitLineData
d442e603
CH
1#include "stdio.h"
2#include "h00vars.h"
3#include "h01errs.h"
4#define HZ 60 /* interrupt frequency */
5
6backtrace(errnum)
7long errnum;
8{
9register struct stack **mydp, *ap;
10 struct stack **dp, *disp[20];
11register char *cp;
12register long i;
13 long linum;
14
15fetchdp(&dp,&linum);
16for (i=0; i<20; i++)
17 disp[i] = display[i];
18if (errnum == EINTR)
19 fputs("\n\tInterrupted at \"",stderr);
20else if (errnum == EHALT)
21 fputs("\n\tHalted at \"",stderr);
22else
23 fputs("\n\tError at \"",stderr);
24if (linum <= 0)
25 return;
26mydp = dp;
27for (;;){
28 ap = *mydp;
29 cp = &((ap)->entry)->name[0];
30 i = 8;
31 do
32 putc(*cp++,stderr);
33 while (--i && *cp != ' ');
34 i = linum - (((ap)->entry)->offset & 0177777);
35 fprintf(stderr,"\"+%1d near line %1d.\n",i,linum);
36 *mydp = (ap)->disp;
37 if (mydp <= &display[addrsze >> 2]){
38 for (i=0; i<20; i++)
39 display[i] = disp[i];
40 return;
41 }
42 mydp = (ap)->dp;
43 linum = (ap)->lino;
44 fputs("\tCalled by \"",stderr);
45 }
46}
47\f
48stats()
49{
50struct {
51 long usr_time;
52 long sys_time;
53 long child_usr_time;
54 long child_sys_time;
55 } tbuf;
56register double l;
57register long count;
58
59if (nodump)
60 return(0);
61times(&tbuf);
62#ifdef profile
63datafile = fopen(proffile,"r");
64if (datafile != NULL) {
65 count = fread(&profdata,sizeof(profdata),1,datafile);
66 if (count != 1) {
67 for (count = 0; count < numops; count++)
68 profdata.counts[count] = 0.0;
69 profdata.runs = 0;
70 profdata.startdate = time(0);
71 profdata.usrtime = 0;
72 profdata.systime = 0;
73 profdata.stmts = 0;
74 }
75 for (count = 0; count < numops; count++)
76 profdata.counts[count] += profcnts[count];
77 profdata.runs += 1;
78 profdata.stmts += stcnt;
79 profdata.usrtime += tbuf.usr_time;
80 profdata.systime += tbuf.sys_time;
81 datafile = freopen(proffile,"w",datafile);
82 if (datafile != NULL) {
83 fwrite(&profdata,sizeof(profdata),1,datafile);
84 fclose(datafile);
85 }
86 }
87#endif
88l = tbuf.usr_time;
89l = l / HZ;
90fprintf(stderr,"\n%1ld statements executed in %04.2f seconds cpu time.\n",
91 stcnt,l);
92}