1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)vmstat.c	5.7 (Berkeley) 4/29/86";
   9: #endif not lint
  10: 
  11: /*
  12:  * Cursed vmstat -- from Robert Elz.
  13:  */
  14: 
  15: #include "systat.h"
  16: 
  17: #include <ctype.h>
  18: #include <utmp.h>
  19: 
  20: #include <sys/vm.h>
  21: #include <sys/buf.h>
  22: #include <sys/stat.h>
  23: #include <sys/dir.h>
  24: #include <sys/user.h>
  25: #include <sys/proc.h>
  26: #include <sys/namei.h>
  27: 
  28: #include <vax/pte.h>
  29: 
  30: static  int ut;
  31: 
  32: WINDOW *
  33: openkre()
  34: {
  35: 
  36:     ut = open("/etc/utmp", O_RDONLY);
  37:     if (ut < 0)
  38:         error("No utmp");
  39:         return (stdscr);
  40: }
  41: 
  42: closekre(w)
  43:         WINDOW *w;
  44: {
  45: 
  46:     (void) close(ut);
  47:         if (w == NULL)
  48:                 return;
  49:         wclear(w);
  50:         wrefresh(w);
  51: }
  52: 
  53: long    time();
  54: float   cputime();
  55: struct  utmp utmp;
  56: 
  57: static struct nlist name[] = {
  58:     { "_cp_time" },
  59: #define X_CPTIME    0
  60:     { "_rate" },
  61: #define X_RATE      1
  62:     { "_total" },
  63: #define X_TOTAL     2
  64:     { "_proc" },
  65: #define X_PROC      3
  66:     { "_nproc" },
  67: #define X_NPROC     4
  68:     { "_sum" },
  69: #define X_SUM       5
  70:     { "_dk_busy" },
  71: #define X_DK_BUSY   6
  72:     { "_dk_time" },
  73: #define X_DK_TIME   7
  74:     { "_dk_xfer" },
  75: #define X_DK_XFER   8
  76:     { "_dk_wds" },
  77: #define X_DK_WDS    9
  78:     { "_tk_nin" },
  79: #define X_TK_NIN    10
  80:     { "_tk_nout" },
  81: #define X_TK_NOUT   11
  82:     { "_dk_seek" },
  83: #define X_DK_SEEK   12
  84:     { "_nchstats" },
  85: #define X_NCHSTATS  13
  86:     { "_intrnames" },
  87: #define X_INTRNAMES 14
  88:     { "_eintrnames" },
  89: #define X_EINTRNAMES    15
  90:     { "_intrcnt" },
  91: #define X_INTRCNT   16
  92:     { "_eintrcnt" },
  93: #define X_EINTRCNT  17
  94:     { "" },
  95: };
  96: 
  97: static struct Info {
  98:     long    time[CPUSTATES];
  99:     struct  vmmeter Rate;
 100:     struct  vmtotal Total;
 101:     struct  vmmeter Sum;
 102:     struct  forkstat Forkstat;
 103:     long    *dk_time;
 104:     long    *dk_wds;
 105:     long    *dk_seek;
 106:     long    *dk_xfer;
 107:     int dk_busy;
 108:     long    tk_nin;
 109:     long    tk_nout;
 110:     struct  nchstats nchstats;
 111:     long    nchcount;
 112:     long    *intrcnt;
 113: } s, s1, s2, z;
 114: 
 115: #define total s.Total
 116: #define sum s.Sum
 117: #define sumold s1.Sum
 118: #define rate s.Rate
 119: #define nchtotal s.nchstats
 120: #define oldnchtotal s1.nchstats
 121: #define oldrate s1.Rate
 122: 
 123: static  char buf[26];
 124: static  time_t t;
 125: static  double etime;
 126: static  float hertz;
 127: static  int nintr;
 128: static  long *intrloc;
 129: static  char **intrname;
 130: static  int nextintsrow;
 131: 
 132: static  enum state { BOOT, TIME, RUN } state = TIME;
 133: 
 134: /*
 135:  * These constants define where the major pieces are laid out
 136:  */
 137: #define PROCSROW    13  /* uses 2 rows and 20 cols */
 138: #define PROCSCOL     0
 139: #define NAMEIROW    20  /* uses 3 rows and 38 cols */
 140: #define NAMEICOL     0
 141: #define GRAPHROW    16  /* uses 3 rows and 51 cols */
 142: #define GRAPHCOL     0
 143: #define GENSTATROW  14  /* uses 8 rows and 11 cols */
 144: #define GENSTATCOL  51
 145: #define INTSROW      2  /* uses all rows to bottom and 17 cols */
 146: #define INTSCOL     63
 147: #define STATROW      0  /* uses 1 row and 68 cols */
 148: #define STATCOL      2
 149: #define PAGEROW      2  /* uses 11 rows and 26 cols */
 150: #define PAGECOL     36
 151: #define MEMROW       2  /* uses 4 rows and 31 cols */
 152: #define MEMCOL       0
 153: #define DISKROW      7  /* uses 5 rows and 35 cols */
 154: #define DISKCOL      0
 155: 
 156: initkre()
 157: {
 158:     char *intrnamebuf, *cp;
 159:     int i;
 160:     static int once = 0;
 161: 
 162:     if (name[0].n_type == 0) {
 163:         nlist("/vmunix",name);
 164:         if (name[0].n_type == 0) {
 165:             error("No namelist");
 166:             return(0);
 167:         }
 168:     }
 169:     hertz = phz ? phz : hz;
 170:     if (! dkinit())
 171:         return(0);
 172:     if (dk_ndrive && !once) {
 173: #define allocate(e, t) \
 174:     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
 175:     s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
 176:     s2./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
 177:     z./**/e = (t *)calloc(dk_ndrive, sizeof (t));
 178:         allocate(dk_time, long);
 179:         allocate(dk_wds, long);
 180:         allocate(dk_seek, long);
 181:         allocate(dk_xfer, long);
 182:         once = 1;
 183: #undef allocate
 184:     }
 185:     if (nintr == 0) {
 186:         nintr = (name[X_EINTRCNT].n_value -
 187:             name[X_INTRCNT].n_value) / sizeof (long);
 188:         intrloc = (long *) calloc(nintr, sizeof (long));
 189:         intrname = (char **) calloc(nintr, sizeof (long));
 190:         intrnamebuf = malloc(name[X_EINTRNAMES].n_value -
 191:             name[X_INTRNAMES].n_value);
 192:         if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
 193:             error("Out of memory\n");
 194:             if (intrnamebuf)
 195:                 free(intrnamebuf);
 196:             if (intrname)
 197:                 free(intrname);
 198:             if (intrloc)
 199:                 free(intrloc);
 200:             nintr = 0;
 201:             return(0);
 202:         }
 203:         lseek(kmem, (long)name[X_INTRNAMES].n_value, L_SET);
 204:         read(kmem, intrnamebuf, name[X_EINTRNAMES].n_value -
 205:             name[X_INTRNAMES].n_value);
 206:         for (cp = intrnamebuf, i = 0; i < nintr; i++) {
 207:             intrname[i] = cp;
 208:             cp += strlen(cp) + 1;
 209:         }
 210:         nextintsrow = INTSROW + 2;
 211:         allocinfo(&s);
 212:         allocinfo(&s1);
 213:         allocinfo(&s2);
 214:         allocinfo(&z);
 215:     }
 216:     getinfo(&s2, RUN);
 217:     copyinfo(&s2, &s1);
 218:     return(1);
 219: }
 220: 
 221: fetchkre()
 222: {
 223:     time_t now;
 224: 
 225:     time(&now);
 226:     strcpy(buf, ctime(&now));
 227:     buf[16] = '\0';
 228:     getinfo(&s, state);
 229: }
 230: 
 231: #define MAXDRIVES   6       /* max # to display */
 232: 
 233: labelkre()
 234: {
 235:     register i, j;
 236: 
 237:     clear();
 238:     mvprintw(STATROW, STATCOL + 4, "users    Load");
 239:     mvprintw(MEMROW, MEMCOL, "Mem     REAL     VIRTUAL");
 240:     mvprintw(MEMROW + 1, MEMCOL, "      Tot Text   Tot Text");
 241:     mvprintw(MEMROW + 2, MEMCOL, "Act");
 242:     mvprintw(MEMROW + 3, MEMCOL, "All");
 243: 
 244:     mvprintw(MEMROW + 1, MEMCOL + 28, "Free");
 245: 
 246:     mvprintw(PAGEROW, PAGECOL, "        PAGING    SWAPING ");
 247:     mvprintw(PAGEROW + 1, PAGECOL, "        in  out   in  out ");
 248:     mvprintw(PAGEROW + 2, PAGECOL, "count");
 249:     mvprintw(PAGEROW + 3, PAGECOL, "pages");
 250: 
 251:     mvprintw(INTSROW, INTSCOL, " Interrupts");
 252:     mvprintw(INTSROW + 1, INTSCOL + 9, "total");
 253: 
 254:     mvprintw(GENSTATROW, GENSTATCOL + 8, "Csw");
 255:     mvprintw(GENSTATROW + 1, GENSTATCOL + 8, "Trp");
 256:     mvprintw(GENSTATROW + 2, GENSTATCOL + 8, "Sys");
 257:     mvprintw(GENSTATROW + 3, GENSTATCOL + 8, "Int");
 258:     mvprintw(GENSTATROW + 4, GENSTATCOL + 8, "Pdm");
 259:     mvprintw(GENSTATROW + 5, GENSTATCOL + 8, "Flt");
 260:     mvprintw(GENSTATROW + 6, GENSTATCOL + 8, "Scn");
 261:     mvprintw(GENSTATROW + 7, GENSTATCOL + 8, "Rev");
 262: 
 263:     mvprintw(PAGEROW + 5, PAGECOL, "Rec It F/S F/F RFL Fre SFr");
 264: 
 265:     mvprintw(PAGEROW + 8, PAGECOL + 9, " zf");
 266:     mvprintw(PAGEROW + 9, PAGECOL + 9, "nzf");
 267:     mvprintw(PAGEROW + 10, PAGECOL + 9, "%%zf");
 268:     mvprintw(PAGEROW + 8, PAGECOL + 23, " xf");
 269:     mvprintw(PAGEROW + 9, PAGECOL + 23, "nxf");
 270:     mvprintw(PAGEROW + 10, PAGECOL + 23, "%%xf");
 271: 
 272:     mvprintw(GRAPHROW, GRAPHCOL,
 273:         "    . %% Sys    . %% User    . %% Nice    . %% Idle");
 274:     mvprintw(PROCSROW, PROCSCOL, "Procs  r  p  d  s  w");
 275:     mvprintw(GRAPHROW + 1, GRAPHCOL,
 276:         "|    |    |    |    |    |    |    |    |    |    |");
 277: 
 278:     mvprintw(NAMEIROW, NAMEICOL, "Namei         Sys-cache     Proc-cache");
 279:     mvprintw(NAMEIROW + 1, NAMEICOL,
 280:         "    Calls     hits    %%     hits     %%");
 281:     mvprintw(DISKROW, DISKCOL, "Discs");
 282:     mvprintw(DISKROW + 1, DISKCOL, "seeks");
 283:     mvprintw(DISKROW + 2, DISKCOL, "xfers");
 284:     mvprintw(DISKROW + 3, DISKCOL, " blks");
 285:     mvprintw(DISKROW + 4, DISKCOL, " msps");
 286:     j = 0;
 287:     for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++)
 288:         if (dk_select[i]) {
 289:             mvprintw(DISKROW, DISKCOL + 5 + 5 * j,
 290:                 "  %3.3s", dr_name[j]);
 291:             j++;
 292:         }
 293:     for (i = 0; i < nintr; i++) {
 294:         if (intrloc[i] == 0)
 295:             continue;
 296:         mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s", intrname[i]);
 297:     }
 298: }
 299: 
 300: #define X(fld)  {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
 301: #define Y(fld)  {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
 302: #define Z(fld)  {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
 303:     if(state == TIME) s1.nchstats.fld = t;}
 304: #define MAXFAIL 5
 305: 
 306: static  char cpuchar[CPUSTATES] = { '=' , '>', '-', ' ' };
 307: static  char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_IDLE };
 308: 
 309: showkre()
 310: {
 311:     float f1, f2;
 312:     int psiz, inttotal;
 313:     int i, l, c;
 314:     static int failcnt = 0;
 315: 
 316:     for (i = 0; i < dk_ndrive; i++) {
 317:         X(dk_xfer); X(dk_seek); X(dk_wds); X(dk_time);
 318:     }
 319:     Y(tk_nin); Y(tk_nout);
 320:     etime = 0;
 321:     for(i = 0; i < CPUSTATES; i++) {
 322:         X(time);
 323:         etime += s.time[i];
 324:     }
 325:     if (etime < 5.0) {  /* < 5 ticks - ignore this trash */
 326:         if (failcnt++ >= MAXFAIL) {
 327:             clear();
 328:             mvprintw(2, 10, "The alternate system clock has died!");
 329:             mvprintw(3, 10, "Reverting to ``pigs'' display.");
 330:             move(CMDLINE, 0);
 331:             refresh();
 332:             failcnt = 0;
 333:             sleep(5);
 334:             command("pigs");
 335:         }
 336:         return;
 337:     }
 338:     failcnt = 0;
 339:     etime /= hertz;
 340:     inttotal = 0;
 341:     for (i = 0; i < nintr; i++) {
 342:         if (s.intrcnt[i] == 0)
 343:             continue;
 344:         if (intrloc[i] == 0) {
 345:             if (nextintsrow == LINES)
 346:                 continue;
 347:             intrloc[i] = nextintsrow++;
 348:             mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s",
 349:                 intrname[i]);
 350:         }
 351:         X(intrcnt);
 352:         l = (int)((float)s.intrcnt[i]/etime + 0.5);
 353:         inttotal += l;
 354:         putint(l, intrloc[i], INTSCOL, 8);
 355:     }
 356:     putint(inttotal, INTSROW + 1, INTSCOL, 8);
 357:     Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss);
 358:     Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes);
 359:     s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits +
 360:         nchtotal.ncs_miss + nchtotal.ncs_long;
 361:     if (state == TIME)
 362:         s1.nchcount = s.nchcount;
 363: 
 364:     psiz = 0;
 365:     f2 = 0.0;
 366:     for (c = 0; c < CPUSTATES; c++) {
 367:         i = cpuorder[c];
 368:         f1 = cputime(i);
 369:         f2 += f1;
 370:         l = (int) ((f2 + 1.0) / 2.0) - psiz;
 371:         if (c == 0)
 372:             putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0);
 373:         else
 374:             putfloat(f1, GRAPHROW, GRAPHCOL + 12 * c,
 375:                 5, 1, 0);
 376:         move(GRAPHROW + 2, psiz);
 377:         psiz += l;
 378:         while (l-- > 0)
 379:             addch(cpuchar[c]);
 380:     }
 381: 
 382:     putint(ucount(), STATROW, STATCOL, 3);
 383:     putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0);
 384:     putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
 385:     putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
 386:     mvaddstr(STATROW, STATCOL + 53, buf);
 387:     putint(total.t_arm/2, MEMROW + 2, MEMCOL + 4, 5);
 388:     putint(total.t_armtxt/2, MEMROW + 2, MEMCOL + 9, 5);
 389:     putint(total.t_avm/2, MEMROW + 2, MEMCOL + 14, 6);
 390:     putint(total.t_avmtxt/2, MEMROW + 2, MEMCOL + 20, 5);
 391:     putint(total.t_rm/2, MEMROW + 3, MEMCOL + 4, 5);
 392:     putint(total.t_rmtxt/2, MEMROW + 3, MEMCOL + 9, 5);
 393:     putint(total.t_vm/2, MEMROW + 3, MEMCOL + 14, 6);
 394:     putint(total.t_vmtxt/2, MEMROW + 3, MEMCOL + 20, 5);
 395:     putint(total.t_free/2, MEMROW + 2, MEMCOL + 27, 5);
 396:     putint(total.t_rq, PROCSROW + 1, PROCSCOL + 5, 3);
 397:     putint(total.t_pw, PROCSROW + 1, PROCSCOL + 8, 3);
 398:     putint(total.t_dw, PROCSROW + 1, PROCSCOL + 11, 3);
 399:     putint(total.t_sl, PROCSROW + 1, PROCSCOL + 14, 3);
 400:     putint(total.t_sw, PROCSROW + 1, PROCSCOL + 17, 3);
 401:     putrate(rate.v_swtch, oldrate.v_swtch,
 402:         GENSTATROW, GENSTATCOL, 7);
 403:     putrate(rate.v_trap, oldrate.v_trap,
 404:         GENSTATROW + 1, GENSTATCOL, 7);
 405:     putrate(rate.v_syscall, oldrate.v_syscall,
 406:         GENSTATROW + 2, GENSTATCOL, 7);
 407:     putrate(rate.v_intr, oldrate.v_intr,
 408:         GENSTATROW + 3, GENSTATCOL, 7);
 409:     putrate(rate.v_pdma, oldrate.v_pdma,
 410:         GENSTATROW + 4, GENSTATCOL, 7);
 411:     putrate(rate.v_faults, oldrate.v_faults,
 412:         GENSTATROW + 5, GENSTATCOL, 7);
 413:     putrate(rate.v_scan, oldrate.v_scan,
 414:         GENSTATROW + 6, GENSTATCOL, 7);
 415:     putrate(rate.v_rev, oldrate.v_rev,
 416:         GENSTATROW + 7, GENSTATCOL, 7);
 417:     putrate(rate.v_pgin, oldrate.v_pgin, PAGEROW + 2,
 418:         PAGECOL + 5, 5);
 419:     putrate(rate.v_pgout, oldrate.v_pgout, PAGEROW + 2,
 420:         PAGECOL + 10, 5);
 421:     putrate(rate.v_swpin, oldrate.v_swpin, PAGEROW + 2,
 422:         PAGECOL + 15, 5);
 423:     putrate(rate.v_swpout, oldrate.v_swpout, PAGEROW + 2,
 424:         PAGECOL + 20, 5);
 425:     putrate(rate.v_pgpgin, oldrate.v_pgpgin, PAGEROW + 3,
 426:         PAGECOL + 5, 5);
 427:     putrate(rate.v_pgpgout, oldrate.v_pgpgout, PAGEROW + 3,
 428:         PAGECOL + 10, 5);
 429:     putrate(rate.v_pswpin, oldrate.v_pswpin, PAGEROW + 3,
 430:         PAGECOL + 15, 5);
 431:     putrate(rate.v_pswpout, oldrate.v_pswpout, PAGEROW + 3,
 432:         PAGECOL + 20, 5);
 433:     putrate(rate.v_pgrec, oldrate.v_pgrec, PAGEROW + 6, PAGECOL, 3);
 434:     putrate(rate.v_intrans, oldrate.v_intrans, PAGEROW + 6,
 435:         PAGECOL + 4, 2);
 436:     putrate(rate.v_xsfrec, oldrate.v_xsfrec, PAGEROW + 6,
 437:         PAGECOL + 7, 3);
 438:     putrate(rate.v_xifrec, oldrate.v_xifrec, PAGEROW + 6,
 439:         PAGECOL + 11, 3);
 440:     putrate(rate.v_pgfrec, oldrate.v_pgfrec, PAGEROW + 6,
 441:         PAGECOL + 15, 3);
 442:     putrate(rate.v_dfree, oldrate.v_dfree, PAGEROW + 6,
 443:         PAGECOL + 19, 3);
 444:     putrate(rate.v_seqfree, oldrate.v_seqfree, PAGEROW + 6,
 445:         PAGECOL + 23, 3);
 446:     putrate(rate.v_zfod, oldrate.v_zfod, PAGEROW + 8, PAGECOL, 8);
 447:     putrate(rate.v_nzfod, oldrate.v_nzfod, PAGEROW + 9, PAGECOL, 8);
 448:     putrate(rate.v_exfod, oldrate.v_exfod, PAGEROW + 8,
 449:         PAGECOL + 14, 8);
 450:     putrate(rate.v_nexfod, oldrate.v_nexfod, PAGEROW + 9,
 451:         PAGECOL + 14, 8);
 452:     putfloat (
 453:         rate.v_nzfod == 0 ?
 454:             0.0
 455:         : state != RUN ?
 456:             ( 100.0 * rate.v_zfod / rate.v_nzfod )
 457:         : rate.v_nzfod == oldrate.v_nzfod ?
 458:             0.0
 459:         :
 460:             ( 100.0 * (rate.v_zfod-oldrate.v_zfod)
 461:             / (rate.v_nzfod-oldrate.v_nzfod) )
 462:         , PAGEROW + 10
 463:         , PAGECOL
 464:         , 8
 465:         , 2
 466:         , 1
 467:     );
 468:     putfloat (
 469:         rate.v_nexfod == 0 ?
 470:             0.0
 471:         : state != RUN ?
 472:             ( 100.0 * rate.v_exfod / rate.v_nexfod )
 473:         : rate.v_nexfod == oldrate.v_nexfod ?
 474:             0.0
 475:         :
 476:             ( 100.0 * (rate.v_exfod-oldrate.v_exfod)
 477:             / (rate.v_nexfod-oldrate.v_nexfod) )
 478:         , PAGEROW + 10
 479:         , PAGECOL + 14
 480:         , 8
 481:         , 2
 482:         , 1
 483:     );
 484:     c = 0;
 485:     for (i = 0; i < dk_ndrive && c < MAXDRIVES; i++)
 486:         if (dk_select[i])
 487:             dinfo(i, ++c);
 488: 
 489:     putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);
 490:     putint(nchtotal.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 9, 9);
 491: #define nz(x)   ((x) ? (x) : 1)
 492:     putfloat(nchtotal.ncs_goodhits * 100.0 / nz(s.nchcount),
 493:        NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);
 494:     putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9);
 495:     putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount),
 496:        NAMEIROW + 2, NAMEICOL + 34, 4, 0, 1);
 497: #undef nz
 498: }
 499: 
 500: cmdkre(cmd, args)
 501:     char *cmd, *args;
 502: {
 503: 
 504:     if (prefix(cmd, "run")) {
 505:         copyinfo(&s2, &s1);
 506:         state = RUN;
 507:         return (1);
 508:     }
 509:     if (prefix(cmd, "boot")) {
 510:         state = BOOT;
 511:         copyinfo(&z, &s1);
 512:         return (1);
 513:     }
 514:     if (prefix(cmd, "time")) {
 515:         state = TIME;
 516:         return (1);
 517:     }
 518:     if (prefix(cmd, "zero")) {
 519:         if (state == RUN)
 520:             getinfo(&s1, RUN);
 521:         return (1);
 522:     }
 523:     return (dkcmd(cmd, args));
 524: }
 525: 
 526: /* calculate number of users on the system */
 527: static
 528: ucount()
 529: {
 530:     register int nusers = 0;
 531: 
 532:     if (ut < 0)
 533:         return (0);
 534:     while (read(ut, &utmp, sizeof(utmp)))
 535:         if (utmp.ut_name[0] != '\0')
 536:             nusers++;
 537: 
 538:     lseek(ut, 0L, L_SET);
 539:     return (nusers);
 540: }
 541: 
 542: static float
 543: cputime(indx)
 544:     int indx;
 545: {
 546:     double t;
 547:     register i;
 548: 
 549:     t = 0;
 550:     for (i = 0; i < CPUSTATES; i++)
 551:         t += s.time[i];
 552:     if (t == 0.0)
 553:         t = 1.0;
 554:     return (s.time[indx] * 100.0 / t);
 555: }
 556: 
 557: static
 558: putrate(r, or, l, c, w)
 559: {
 560: 
 561:     if (state != TIME) {
 562:         if (state == RUN)
 563:             r -= or;
 564:         putint((int)((float)r/etime + 0.5), l, c, w);
 565:     } else
 566:         putint(r, l, c, w);
 567: }
 568: 
 569: static
 570: putint(n, l, c, w)
 571: {
 572:     char b[128];
 573: 
 574:     move(l, c);
 575:     if (n == 0) {
 576:         while (w-- > 0)
 577:             addch(' ');
 578:         return;
 579:     }
 580:     sprintf(b, "%*d", w, n);
 581:     if (strlen(b) > w) {
 582:         while (w-- > 0)
 583:             addch('*');
 584:         return;
 585:     }
 586:     addstr(b);
 587: }
 588: 
 589: static
 590: putfloat(f, l, c, w, d, nz)
 591:     float f;
 592: {
 593:     char b[128];
 594: 
 595:     move(l, c);
 596:     if (nz && f == 0.0) {
 597:         while (w-- > 0)
 598:             addch(' ');
 599:         return;
 600:     }
 601:     sprintf(b, "%*.*f", w, d, f);
 602:     if (strlen(b) > w) {
 603:         while (w-- > 0)
 604:             addch('*');
 605:         return;
 606:     }
 607:     addstr(b);
 608: }
 609: 
 610: static
 611: getinfo(s, st)
 612:     struct Info *s;
 613:     enum state st;
 614: {
 615: 
 616:     lseek(kmem, (long)name[X_CPTIME].n_value,L_SET);
 617:     read(kmem, s->time, sizeof s->time);
 618:     if (st != TIME) {
 619:         lseek(kmem, (long)name[X_SUM].n_value, L_SET);
 620:         read(kmem, &s->Rate, sizeof s->Rate);
 621:     } else {
 622:         lseek(kmem, (long)name[X_RATE].n_value,L_SET);
 623:         read(kmem, &s->Rate, sizeof s->Rate);
 624:     }
 625:     lseek(kmem, (long)name[X_TOTAL].n_value, L_SET);
 626:     read(kmem, &s->Total, sizeof s->Total);
 627:     s->dk_busy = getw(name[X_DK_BUSY].n_value);
 628:     lseek(kmem, (long)name[X_DK_TIME].n_value,  L_SET);
 629:     read(kmem, s->dk_time, dk_ndrive * sizeof (long));
 630:     lseek(kmem, (long)name[X_DK_XFER].n_value,  L_SET);
 631:     read(kmem, s->dk_xfer, dk_ndrive * sizeof (long));
 632:     lseek(kmem, (long)name[X_DK_WDS].n_value,  L_SET);
 633:     read(kmem, s->dk_wds, dk_ndrive * sizeof (long));
 634:     lseek(kmem, (long)name[X_DK_SEEK].n_value,  L_SET);
 635:     read(kmem, s->dk_seek, dk_ndrive * sizeof (long));
 636:     s->tk_nin = getw(name[X_TK_NIN].n_value);
 637:     s->tk_nout = getw(name[X_TK_NOUT].n_value);
 638:     lseek(kmem, (long)name[X_NCHSTATS].n_value,  L_SET);
 639:     read(kmem, &s->nchstats, sizeof s->nchstats);
 640:     lseek(kmem, (long)name[X_INTRCNT].n_value,  L_SET);
 641:     read(kmem, s->intrcnt, nintr * sizeof (long));
 642: }
 643: 
 644: static
 645: allocinfo(s)
 646:     struct Info *s;
 647: {
 648: 
 649:     s->intrcnt = (long *) malloc(nintr * sizeof(long));
 650:     if (s->intrcnt == NULL) {
 651:         fprintf(stderr, "systat: out of memory\n");
 652:         exit(2);
 653:     }
 654: }
 655: 
 656: static
 657: copyinfo(from, to)
 658:     register struct Info *from, *to;
 659: {
 660:     long *time, *wds, *seek, *xfer;
 661:     long *intrcnt;
 662: 
 663:     time = to->dk_time; wds = to->dk_wds; seek = to->dk_seek;
 664:     xfer = to->dk_xfer; intrcnt = to->intrcnt;
 665:     *to = *from;
 666:     bcopy(from->dk_time, to->dk_time = time, dk_ndrive * sizeof (long));
 667:     bcopy(from->dk_wds, to->dk_wds = wds, dk_ndrive * sizeof (long));
 668:     bcopy(from->dk_seek, to->dk_seek = seek, dk_ndrive * sizeof (long));
 669:     bcopy(from->dk_xfer, to->dk_xfer = xfer, dk_ndrive * sizeof (long));
 670:     bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
 671: }
 672: 
 673: static
 674: dinfo(dn, c)
 675: {
 676:     double words, atime, itime, xtime;
 677: 
 678:     c = DISKCOL + c * 5;
 679:     atime = s.dk_time[dn];
 680:     atime /= hertz;
 681:     words = s.dk_wds[dn]*32.0;  /* number of words transferred */
 682:     xtime = dk_mspw[dn]*words;  /* transfer time */
 683:     itime = atime - xtime;      /* time not transferring */
 684:     if (xtime < 0)
 685:         itime += xtime, xtime = 0;
 686:     if (itime < 0)
 687:         xtime += itime, itime = 0;
 688:     putint((int)((float)s.dk_seek[dn]/etime+0.5), DISKROW + 1, c, 5);
 689:     putint((int)((float)s.dk_xfer[dn]/etime+0.5), DISKROW + 2, c, 5);
 690:     putint((int)(words/etime/512.0 + 0.5), DISKROW + 3, c, 5);
 691:     if (s.dk_seek[dn])
 692:         putfloat(itime*1000.0/s.dk_seek[dn], DISKROW + 4, c, 5, 1, 1);
 693:     else
 694:         putint(0, DISKROW + 4, c, 5);
 695: }

