[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.88 and 1.89

version 1.88, 2018/10/05 18:56:57 version 1.89, 2018/11/17 23:10:08
Line 60 
Line 60 
 #define MINIMUM(a, b)   (((a) < (b)) ? (a) : (b))  #define MINIMUM(a, b)   (((a) < (b)) ? (a) : (b))
   
 static struct Info {  static struct Info {
         long    time[CPUSTATES];          struct  cpustats cpustats;
         struct  uvmexp uvmexp;          struct  uvmexp uvmexp;
         struct  vmtotal Total;          struct  vmtotal Total;
         struct  nchstats nchstats;          struct  nchstats nchstats;
Line 68 
Line 68 
         uint64_t *intrcnt;          uint64_t *intrcnt;
 } s, s1, s2, s3, z;  } s, s1, s2, s3, z;
   
   static int ncpu;
   
 extern struct _disk     cur;  extern struct _disk     cur;
   
 #define cnt s.Cnt  #define cnt s.Cnt
Line 172 
Line 174 
         if (!dkinit(1))          if (!dkinit(1))
                 return(0);                  return(0);
   
           mib[0] = CTL_HW;
           mib[1] = HW_NCPU;
           size = sizeof(ncpu);
           if (sysctl(mib, 2, &ncpu, &size, NULL, 0) < 0)
                   return (-1);
   
         mib[0] = CTL_KERN;          mib[0] = CTL_KERN;
         mib[1] = KERN_INTRCNT;          mib[1] = KERN_INTRCNT;
         mib[2] = KERN_INTRCNT_NUM;          mib[2] = KERN_INTRCNT_NUM;
Line 337 
Line 345 
         }          }
         etime = 0;          etime = 0;
         for (i = 0; i < CPUSTATES; i++) {          for (i = 0; i < CPUSTATES; i++) {
                 X(time);                  X(cpustats.cs_time);
                 etime += s.time[i];                  etime += s.cpustats.cs_time[i];
         }          }
         if (etime < 5.0) {      /* < 5 ticks - ignore this trash */          if (etime < 5.0) {      /* < 5 ticks - ignore this trash */
                 if (failcnt++ >= MAXFAIL) {                  if (failcnt++ >= MAXFAIL) {
Line 497 
Line 505 
         int i;          int i;
   
         tm = 0;          tm = 0;
         for (i = 0; i < CPUSTATES; i++)          for (i = 0; i < nitems(s.cpustats.cs_time); i++)
                 tm += s.time[i];                  tm += s.cpustats.cs_time[i];
         if (tm == 0.0)          if (tm == 0.0)
                 tm = 1.0;                  tm = 1.0;
         return (s.time[indx] * 100.0 / tm);          return (s.cpustats.cs_time[indx] * 100.0 / tm);
 }  }
   
 void  void
Line 592 
Line 600 
 static void  static void
 getinfo(struct Info *si)  getinfo(struct Info *si)
 {  {
         static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME };          static int cpustats_mib[3] = { CTL_KERN, KERN_CPUSTATS, 0 };
         static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS };          static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS };
         static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP };          static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP };
         static int vmtotal_mib[2] = { CTL_VM, VM_METER };          static int vmtotal_mib[2] = { CTL_VM, VM_METER };
         int mib[4], i;          struct cpustats cs;
           int mib[4], i, j;
         size_t size;          size_t size;
   
         dkreadstats();          dkreadstats();
Line 612 
Line 621 
                 }                  }
         }          }
   
         size = sizeof(si->time);          memset(&si->cpustats.cs_time, 0, sizeof(si->cpustats.cs_time));
         if (sysctl(cp_time_mib, 2, &si->time, &size, NULL, 0) < 0) {          for (i = 0; i < ncpu; i++) {
                 error("Can't get KERN_CPTIME: %s\n", strerror(errno));                  cpustats_mib[2] = i;
                 memset(&si->time, 0, sizeof(si->time));                  size = sizeof(cs);
                   if (sysctl(cpustats_mib, 3, &cs, &size, NULL, 0) < 0) {
                           error("Can't get KERN_CPUSTATS: %s\n", strerror(errno));
                           memset(&si->cpustats, 0, sizeof(si->cpustats));
                   }
                   if ((cs.cs_flags & CPUSTATS_ONLINE) == 0)
                           continue;       /* omit totals for offline CPUs */
                   for (j = 0; j < nitems(cs.cs_time); j++)
                           si->cpustats.cs_time[j] += cs.cs_time[j];
         }          }
   
         size = sizeof(si->nchstats);          size = sizeof(si->nchstats);

Legend:
Removed from v.1.88  
changed lines
  Added in v.1.89