Commit | Line | Data |
---|---|---|
e0f018be KM |
1 | /* Copyright (c) 1979 Regents of the University of California */ |
2 | ||
d1c0bd16 | 3 | static char sccsid[] = "@(#)utilities.c 1.4 %G%"; |
e0f018be | 4 | |
9a92014d | 5 | #include "whoami.h" |
e0f018be KM |
6 | #include "vars.h" |
7 | #include "panics.h" | |
8 | #include "h02opcs.h" | |
9 | ||
10 | stats() | |
11 | { | |
12 | struct { | |
13 | long usr_time; | |
14 | long sys_time; | |
15 | long child_usr_time; | |
16 | long child_sys_time; | |
15834a19 | 17 | } tbuf; |
e0f018be KM |
18 | register double l; |
19 | register long count; | |
15834a19 KM |
20 | # ifdef PROFILE |
21 | # define proffile "/vb/grad/mckusick/px/profile/pcnt.out" | |
22 | struct cntrec { | |
23 | double counts[NUMOPS]; /* instruction counts */ | |
24 | long runs; /* number of interpreter runs */ | |
25 | long startdate; /* date profile started */ | |
26 | long usrtime; /* total user time consumed */ | |
27 | long systime; /* total system time consumed */ | |
28 | double stmts; /* number of pascal stmts executed */ | |
29 | } profdata; | |
30 | FILE *datafile; | |
31 | # endif PROFILE | |
e0f018be KM |
32 | |
33 | if (_nodump) | |
34 | return(0); | |
35 | times(&tbuf); | |
15834a19 | 36 | # ifdef PROFILE |
e0f018be | 37 | datafile = fopen(proffile,"r"); |
15834a19 KM |
38 | if (datafile == NULL) |
39 | goto skipprof; | |
40 | count = fread(&profdata,1,sizeof(profdata),datafile); | |
41 | if (count != sizeof(profdata)) | |
42 | goto skipprof; | |
43 | for (count = 0; count < NUMOPS; count++) | |
44 | profdata.counts[count] += _profcnts[count]; | |
45 | profdata.runs += 1; | |
46 | profdata.stmts += _stcnt; | |
47 | profdata.usrtime += tbuf.usr_time; | |
48 | profdata.systime += tbuf.sys_time; | |
49 | datafile = freopen(proffile,"w",datafile); | |
50 | if (datafile == NULL) | |
51 | goto skipprof; | |
52 | count = fwrite(&profdata,1,sizeof(profdata),datafile); | |
53 | if (count != sizeof(profdata)) | |
54 | goto skipprof; | |
55 | fclose(datafile); | |
56 | skipprof: | |
57 | # endif PROFILE | |
e0f018be KM |
58 | l = tbuf.usr_time; |
59 | l = l / HZ; | |
60 | fprintf(stderr, | |
61 | "\n%1ld statements executed in %04.2f seconds cpu time.\n", | |
62 | _stcnt,l); | |
63 | } | |
64 | \f | |
65 | backtrace(errnum) | |
9a92014d | 66 | int errnum; |
e0f018be KM |
67 | { |
68 | register struct disp *mydp; | |
69 | register struct stack *ap; | |
70 | register char *cp; | |
71 | register long i, linum; | |
15834a19 | 72 | struct disply disp; |
e0f018be KM |
73 | |
74 | if (_lino <= 0) { | |
75 | fputs("Program was not executed.\n",stderr); | |
76 | return; | |
77 | } | |
15834a19 | 78 | disp = _display; |
e0f018be KM |
79 | if (errnum == PINTR) |
80 | fputs("\n\tInterrupted in \"",stderr); | |
81 | else if (errnum == PHALT) | |
82 | fputs("\n\tHalted in \"",stderr); | |
83 | else | |
84 | fputs("\n\tError in \"",stderr); | |
85 | mydp = _dp; | |
86 | linum = _lino; | |
87 | for (;;) { | |
88 | ap = mydp->stp; | |
89 | i = linum - (((ap)->entry)->offset & 0177777); | |
90 | fprintf(stderr,"%s\"",(ap->entry)->name); | |
d1c0bd16 | 91 | if (_nodump == FALSE) |
9a92014d | 92 | fprintf(stderr,"+%D near line %D.",i,linum); |
e0f018be KM |
93 | fputc('\n',stderr); |
94 | *mydp = (ap)->odisp; | |
15834a19 KM |
95 | if (mydp <= &_display.frame[1]){ |
96 | _display = disp; | |
e0f018be KM |
97 | psexit(errnum); |
98 | } | |
99 | mydp = (ap)->dp; | |
100 | linum = (ap)->lino; | |
101 | fputs("\tCalled by \"",stderr); | |
102 | } | |
103 | } | |
104 | \f | |
105 | psexit(code) | |
106 | ||
9a92014d | 107 | int code; |
e0f018be KM |
108 | { |
109 | if (_pcpcount != 0) | |
110 | PMFLUSH(_cntrs, _rtns, _pcpcount); | |
111 | if (_mode == PIX) { | |
112 | fputs("Execution terminated",stderr); | |
113 | if (code) | |
114 | fputs(" abnormally",stderr); | |
115 | fputc('.',stderr); | |
116 | fputc('\n',stderr); | |
117 | } | |
118 | stats(); | |
119 | exit(code); | |
120 | } |