Defined functions

allocinfo defined in line 644; used 4 times
closekre defined in line 42; used 2 times
cmdkre defined in line 500; used 2 times
copyinfo defined in line 656; used 3 times
cputime defined in line 542; used 2 times
dinfo defined in line 673; used 1 times
fetchkre defined in line 221; used 2 times
getinfo defined in line 610; used 3 times
initkre defined in line 156; used 2 times
labelkre defined in line 233; used 2 times
openkre defined in line 32; used 2 times
putfloat defined in line 589; used 10 times
putint defined in line 569; used 26 times
putrate defined in line 557; used 27 times
showkre defined in line 309; used 2 times
ucount defined in line 527; used 1 times

Defined variables

buf defined in line 123; used 3 times
cpuchar defined in line 306; used 1 times
cpuorder defined in line 307; used 1 times
etime defined in line 125; used 9 times
hertz defined in line 126; used 3 times
intrloc defined in line 128; used 10 times
intrname defined in line 129; used 7 times
name defined in line 57; used 23 times
nextintsrow defined in line 130; used 3 times
nintr defined in line 127; used 11 times
s defined in line 113; used 53 times
s1 defined in line 113; used 16 times
s2 defined in line 113; used 5 times
sccsid defined in line 8; never used
state defined in line 132; used 13 times
t defined in line 124; used 21 times
ut defined in line 30; used 6 times
utmp defined in line 55; used 3 times
z defined in line 113; used 3 times

