1: static  char *sccsid = "@(#)sh.time.c 4.1 10/9/80";
   2: 
   3: #include "sh.h"
   4: 
   5: /*
   6:  * C Shell - routines handling process timing and niceing
   7:  */
   8: #ifdef VMUNIX
   9: struct  vtimes vm0;
  10: #else
  11: struct  tms times0;
  12: struct  tms timesdol;
  13: #endif
  14: 
  15: settimes()
  16: {
  17: 
  18:     time(&time0);
  19: #ifdef VMUNIX
  20:     vtimes(&vm0, 0);
  21: #else
  22:     times(&times0);
  23: #endif
  24: }
  25: 
  26: /*
  27:  * dotime is only called if it is truly a builtin function and not a
  28:  * prefix to another command
  29:  */
  30: dotime()
  31: {
  32:     time_t timedol;
  33: #ifdef VMUNIX
  34:     struct vtimes vm1, vmch;
  35: 
  36:     vtimes(&vm1, &vmch);
  37:     vmsadd(&vm1, &vmch);
  38: #else
  39:     time_t utime, stime;
  40: #endif
  41: 
  42:     time(&timedol);
  43: #ifdef VMUNIX
  44:     pvtimes(&vm0, &vm1, timedol - time0);
  45: #else
  46:     times(&timesdol);
  47:     utime = (timesdol.tms_utime + timesdol.tms_cutime) -
  48:         (times0.tms_utime + times0.tms_cutime);
  49:     stime = (timesdol.tms_stime + timesdol.tms_cstime) -
  50:         (times0.tms_stime + times0.tms_cstime);
  51:     ptimes(utime, stime, timedol - time0);
  52: #endif
  53: }
  54: 
  55: /*
  56:  * donice is only called when it on the line by itself or with a +- value
  57:  */
  58: donice(v)
  59:     register char **v;
  60: {
  61:     register char *cp;
  62: 
  63:     v++, cp = *v++;
  64:     if (cp == 0) {
  65: #ifndef V6
  66:         nice(20);
  67:         nice(-10);
  68: #endif
  69:         nice(4);
  70:     } else if (*v == 0 && any(cp[0], "+-")) {
  71: #ifndef V6
  72:         nice(20);
  73:         nice(-10);
  74: #endif
  75:         nice(getn(cp));
  76:     }
  77: }
  78: 
  79: #ifndef VMUNIX
  80: ptimes(utime, stime, etime)
  81:     register time_t utime, stime, etime;
  82: {
  83: 
  84:     p60ths(utime);
  85:     printf("u ");
  86:     p60ths(stime);
  87:     printf("s ");
  88:     psecs(etime);
  89:     printf(" %d%%\n", (int) (100 * (utime+stime) /
  90:         (60 * (etime ? etime : 1))));
  91: }
  92: 
  93: #else
  94: vmsadd(vp, wp)
  95:     register struct vtimes *vp, *wp;
  96: {
  97: 
  98:     vp->vm_utime += wp->vm_utime;
  99:     vp->vm_stime += wp->vm_stime;
 100:     vp->vm_nswap += wp->vm_nswap;
 101:     vp->vm_idsrss += wp->vm_idsrss;
 102:     vp->vm_ixrss += wp->vm_ixrss;
 103:     if (vp->vm_maxrss < wp->vm_maxrss)
 104:         vp->vm_maxrss = wp->vm_maxrss;
 105:     vp->vm_majflt += wp->vm_majflt;
 106:     vp->vm_minflt += wp->vm_minflt;
 107:     vp->vm_inblk += wp->vm_inblk;
 108:     vp->vm_oublk += wp->vm_oublk;
 109: }
 110: 
 111: pvtimes(v0, v1, sec)
 112:     register struct vtimes *v0, *v1;
 113:     time_t sec;
 114: {
 115:     register time_t t =
 116:         (v1->vm_utime-v0->vm_utime)+(v1->vm_stime-v0->vm_stime);
 117:     register char *cp;
 118:     register int i;
 119:     register struct varent *vp = adrof("time");
 120: 
 121:     cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
 122:     if (vp && vp->vec[0] && vp->vec[1])
 123:         cp = vp->vec[1];
 124:     for (; *cp; cp++)
 125:     if (*cp != '%')
 126:         putchar(*cp);
 127:     else if (cp[1]) switch(*++cp) {
 128: 
 129:     case 'U':
 130:         p60ths(v1->vm_utime - v0->vm_utime);
 131:         break;
 132: 
 133:     case 'S':
 134:         p60ths(v1->vm_stime - v0->vm_stime);
 135:         break;
 136: 
 137:     case 'E':
 138:         psecs(sec);
 139:         break;
 140: 
 141:     case 'P':
 142:         printf("%d%%", (int) ((100 * t) / (60 * (sec ? sec : 1))));
 143:         break;
 144: 
 145:     case 'W':
 146:         i = v1->vm_nswap - v0->vm_nswap;
 147:         printf("%d", i);
 148:         break;
 149: 
 150:     case 'X':
 151:         printf("%d", t == 0 ? 0 : (v1->vm_ixrss-v0->vm_ixrss)/(2*t));
 152:         break;
 153: 
 154:     case 'D':
 155:         printf("%d", t == 0 ? 0 : (v1->vm_idsrss-v0->vm_idsrss)/(2*t));
 156:         break;
 157: 
 158:     case 'K':
 159:         printf("%d", t == 0 ? 0 : ((v1->vm_ixrss+v1->vm_idsrss) -
 160:            (v0->vm_ixrss+v0->vm_idsrss))/(2*t));
 161:         break;
 162: 
 163:     case 'M':
 164:         printf("%d", v1->vm_maxrss/2);
 165:         break;
 166: 
 167:     case 'F':
 168:         printf("%d", v1->vm_majflt-v0->vm_majflt);
 169:         break;
 170: 
 171:     case 'R':
 172:         printf("%d", v1->vm_minflt-v0->vm_minflt);
 173:         break;
 174: 
 175:     case 'I':
 176:         printf("%d", v1->vm_inblk-v0->vm_inblk);
 177:         break;
 178: 
 179:     case 'O':
 180:         printf("%d", v1->vm_oublk-v0->vm_oublk);
 181:         break;
 182: 
 183:     }
 184:     putchar('\n');
 185: }
 186: #endif

Defined functions

donice defined in line 58; used 2 times
dotime defined in line 30; used 2 times
ptimes defined in line 80; used 3 times
pvtimes defined in line 111; used 3 times
settimes defined in line 15; used 2 times
vmsadd defined in line 94; used 2 times

Defined variables

sccsid defined in line 1; never used
times0 defined in line 11; used 5 times
timesdol defined in line 12; used 5 times
vm0 defined in line 9; used 2 times
Last modified: 1982-10-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 828
Valid CSS Valid XHTML 1.0 Strict