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