Defined struct's

Info defined in line 97; used 6 times

Defined enum's

state defined in line 132; used 2 times
  • in line 613(2)

Defined macros

DISKCOL defined in line 154; used 7 times
DISKROW defined in line 153; used 11 times
GENSTATCOL defined in line 144; used 16 times
GENSTATROW defined in line 143; used 16 times
GRAPHCOL defined in line 142; used 4 times
GRAPHROW defined in line 141; used 5 times
INTSCOL defined in line 146; used 6 times
INTSROW defined in line 145; used 4 times
MAXDRIVES defined in line 231; used 2 times
MAXFAIL defined in line 304; used 1 times
MEMCOL defined in line 152; used 14 times
MEMROW defined in line 151; used 14 times
NAMEICOL defined in line 140; used 7 times
NAMEIROW defined in line 139; used 7 times
PAGECOL defined in line 150; used 32 times
PAGEROW defined in line 149; used 32 times
PROCSCOL defined in line 138; used 6 times
PROCSROW defined in line 137; used 6 times
STATCOL defined in line 148; used 6 times
STATROW defined in line 147; used 6 times
X defined in line 300; used 6 times
X_CPTIME defined in line 59; used 1 times
X_DK_BUSY defined in line 71; used 1 times
X_DK_SEEK defined in line 83; used 1 times
X_DK_TIME defined in line 73; used 1 times
X_DK_WDS defined in line 77; used 1 times
X_DK_XFER defined in line 75; used 1 times
X_EINTRCNT defined in line 93; used 1 times
X_EINTRNAMES defined in line 89; used 2 times
X_INTRCNT defined in line 91; used 2 times
X_INTRNAMES defined in line 87; used 3 times
X_NCHSTATS defined in line 85; used 1 times
X_NPROC defined in line 67; never used
X_PROC defined in line 65; never used
X_RATE defined in line 61; used 1 times
X_SUM defined in line 69; used 1 times
X_TK_NIN defined in line 79; used 1 times
X_TK_NOUT defined in line 81; used 1 times
X_TOTAL defined in line 63; used 1 times
Y defined in line 301; used 2 times
  • in line 319(2)
Z defined in line 302; used 6 times
allocate defined in line 173; used 5 times
nchtotal defined in line 119; used 8 times
nz defined in line 491; used 5 times
oldnchtotal defined in line 120; never used
oldrate defined in line 121; used 33 times
rate defined in line 118; used 39 times
sum defined in line 116; never used
sumold defined in line 117; never used
total defined in line 115; used 14 times
Last modified: 1986-04-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 6488
Valid CSS Valid XHTML 1.0 Strict