CpuInfo getCpuInfo()
 {
     CpuInfo cpuInfo;
     cpuInfo.m_cpuBrand = getCpuBrand();
     cpuInfo.m_processorPackageCount = getCpuCount();
     cpuInfo.m_coreCount = getCpuCoreCount();
     cpuInfo.m_processSpeed = getCpuSpeed();
     return cpuInfo;
 }
  int readCpuCounters(SFLHost_cpu_counters *cpu) 
  {
    int gotData = NO;
    uint64_t val64;
    size_t len;
    double load[3];
    long cp_time[CPUSTATES];
    uint32_t stathz = sysconf(_SC_CLK_TCK);
    
#define STATHZ_TO_MS(t) (((t) * 1000) / stathz)

    getloadavg(load, 3);
    cpu->load_one = (float)load[0];
    cpu->load_five = (float)load[1];
    cpu->load_fifteen = (float)load[2];

    cpu->proc_run = (uint32_t)getRunningProcesses();
    cpu->proc_total = (uint32_t)getTotalProcesses();
    if (getSys64("hw.ncpu", &val64)) cpu->cpu_num = (uint32_t)val64;
    cpu->cpu_speed = (uint32_t) getCpuSpeed();

    /* puts kern.cp_time array into cp_time */
    /* constants are defined in sys/dkstat.h */
    len = sizeof(cp_time);
    if (sysctlbyname("kern.cp_time", &cp_time, &len, NULL, 0) != -1) {
      // len should be 20. is it really an array of long, though?
      // might want to just read up to 40 bytes and then see what we get.
      // myLog(LOG_INFO, "kerm.cp_time len=%u", len);
      cpu->cpu_user = STATHZ_TO_MS(cp_time[CP_USER]);
      cpu->cpu_nice = STATHZ_TO_MS(cp_time[CP_NICE]);
      cpu->cpu_system = STATHZ_TO_MS(cp_time[CP_SYS]);
      cpu->cpu_idle = STATHZ_TO_MS(cp_time[CP_IDLE]);
      cpu->cpu_intr = STATHZ_TO_MS(cp_time[CP_INTR]);
    }

    cpu->cpu_wio = (uint32_t)-1; // unsupported
    // note "vm.stats.sys.v_soft" gives us the number of soft interrupts, not the time spent
    cpu->cpu_sintr = (uint32_t)-1; // unsupported

    if(getSys64("vm.stats.sys.v_intr", &val64)) cpu->interrupts = (uint32_t)val64;
    if(getSys64("vm.stats.sys.v_swtch", &val64)) cpu->contexts = (uint32_t)val64;

    gotData = YES;
  
    return gotData;
  }