1 /* Copyright (c) 1979 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)utilities.c 1.3 03/06/81"; 4 5 #include "whoami.h" 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; 17 } tbuf; 18 register double l; 19 register long count; 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 32 33 if (_nodump) 34 return(0); 35 times(&tbuf); 36 # ifdef PROFILE 37 datafile = fopen(proffile,"r"); 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 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 65 backtrace(errnum) 66 int errnum; 67 { 68 register struct disp *mydp; 69 register struct stack *ap; 70 register char *cp; 71 register long i, linum; 72 struct disply disp; 73 74 if (_lino <= 0) { 75 fputs("Program was not executed.\n",stderr); 76 return; 77 } 78 disp = _display; 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); 91 if (_nodump == 0) 92 fprintf(stderr,"+%D near line %D.",i,linum); 93 fputc('\n',stderr); 94 *mydp = (ap)->odisp; 95 if (mydp <= &_display.frame[1]){ 96 _display = disp; 97 psexit(errnum); 98 } 99 mydp = (ap)->dp; 100 linum = (ap)->lino; 101 fputs("\tCalled by \"",stderr); 102 } 103 } 104 105 psexit(code) 106 107 int code; 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 } 121