[BACK]Return to vmstat.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / systat

Diff for /src/usr.bin/systat/vmstat.c between version 1.30 and 1.31

version 1.30, 2001/12/07 07:57:36 version 1.31, 2001/12/07 09:18:08
Line 88 
Line 88 
 #include "dkstats.h"  #include "dkstats.h"
 extern struct _disk     cur;  extern struct _disk     cur;
   
   
 #define cnt s.Cnt  #define cnt s.Cnt
 #define oldcnt s1.Cnt  #define oldcnt s1.Cnt
 #define total s.Total  #define total s.Total
Line 118 
Line 117 
   
 struct  utmp utmp;  struct  utmp utmp;
   
   
 WINDOW *  WINDOW *
 openkre()  openkre()
 {  {
Line 143 
Line 141 
   
   
 static struct nlist namelist[] = {  static struct nlist namelist[] = {
 #define X_CPTIME        0  #define X_HZ            0
         { "_cp_time" },          { "_hz" },
 #define X_UVMEXP        1  #define X_INTRNAMES     1
         { "_uvmexp" },  
 #define X_NCHSTATS      2  
         { "_nchstats" },  
 #define X_INTRNAMES     3  
         { "_intrnames" },          { "_intrnames" },
 #define X_EINTRNAMES    4  #define X_EINTRNAMES    2
         { "_eintrnames" },          { "_eintrnames" },
 #define X_INTRCNT       5  #define X_INTRCNT       3
         { "_intrcnt" },          { "_intrcnt" },
 #define X_EINTRCNT      6  #define X_EINTRCNT      4
         { "_eintrcnt" },          { "_eintrcnt" },
 #if defined(__i386__)  #if defined(__i386__)
 #define X_INTRHAND      7  #define X_INTRHAND      5
         { "_intrhand" },          { "_intrhand" },
 #endif  #endif
         { "" },          { "" },
Line 201 
Line 195 
 {  {
         char *intrnamebuf, *cp;          char *intrnamebuf, *cp;
         int i, ret;          int i, ret;
         static int once = 0;  
   
         if (namelist[0].n_type == 0) {          if (namelist[0].n_type == 0) {
                 if ((ret = kvm_nlist(kd, namelist)) == -1)                  if ((ret = kvm_nlist(kd, namelist)) == -1)
Line 214 
Line 207 
                 }                  }
         }          }
         hertz = stathz ? stathz : hz;          hertz = stathz ? stathz : hz;
         if (! dkinit(1))          if (!dkinit(1))
                 return(0);                  return(0);
         if (dk_ndrive && !once) {  
 #define allocate(e, t) \  
     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \  
     s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \  
     s2./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \  
     z./**/e = (t *)calloc(dk_ndrive, sizeof (t));  
                 once = 1;  
 #undef allocate  
         }  
         if (nintr == 0) {          if (nintr == 0) {
 #if defined(__i386__)  #if defined(__i386__)
                 struct intrhand *intrhand[16], *ihp, ih;                  struct intrhand *intrhand[16], *ihp, ih;
Line 250 
Line 234 
                         while (ihp) {                          while (ihp) {
                                 KREAD(ihp, &ih, sizeof(ih));                                  KREAD(ihp, &ih, sizeof(ih));
                                 KREAD(ih.ih_what, iname, 16);                                  KREAD(ih.ih_what, iname, 16);
                                 /* XXX strcpy is safe, sized & malloc'd buffer */                                  /* XXX strcpy is safe, sized & malloc'd buffer */
                                 strcpy(intrname[n++] = intrnamebuf + namelen, iname);                                  strcpy(intrname[n++] = intrnamebuf + namelen, iname);
                                 namelen += 1 + strlen(iname);                                  namelen += 1 + strlen(iname);
                                 ihp = ih.ih_next;                                  ihp = ih.ih_next;
Line 258 
Line 242 
                 }                  }
 #else  #else
                 nintr = (namelist[X_EINTRCNT].n_value -                  nintr = (namelist[X_EINTRCNT].n_value -
                         namelist[X_INTRCNT].n_value) / sizeof (long);                      namelist[X_INTRCNT].n_value) / sizeof (long);
                 intrloc = calloc(nintr, sizeof (long));                  intrloc = calloc(nintr, sizeof (long));
                 intrname = calloc(nintr, sizeof (long));                  intrname = calloc(nintr, sizeof (long));
                 intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -                  intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -
                         namelist[X_INTRNAMES].n_value);                      namelist[X_INTRNAMES].n_value);
                 if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {                  if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
                         error("Out of memory\n");                          error("Out of memory\n");
                         if (intrnamebuf)                          if (intrnamebuf)
Line 275 
Line 259 
                         return(0);                          return(0);
                 }                  }
                 NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -                  NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -
                         NVAL(X_INTRNAMES));                      NVAL(X_INTRNAMES));
                 for (cp = intrnamebuf, i = 0; i < nintr; i++) {                  for (cp = intrnamebuf, i = 0; i < nintr; i++) {
                         intrname[i] = cp;                          intrname[i] = cp;
                         cp += strlen(cp) + 1;                          cp += strlen(cp) + 1;
Line 344 
Line 328 
         mvprintw(GENSTATROW, GENSTATCOL, "   Csw   Trp   Sys   Int   Sof  Flt");          mvprintw(GENSTATROW, GENSTATCOL, "   Csw   Trp   Sys   Int   Sof  Flt");
   
         mvprintw(GRAPHROW, GRAPHCOL,          mvprintw(GRAPHROW, GRAPHCOL,
                 "    . %% Sys    . %% User    . %% Nice    . %% Idle");              "    . %% Sys    . %% User    . %% Nice    . %% Idle");
         mvprintw(PROCSROW, PROCSCOL, "Proc:r  d  s  w");          mvprintw(PROCSROW, PROCSCOL, "Proc:r  d  s  w");
         mvprintw(GRAPHROW + 1, GRAPHCOL,          mvprintw(GRAPHROW + 1, GRAPHCOL,
                 "|    |    |    |    |    |    |    |    |    |    |");              "|    |    |    |    |    |    |    |    |    |    |");
   
         mvprintw(NAMEIROW, NAMEICOL,          mvprintw(NAMEIROW, NAMEICOL,
                 "Namei         Sys-cache    Proc-cache    No-cache");              "Namei         Sys-cache    Proc-cache    No-cache");
         mvprintw(NAMEIROW + 1, NAMEICOL,          mvprintw(NAMEIROW + 1, NAMEICOL,
                 "    Calls     hits    %%    hits     %%    miss   %%");              "    Calls     hits    %%    hits     %%    miss   %%");
         mvprintw(DISKROW, DISKCOL, "Discs");          mvprintw(DISKROW, DISKCOL, "Discs");
         mvprintw(DISKROW + 1, DISKCOL, "seeks");          mvprintw(DISKROW + 1, DISKCOL, "seeks");
         mvprintw(DISKROW + 2, DISKCOL, "xfers");          mvprintw(DISKROW + 2, DISKCOL, "xfers");
Line 362 
Line 346 
         for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++)          for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++)
                 if (dk_select[i]) {                  if (dk_select[i]) {
                         mvprintw(DISKROW, DISKCOL + 5 + 5 * j,                          mvprintw(DISKROW, DISKCOL + 5 + 5 * j,
                                 " %4.4s", dr_name[j]);                              " %4.4s", dr_name[j]);
                         j++;                          j++;
                 }                  }
         for (i = 0; i < nintr; i++) {          for (i = 0; i < nintr; i++) {
Line 392 
Line 376 
         int i, l, c;          int i, l, c;
         static int failcnt = 0;          static int failcnt = 0;
   
   
         if (state == TIME)          if (state == TIME)
                 dkswap();                  dkswap();
         etime = 0;          etime = 0;
Line 424 
Line 407 
                                 continue;                                  continue;
                         intrloc[i] = nextintsrow++;                          intrloc[i] = nextintsrow++;
                         mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s",                          mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s",
                                 intrname[i]);                              intrname[i]);
                 }                  }
                 X(intrcnt);                  X(intrcnt);
                 l = (int)((float)s.intrcnt[i]/etime + 0.5);                  l = (int)((float)s.intrcnt[i]/etime + 0.5);
