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

Diff for /src/usr.bin/vmstat/dkstats.c between version 1.15 and 1.16

version 1.15, 2002/02/16 21:27:58 version 1.16, 2002/05/23 10:35:07
Line 51 
Line 51 
 #include <unistd.h>  #include <unistd.h>
 #include "dkstats.h"  #include "dkstats.h"
   
   #if !defined(NOKVM)
 static struct nlist namelist[] = {  static struct nlist namelist[] = {
 #define X_TK_NIN        0  #define X_TK_NIN        0
         { "_tk_nin" },          /* tty characters in */          { "_tk_nin" },          /* tty characters in */
Line 68 
Line 69 
         { "_disklist" },        /* TAILQ of disks */          { "_disklist" },        /* TAILQ of disks */
         { NULL },          { NULL },
 };  };
   #define KVM_ERROR(_string) {                                            \
           warnx("%s", (_string));                                         \
           errx(1, "%s", kvm_geterr(kd));                                  \
   }
   
   /*
    * Dereference the namelist pointer `v' and fill in the local copy
    * 'p' which is of size 's'.
    */
   #define deref_nl(v, p, s) deref_kptr((void *)namelist[(v)].n_value, (p), (s));
   static void deref_kptr(void *, void *, size_t);
   #endif /* !defined(NOKVM) */
   
 /* Structures to hold the statistics. */  /* Structures to hold the statistics. */
 struct _disk    cur, last;  struct _disk    cur, last;
   
Line 85 
Line 98 
 int             *dk_select;  int             *dk_select;
 char            **dr_name;  char            **dr_name;
   
 #define KVM_ERROR(_string) {                                            \  
         warnx("%s", (_string));                                         \  
         errx(1, "%s", kvm_geterr(kd));                                  \  
 }  
   
 /*  
  * Dereference the namelist pointer `v' and fill in the local copy  
  * 'p' which is of size 's'.  
  */  
 #define deref_nl(v, p, s) deref_kptr((void *)namelist[(v)].n_value, (p), (s));  
   
 /* Missing from <sys/time.h> */  /* Missing from <sys/time.h> */
 #define timerset(tvp, uvp) ((uvp)->tv_sec = (tvp)->tv_sec);             \  #define timerset(tvp, uvp) \
                            ((uvp)->tv_usec = (tvp)->tv_usec)          ((uvp)->tv_sec = (tvp)->tv_sec);                \
           ((uvp)->tv_usec = (tvp)->tv_usec)
   
 static void deref_kptr(void *, void *, size_t);  #define SWAP(fld)       tmp = cur.fld;                          \
                           cur.fld -= last.fld;                    \
                           last.fld = tmp
   
 /*  /*
  * Take the delta between the present values and the last recorded   * Take the delta between the present values and the last recorded
Line 110 
Line 115 
 void  void
 dkswap()  dkswap()
 {  {
 #define SWAP(fld)               tmp = cur.fld;                          \  
                                 cur.fld -= last.fld;                    \  
                                 last.fld = tmp  
         u_int64_t tmp;          u_int64_t tmp;
         int     i;          int     i;
   
Line 199 
Line 201 
                         cur.tk_nout = 0;                          cur.tk_nout = 0;
                 }                  }
         } else {          } else {
   #if !defined(NOKVM)
                 p = dk_drivehead;                  p = dk_drivehead;
   
                 for (i = 0; i < dk_ndrive; i++) {                  for (i = 0; i < dk_ndrive; i++) {
Line 209 
Line 212 
                         timerset(&(cur_disk.dk_time), &(cur.dk_time[i]));                          timerset(&(cur_disk.dk_time), &(cur.dk_time[i]));
                         p = cur_disk.dk_link.tqe_next;                          p = cur_disk.dk_link.tqe_next;
                 }                  }
   
                 deref_nl(X_CP_TIME, cur.cp_time, sizeof(cur.cp_time));                  deref_nl(X_CP_TIME, cur.cp_time, sizeof(cur.cp_time));
                 deref_nl(X_TK_NIN, &cur.tk_nin, sizeof(cur.tk_nin));                  deref_nl(X_TK_NIN, &cur.tk_nin, sizeof(cur.tk_nin));
                 deref_nl(X_TK_NOUT, &cur.tk_nout, sizeof(cur.tk_nout));                  deref_nl(X_TK_NOUT, &cur.tk_nout, sizeof(cur.tk_nout));
   #endif /* !defined(NOKVM) */
         }          }
 }  }
   
Line 238 
Line 241 
                 return(1);                  return(1);
   
         if (nlistf != NULL || memf != NULL) {          if (nlistf != NULL || memf != NULL) {
   #if !defined(NOKVM)
                 /* Open the kernel. */                  /* Open the kernel. */
                 if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,                  if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
                     errbuf)) == NULL)                      errbuf)) == NULL)
Line 261 
Line 265 
                 deref_nl(X_STATHZ, &hz, sizeof(hz));                  deref_nl(X_STATHZ, &hz, sizeof(hz));
                 if (!hz)                  if (!hz)
                   deref_nl(X_HZ, &hz, sizeof(hz));                    deref_nl(X_HZ, &hz, sizeof(hz));
   #endif /* !defined(NOKVM) */
         } else {          } else {
                 /* Get the number of attached drives. */                  /* Get the number of attached drives. */
                 mib[0] = CTL_HW;                  mib[0] = CTL_HW;
Line 322 
Line 327 
                     cur.dk_select[i++] = select;                      cur.dk_select[i++] = select;
                 }                  }
         } else {          } else {
   #if !defined(NOKVM)
                 p = dk_drivehead;                  p = dk_drivehead;
                 for (i = 0; i < dk_ndrive; i++) {                  for (i = 0; i < dk_ndrive; i++) {
                         char    buf[10];                          char    buf[10];
   
                         deref_kptr(p, &cur_disk, sizeof(cur_disk));                          deref_kptr(p, &cur_disk, sizeof(cur_disk));
                         deref_kptr(cur_disk.dk_name, buf, sizeof(buf));                          deref_kptr(cur_disk.dk_name, buf, sizeof(buf));
                         cur.dk_name[i] = strdup(buf);                          cur.dk_name[i] = strdup(buf);
Line 334 
Line 341 
   
                         p = cur_disk.dk_link.tqe_next;                          p = cur_disk.dk_link.tqe_next;
                 }                  }
   #endif /* !defined(NOKVM) */
         }          }
   
         /* Never do this initalization again. */          /* Never do this initalization again. */
Line 341 
Line 349 
         return(1);          return(1);
 }  }
   
   #if !defined(NOKVM)
 /*  /*
  * Dereference the kernel pointer `kptr' and fill in the local copy   * Dereference the kernel pointer `kptr' and fill in the local copy
  * pointed to by `ptr'.  The storage space must be pre-allocated,   * pointed to by `ptr'.  The storage space must be pre-allocated,
Line 360 
Line 369 
                 KVM_ERROR(buf);                  KVM_ERROR(buf);
         }          }
 }  }
   #endif /* !defined(NOKVM) */
   

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16