|
|
1.1 root 1: /* Copyright (c) 1979 Regents of the University of California */
2:
3: static char sccsid[] = "@(#)stats.c 4.1 10/10/80";
4:
5: #include "stdio.h"
6: #include "h00vars.h"
7: #include "h01errs.h"
8: #define HZ 60 /* interrupt frequency */
9:
10: backtrace(errnum)
11: long errnum;
12: {
13: register struct stack **mydp, *ap;
14: struct stack **dp, *disp[20];
15: register char *cp;
16: register long i;
17: long linum;
18:
19: fetchdp(&dp,&linum);
20: for (i=0; i<20; i++)
21: disp[i] = display[i];
22: if (errnum == EINTR)
23: fputs("\n\tInterrupted in \"",stderr);
24: else if (errnum == EHALT)
25: fputs("\n\tHalted in \"",stderr);
26: else
27: fputs("\n\tError in \"",stderr);
28: if (linum <= 0)
29: return;
30: mydp = dp;
31: for (;;){
32: ap = *mydp;
33: i = linum - (((ap)->entry)->offset & 0177777);
34: fprintf(stderr,"%s\"",(ap->entry)->name);
35: if (nodump == 0)
36: fprintf(stderr,"+%1d near line %1d.",i,linum);
37: fputc('\n',stderr);
38: *mydp = (ap)->disp;
39: if (mydp <= &display[1]){
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:
50: stats()
51: {
52: struct {
53: long usr_time;
54: long sys_time;
55: long child_usr_time;
56: long child_sys_time;
57: } tbuf;
58: register double l;
59: register long count;
60:
61: if (nodump)
62: return(0);
63: times(&tbuf);
64: #ifdef profile
65: datafile = fopen(proffile,"r");
66: if (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
90: l = tbuf.usr_time;
91: l = l / HZ;
92: fprintf(stderr,"\n%1ld statements executed in %04.2f seconds cpu time.\n",
93: stcnt,l);
94: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.