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

Diff for /src/usr.bin/systat/cpu.c between version 1.7 and 1.8

version 1.7, 2018/09/26 17:23:13 version 1.8, 2018/10/05 18:56:57
Line 50 
Line 50 
 #include <sys/sched.h>  #include <sys/sched.h>
 #include <sys/sysctl.h>  #include <sys/sysctl.h>
   
 #include <errno.h>  
 #include <stdlib.h>  #include <stdlib.h>
 #include <stdint.h>  #include <stdint.h>
 #include <string.h>  #include <string.h>
Line 100 
Line 99 
 };  };
   
 int       cpu_count;  int       cpu_count;
 int      *cpu_online;  
 int64_t  *cpu_states;  int64_t  *cpu_states;
 int64_t **cpu_tm;  int64_t **cpu_tm;
 int64_t **cpu_old;  int64_t **cpu_old;
Line 158 
Line 156 
         for (i = 0; i < cpu_count; i++) {          for (i = 0; i < cpu_count; i++) {
                 cpu_time_mib[2] = i;                  cpu_time_mib[2] = i;
                 tmpstate = cpu_states + (CPUSTATES * i);                  tmpstate = cpu_states + (CPUSTATES * i);
                 if (sysctl(cpu_time_mib, 3, cpu_tm[i], &size, NULL, 0) < 0) {                  if (sysctl(cpu_time_mib, 3, cpu_tm[i], &size, NULL, 0) < 0)
                         if (errno != ENODEV)                          error("sysctl KERN_CPTIME2");
                                 error("sysctl KERN_CPTIME2");  
                         cpu_online[i] = 0;  
                         continue;  
                 }  
                 cpu_online[i] = 1;  
                 percentages(CPUSTATES, tmpstate, cpu_tm[i],                  percentages(CPUSTATES, tmpstate, cpu_tm[i],
                     cpu_old[i], cpu_diff[i]);                      cpu_old[i], cpu_diff[i]);
         }          }
Line 207 
Line 200 
         mib[1] = HW_NCPU;          mib[1] = HW_NCPU;
         if (sysctl(mib, 2, &cpu_count, &size, NULL, 0) == -1)          if (sysctl(mib, 2, &cpu_count, &size, NULL, 0) == -1)
                 return (-1);                  return (-1);
         if ((cpu_online = calloc(cpu_count, sizeof(*cpu_online))) == NULL)  
                 return (-1);  
         if ((cpu_states = calloc(cpu_count,          if ((cpu_states = calloc(cpu_count,
             CPUSTATES * sizeof(int64_t))) == NULL)              CPUSTATES * sizeof(int64_t))) == NULL)
                 return (-1);                  return (-1);
Line 255 
Line 246 
                         return;                                         \                          return;                                         \
         } while (0)          } while (0)
   
 #define ADD_OFFLINE_CPU(v) do {                                         \  
         if (cur >= dispstart && cur < end) {                            \  
                 print_fld_size(FLD_CPU_CPU, (v));                       \  
                 print_fld_str(FLD_CPU_USR, "-");                        \  
                 print_fld_str(FLD_CPU_NIC, "-");                        \  
                 print_fld_str(FLD_CPU_SYS, "-");                        \  
                 print_fld_str(FLD_CPU_SPIN, "-");                       \  
                 print_fld_str(FLD_CPU_INT, "-");                        \  
                 print_fld_str(FLD_CPU_IDLE, "-");                       \  
                 end_line();                                             \  
         }                                                               \  
         if (++cur >= end)                                               \  
                 return;                                                 \  
 } while (0)  
   
 void  void
 print_cpu(void)  print_cpu(void)
 {  {
Line 282 
Line 258 
                 end = num_disp;                  end = num_disp;
   
         for (c = 0; c < cpu_count; c++) {          for (c = 0; c < cpu_count; c++) {
                 if (!cpu_online[c]) {  
                         ADD_OFFLINE_CPU(c);  
                         continue;  
                 }  
                 states = cpu_states + (CPUSTATES * c);                  states = cpu_states + (CPUSTATES * c);
   
                 for (i = 0; i < CPUSTATES; i++)                  for (i = 0; i < CPUSTATES; i++)

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8