Line 442 
Line 425 
         psiz = 0;          psiz = 0;
         f2 = 0.0;          f2 = 0.0;
   
         /*          /*
          * Last CPU state not calculated yet.           * Last CPU state not calculated yet.
          */           */
         for (c = 0; c < CPUSTATES - 1; c++) {          for (c = 0; c < CPUSTATES - 1; c++) {
Line 454 
Line 437 
                         putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0);                          putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0);
                 else                  else
                         putfloat(f1, GRAPHROW, GRAPHCOL + 12 * c,                          putfloat(f1, GRAPHROW, GRAPHCOL + 12 * c,
                                 5, 1, 0);                              5, 1, 0);
                 move(GRAPHROW + 2, psiz);                  move(GRAPHROW + 2, psiz);
                 psiz += l;                  psiz += l;
                 while (l-- > 0)                  while (l-- > 0)
Line 476 
Line 459 
         putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);          putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
         putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);          putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
         mvaddstr(STATROW, STATCOL + 53, buf);          mvaddstr(STATROW, STATCOL + 53, buf);
 #define pgtokb(pg)     ((pg) * s.uvmexp.pagesize / 1024)  #define pgtokb(pg)      ((pg) * s.uvmexp.pagesize / 1024)
   
         putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 6, 7);          putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 6, 7);
         putint(pgtokb(s.uvmexp.active + s.uvmexp.swpginuse),    /* XXX */          putint(pgtokb(s.uvmexp.active + s.uvmexp.swpginuse),    /* XXX */
Line 528 
Line 511 
         for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++)          for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++)
                 if (dk_select[i]) {                  if (dk_select[i]) {
                         mvprintw(DISKROW, DISKCOL + 5 + 5 * c,                          mvprintw(DISKROW, DISKCOL + 5 + 5 * c,
                                 " %4.4s", dr_name[i]);                              " %4.4s", dr_name[i]);
                         dinfo(i, ++c);                          dinfo(i, ++c);
                 }                  }
         putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);          putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);
         putint(nchtotal.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 10, 8);          putint(nchtotal.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 10, 8);
 #define nz(x)   ((x) ? (x) : 1)  #define nz(x)   ((x) ? (x) : 1)
         putfloat(nchtotal.ncs_goodhits * 100.0 / nz(s.nchcount),          putfloat(nchtotal.ncs_goodhits * 100.0 / nz(s.nchcount),
            NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);              NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);
         putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 24, 7);          putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 24, 7);
         putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount),          putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount),
            NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1);              NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1);
         putint(nchtotal.ncs_miss - nchtotal.ncs_pass2,          putint(nchtotal.ncs_miss - nchtotal.ncs_pass2,
            NAMEIROW + 2, NAMEICOL + 38, 7);             NAMEIROW + 2, NAMEICOL + 38, 7);
         putfloat((nchtotal.ncs_miss - nchtotal.ncs_pass2) *          putfloat((nchtotal.ncs_miss - nchtotal.ncs_pass2) *
            100.0 / nz(s.nchcount), NAMEIROW + 2, NAMEICOL + 45, 4, 0, 1);              100.0 / nz(s.nchcount), NAMEIROW + 2, NAMEICOL + 45, 4, 0, 1);
 #undef nz  #undef nz
 }  }
   
