コード例 #1
0
ファイル: vm_time_linux32.c プロジェクト: ykiryanov/andopal
/* Stop the process of time measure and obtain the sampling time in seconds */
Ipp64f vm_time_stop(vm_time_handle handle, vm_time *m)
{
   Ipp64f speed_sec;
   Ipp64s end;
   Ipp32s freq_mhz;

   if (handle > 0) {
       Ipp32u startHigh, startLow;
       startLow   = ioctl(handle, GET_TSC_LOW, 0);
       startHigh  = ioctl(handle, GET_TSC_HIGH, 0);
       end = ((Ipp64u)startHigh << 32) + (Ipp64u)startLow;
   }
   else {
       end = vm_time_get_tick();
   }
   m->diff += (end - m->start);

   if (handle > 0) {
      if((m->freq == 0) || (m->freq == VM_TIME_MHZ)) {
         ippGetCpuFreqMhz(&freq_mhz);
         m->freq = (Ipp64s)freq_mhz;
      }
      speed_sec = (Ipp64f)m->diff/1000000.0/(Ipp64f)m->freq;
   } else {
      if(m->freq == 0) m->freq = vm_time_get_frequency();
      speed_sec = (Ipp64f)m->diff/(Ipp64f)m->freq;
   }

   return speed_sec;

} /* Ipp64f vm_time_stop(vm_time_handle handle, vm_time *m) */
コード例 #2
0
/* Start the process of time measure */
vm_status vm_time_start(vm_time_handle handle, vm_time *m)
{
   if (NULL == m)
       return VM_NULL_PTR;

   if (handle > 0)
   {
       Ipp32u startHigh, startLow;
       startLow   = ioctl(handle, GET_TSC_LOW, 0);
       startHigh  = ioctl(handle, GET_TSC_HIGH, 0);
       m->start = ((Ipp64u)startHigh << 32) + (Ipp64u)startLow;
   }
   else
       m->start = vm_time_get_tick();
   return VM_OK;
}
コード例 #3
0
vm_status vm_sys_info_cpu_loading_avg(struct VM_SYSINFO_CPULOAD *dbuf, Ipp32u timeslice/* in msec */) {
  PDH_STATUS sts = ERROR_SUCCESS;
  HQUERY tmpq = 0;
  vm_status rtval = VM_NULL_PTR;
  vm_char scountername[MAX_COUNTER_NAME];
  PDH_HCOUNTER cptr = NULL;
  BOOL isprepared = FALSE;
  DWORD t;
  PDH_FMT_COUNTERVALUE v;
  int i;
  /* we need 1 ms period to hold timeslice time correct */
  timeBeginPeriod(ONEMILLISECOND);
  do {
#ifdef VM_CHECK_CPU_CHECK_TIMESLICE
    if (timeslice < 10) {
      rtval = VM_NOT_ENOUGH_DATA;
      break;
      }
#endif
    if (dbuf == NULL) {
      dbuf = (struct VM_SYSINFO_CPULOAD *)malloc(sizeof(struct VM_SYSINFO_CPULOAD));
      if (dbuf != NULL)
        dbuf[0].cpudes = NULL;
      }
    if (dbuf == NULL)
      break;
    if (dbuf[0].ncpu == 0)
      break;
    if (dbuf[0].cpudes == NULL) {
      dbuf[0].ncpu = vm_sys_info_get_cpu_num();
      dbuf[0].cpudes = (struct VM_SYSINFO_CPULOAD_ENTRY *)(malloc(sizeof(struct VM_SYSINFO_CPULOAD_ENTRY)*(dbuf[0].ncpu+1)));
      }
    if (dbuf[0].cpudes == NULL)
      break;
    /* if cpu description buffer was not NULL I hope it will be enough to hold all information
       about all the CPUs */
    tmpq = dbuf[0].CpuLoadQuery;
    if ( tmpq == 0) {/* no more performance handle created yet */
      PdhOpenQuery(NULL, 0, &tmpq);
      if (tmpq == 0)
        break;
      dbuf[0].CpuLoadQuery = tmpq;
      }
    if (dbuf[0].CpuPerfCounters[0] != 0)
      isprepared = TRUE; /* performance monitor already prepared */
    if (dbuf[0].CpuLoadQuery == 0)
      break;
    if (!isprepared) {
        /* create buffers for counters */
        rtval = VM_OK;
        for( i = 0; i < MAX_PERF_PARAMETERS; ++i ) {
          dbuf[0].CpuPerfCounters[i] = NULL;
          dbuf[0].CpuPerfCounters[i] = (PDH_HCOUNTER *)malloc((dbuf[0].ncpu+1/*for overall counter*/)*sizeof(PDH_HCOUNTER));
          if (dbuf[0].CpuPerfCounters[i] == NULL) {
            rtval = VM_OPERATION_FAILED;
            break;
            }
          }
        if (rtval != VM_OK) {
          for( i = 0; i < MAX_PERF_PARAMETERS; ++i )
            if (dbuf[0].CpuPerfCounters[i] != NULL) {
              free(dbuf[0].CpuPerfCounters[i]);
              dbuf[0].CpuPerfCounters[i] = NULL;
              }
          break;
          }          
        /* add performance counters */
        /* user time                */
        vm_string_strcpy(scountername, VM_STRING("\\Processor     "));
        for( i = 0; i < dbuf[0].ncpu; ++i ) {
          vm_string_sprintf(&scountername[10], VM_STRING("(%d)\\%% User Time"), i);
          cptr = dbuf[0].CpuPerfCounters[0] + i*sizeof(PDH_HCOUNTER);
          sts = PdhAddCounter(dbuf[0].CpuLoadQuery, scountername, 0, cptr);    
          vm_string_sprintf(&scountername[10], VM_STRING("(%d)\\%% Privileged Time"), i);
          cptr = dbuf[0].CpuPerfCounters[1] + i*sizeof(PDH_HCOUNTER);
          sts = PdhAddCounter(dbuf[0].CpuLoadQuery, scountername, 0, cptr);

          vm_string_sprintf(&scountername[10], VM_STRING("(%d)\\%% Interrupt Time"), i);
          cptr = dbuf[0].CpuPerfCounters[2] + i*sizeof(PDH_HCOUNTER);
          sts = PdhAddCounter(dbuf[0].CpuLoadQuery, scountername, 0, cptr);
          }
        }        
      vm_time_sleep(timeslice);
      if ((sts = PdhCollectQueryData(dbuf[0].CpuLoadQuery)) != ERROR_SUCCESS)
        break;
      /* fill in output data structure */
      for(i = 0; i < dbuf[0].ncpu; ++i) {
        sts = PdhGetFormattedCounterValue(dbuf[0].CpuPerfCounters[0][i], PDH_FMT_LONG, &t, &v);
        dbuf[0].cpudes[i].usrload = AVGFLOAT(v.longValue);
        sts = PdhGetFormattedCounterValue(dbuf[0].CpuPerfCounters[1][i], PDH_FMT_LONG, &t, &v); 
        dbuf[0].cpudes[i].sysload = AVGFLOAT(v.longValue);           
        dbuf[0].cpudes[i].idleload = (float)1. - dbuf[0].cpudes[i].usrload - dbuf[0].cpudes[i].sysload;
        dbuf[0].cpudes[i].idleload = (dbuf[0].cpudes[i].idleload < 0) ? 0 : dbuf[0].cpudes[i].idleload;
        sts = PdhGetFormattedCounterValue(dbuf[0].CpuPerfCounters[2][i], PDH_FMT_LONG, &t, &v);
        dbuf[0].cpudes[i].irqsrvload = AVGFLOAT(v.longValue);
        /* clear other parameters for each processor */
        dbuf[0].cpudes[i].iowaitsload = dbuf[0].cpudes[i].softirqsrvload = 0.;
          dbuf[0].cpudes[i].usrniceload = dbuf[0].cpudes[i].vmstalled = 0.;
        }
      rtval = VM_OK;
    } while (0);
    if ((NULL != dbuf) && (ticks_on_avg_call != 0))
      dbuf[0].tickspassed = (vm_tick)((vm_time_get_tick() - ticks_on_avg_call)*1000/vm_time_get_frequency());
    ticks_on_avg_call = vm_time_get_tick();
    timeEndPeriod(ONEMILLISECOND);
  return rtval;
  }