Line 652 
Line 635 
         struct Info *s;          struct Info *s;
         enum state st;          enum state st;
 {  {
         int mib[2];          static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME };
           static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS };
           static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP };
           static int vmtotal_mib[2] = { CTL_VM, VM_METER };
         size_t size;          size_t size;
         extern int errno;  
 #if defined(__i386__)  #if defined(__i386__)
         struct intrhand *intrhand[16], *ihp, ih;          struct intrhand *intrhand[16], *ihp, ih;
         int i, n;          int i, n;
 #endif  #endif
   
         dkreadstats();          dkreadstats();
         NREAD(X_CPTIME, s->time, sizeof s->time);  
         NREAD(X_UVMEXP, &s->uvmexp, sizeof s->uvmexp);  
         NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);  
 #if defined(__i386__)  #if defined(__i386__)
         NREAD(X_INTRHAND, intrhand, sizeof(intrhand));          NREAD(X_INTRHAND, intrhand, sizeof(intrhand));
         for (i = 0, n = 0; i < 16; i++) {          for (i = 0, n = 0; i < 16; i++) {
Line 675 
Line 657 
                 }                  }
         }          }
 #else  #else
         NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);          NREAD(X_INTRCNT, s->intrcnt, nintr * sizeof(long));
 #endif  #endif
           size = sizeof(s->time);
           if (sysctl(cp_time_mib, 2, &s->time, &size, NULL, 0) < 0) {
                   error("Can't get KERN_CPTIME: %s\n", strerror(errno));
                   bzero(&s->time, sizeof(s->time));
           }
   
           size = sizeof(s->nchstats);
           if (sysctl(nchstats_mib, 2, &s->nchstats, &size, NULL, 0) < 0) {
                   error("Can't get KERN_NCHSTATS: %s\n", strerror(errno));
                   bzero(&s->nchstats, sizeof(s->nchstats));
           }
   
           size = sizeof(s->uvmexp);
           if (sysctl(uvmexp_mib, 2, &s->uvmexp, &size, NULL, 0) < 0) {
                   error("Can't get VM_UVMEXP: %s\n", strerror(errno));
                   bzero(&s->uvmexp, sizeof(s->uvmexp));
           }
   
         size = sizeof(s->Total);          size = sizeof(s->Total);
         mib[0] = CTL_VM;          if (sysctl(vmtotal_mib, 2, &s->Total, &size, NULL, 0) < 0) {
         mib[1] = VM_METER;                  error("Can't get VM_METER: %s\n", strerror(errno));
         if (sysctl(mib, 2, &s->Total, &size, NULL, 0) < 0) {  
                 error("Can't get kernel info: %s\n", strerror(errno));  
                 bzero(&s->Total, sizeof(s->Total));                  bzero(&s->Total, sizeof(s->Total));
         }          }
 }  }
Line 717 
Line 715 
   
         /* time busy in disk activity */          /* time busy in disk activity */
         atime = (double)cur.dk_time[dn].tv_sec +          atime = (double)cur.dk_time[dn].tv_sec +
                 ((double)cur.dk_time[dn].tv_usec / (double)1000000);              ((double)cur.dk_time[dn].tv_usec / (double)1000000);
   
         words = cur.dk_bytes[dn] / 1024.0;      /* # of K transferred */          words = cur.dk_bytes[dn] / 1024.0;      /* # of K transferred */
   

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31