Ejemplo n.º 1
0
static int read_counter_large_int(HCOUNTER hcounter, long long *result)
{
	PDH_STATUS pdh_status;
	PDH_FMT_COUNTERVALUE *item_buf;

	if(hcounter == NULL)
		return -1;

	item_buf = sg_malloc(sizeof(PDH_FMT_COUNTERVALUE));
	if (item_buf == NULL) {
		return -1;
	}

	pdh_status = PdhGetFormattedCounterValue(hcounter, PDH_FMT_LARGE, NULL,
			item_buf);
	if(pdh_status != ERROR_SUCCESS) {
		free(item_buf);
		/*switch(pdh_status) {
			case PDH_INVALID_ARGUMENT:
				printf("invalid argument\n");
				break;
			case PDH_INVALID_DATA:
				printf("invalid data\n");
				break;
			case PDH_INVALID_HANDLE:
				printf("invalid handle\n");
				break;
		}*/
		return -1;
	}
	*result = item_buf->largeValue;
	free(item_buf);
	return 0;
}
Ejemplo n.º 2
0
int 
loadvalue_update_cpuusage(t_loadvalues *loadvalue, t_pdhquery *query,
                          t_pdhcounterset *counter_cpuusage)
{
   static BOOL initialized = FALSE;
   int ret = 0;
   DWORD local_ret;

   DENTER("loadvalue_update_cpuusage");

   /* Do query counter initialisation only once */ 
   if (!initialized) { 
      local_ret = pdhquery_initialize(query);
      if (local_ret == 0) {
         local_ret = pdhcounterset_initialize(counter_cpuusage,
                                              "Processor",
                                              "_Total",
                                              "% Processor Time");
         if (local_ret == 0) {
            local_ret = pdhquery_add_counterset(query, counter_cpuusage);
            if (local_ret != 0) {
               // error handling
               ret = 3;
            }
         } else {
            // error handling
            ret = 2;
         }
      } else {
         // error handling
         ret = 1;
      }
      if (ret != 0) {
         return ret;
      }
      initialized = TRUE;
   }

   /* We are here - no error occured during initialisation */
   local_ret = pdhquery_update(query);
   if (local_ret == 0) {
      PDH_FMT_COUNTERVALUE cpu_usage;
   
      local_ret = PdhGetFormattedCounterValue(
                                          counter_cpuusage->counter_handles[0], 
                                          PDH_FMT_LONG, NULL, &cpu_usage);
      // error handling
      local_ret = WaitForSingleObject(loadvalue_mutex, INFINITE);
      if (local_ret == WAIT_OBJECT_0) {
         loadvalue->cpu = cpu_usage.longValue;
      }
      ReleaseMutex(loadvalue_mutex);
   } else {
      // error handling
      ret = 10;
   }
    
   DEXIT; 
   return ret;
}
Ejemplo n.º 3
0
float ZeroProcessMonitor::GetCpuUsage() {
	// CPU 사용량 정보 수집
	PDH_STATUS pdhStatus = PdhCollectQueryData(cpuUsageQuery);

	if (ERROR_SUCCESS != pdhStatus) {
		// TODO: 에러 처리
		// pdhStatus ==> ErrorCode

		return -1;
	}

	// CPU 사용량 정보 처리
	PDH_FMT_COUNTERVALUE fmtValue;

	pdhStatus = PdhGetFormattedCounterValue(cpuUsageCounter, PDH_FMT_DOUBLE, NULL, &fmtValue);

	if (ERROR_SUCCESS != pdhStatus) {
		// TODO: 에러 처리
		// pdhStatus ==> ErrorCode

		return -1;
	}

	return static_cast<float>(fmtValue.doubleValue);
}
bool PerformanceManager::update()
{
	float timeDifference;
	INT64 currentTime;
	PDH_FMT_COUNTERVALUE value;

	//=====
	// FPS 
	//=====

	m_frameCount++;

	// If one second has passed then update the frame per second speed.
	if (timeGetTime() >= (m_fpsStart + 1000))
	{
		// Store FPS Count
		m_fps = m_frameCount;

		// Reset
		m_frameCount = 0;
		m_fpsStart = timeGetTime();
	}

	//=====
	// CPU
	//=====

	if (m_canAccessCPU)
	{
		// If it has been 1 second then update the current cpu usage and reset the 1 second timer again.
		if ((m_lastSampleTime + 1000) < GetTickCount())
		{
			m_lastSampleTime = GetTickCount();

			PdhCollectQueryData(m_queryHandle);

			PdhGetFormattedCounterValue(m_counterHandle, PDH_FMT_LONG, NULL, &value);

			m_usage = value.longValue;
		}
	}

	//=======
	// Timer
	//=======

	// Query the current time
	QueryPerformanceCounter((LARGE_INTEGER*)&currentTime);

	// Calculate difference in time since last check
	timeDifference = (float)(currentTime - m_timerStart);

	// Calculate the frame time by the time difference over the timer speed resolution.
	m_frameTime = timeDifference / m_ticksPerMs;

	// Restart the timer.
	QueryPerformanceCounter((LARGE_INTEGER*)&m_timerStart);

	return true;
}
int PerfCounterMuninNodePlugin::GetValues(char *buffer, int len)
{
  PDH_STATUS status;
  PDH_FMT_COUNTERVALUE counterValue;
  int printCount;

  status = PdhCollectQueryData(m_PerfQuery);
  if (status != ERROR_SUCCESS)
    return -1;  

  for (size_t i = 0; i < m_Counters.size(); i++) {
    // Get the formatted counter value    
    status = PdhGetFormattedCounterValue(m_Counters[i], m_dwCounterFormat, NULL, &counterValue);
    if (status != ERROR_SUCCESS)
      return -1;
    double value = 0;
    switch (m_dwCounterFormat) {
      case PDH_FMT_DOUBLE:        
        value = counterValue.doubleValue * m_CounterMultiply;
        break;
      case PDH_FMT_LONG:
        value = counterValue.longValue * m_CounterMultiply;
        break;
      case PDH_FMT_LARGE:
        value = counterValue.largeValue * m_CounterMultiply;
        break;
    }
    printCount = printvalue(buffer, len, m_Name.c_str(), i, value, m_dwCounterFormat);
    len -= printCount;
    buffer += printCount;
  }
  strncat(buffer, ".\n", len);
  return 0;
}
Ejemplo n.º 6
0
nsresult WinProcMon::QuerySystemLoad(float* load_percent)
{
  *load_percent = 0;

  if (mQuery == 0) {
    return NS_ERROR_FAILURE;
  }

  // Update all counters associated with this query object.
  PDH_STATUS status = PdhCollectQueryData(mQuery);

  if (status != ERROR_SUCCESS) {
    LOG(("PdhCollectQueryData error = %X", status));
    return NS_ERROR_FAILURE;
  }

  PDH_FMT_COUNTERVALUE counter;
  // maximum is 100% regardless of CPU core count.
  status = PdhGetFormattedCounterValue(
               mCounter,
               PDH_FMT_DOUBLE,
               (LPDWORD)NULL,
               &counter);

  if (ERROR_SUCCESS != status ||
      // There are multiple success return values.
      !IsSuccessSeverity(counter.CStatus)) {
    LOG(("PdhGetFormattedCounterValue error"));
    return NS_ERROR_FAILURE;
  }

  // The result is a percent value, reduce to match expected scale.
  *load_percent = (float)(counter.doubleValue / 100.0f);
  return NS_OK;
}
Ejemplo n.º 7
0
__int64 PerfCounter::GetLong(int id)
{
	if(id == 0)
		return 0;

	PDH_FMT_COUNTERVALUE value;
	PdhGetFormattedCounterValue(m_counters[id - 1], PDH_FMT_LARGE, NULL, &value);
	return value.longValue;
}
Ejemplo n.º 8
0
double PerfCounter::GetDouble(int id)
{
	if(id == 0)
		return 0.0;

	PDH_FMT_COUNTERVALUE value;
	PdhGetFormattedCounterValue(m_counters[id - 1], PDH_FMT_DOUBLE, NULL, &value);
	return value.doubleValue;
}
Ejemplo n.º 9
0
PDH_STATUS PerformanceCounter::NextValue(DWORD format,
                                         PDH_FMT_COUNTERVALUE* value) {
  auto status = PdhCollectQueryData(query_);
  if (status != ERROR_SUCCESS)
    return status;

  return PdhGetFormattedCounterValue(counter_, format | PDH_FMT_NOCAP100,
                                     nullptr, value);
}
Ejemplo n.º 10
0
/**
 * 指定されたカウンタの値を double 値で取得します。
 * 上限値を 100 で制限しません。
 *
 * @param hCounter カウンタハンドル
 * @return 成功した場合はカウンタの値、失敗した場合は DOUBLE_ERROR_VALUE (-1)
 */
static double GetFormattedCounterValueByDoubleNoCap100(PDH_HCOUNTER hCounter)
{
	PDH_FMT_COUNTERVALUE fntValue;
	PDH_STATUS status = PdhGetFormattedCounterValue(
			hCounter, PDH_FMT_DOUBLE | PDH_FMT_NOCAP100, NULL, &fntValue);
	if (status != ERROR_SUCCESS) 
	{
		fntValue.doubleValue = DOUBLE_ERROR_VALUE;
	}
	return fntValue.doubleValue;
}
Ejemplo n.º 11
0
//------------------------------------------------------------------------------------------------------------------
// getcpuload()
//   directly prints the CPU usage on screen. This function need to be called twice with a minimum of 1 seconds
//   delay (msdn guideline) to display something usefull.
//   Also returns the usage in percent 0-100 where 100 means the system is working at maximum capacity.
//   Note for multiprocessor systems:
//   If one CPU is working at max capacity the result will (if using (_total) for PdhAddCounter() ) show a maximum
//   workload of 50% unless the other CPU(s) is also working at max load. 
//------------------------------------------------------------------------------------------------------------------
int getcpuload()
{
	static PDH_STATUS            status;
	static PDH_FMT_COUNTERVALUE  value;
	static HQUERY                query;
	static HCOUNTER              counter;
	static DWORD                 ret;
	static char                  runonce=1;
	char                         cput=0;

	if(runonce)
	{
		status = PdhOpenQuery(NULL, 0, &query);
		if(status != ERROR_SUCCESS)
		{
			printf("PdhOpenQuery() ***Error: 0x%X\n",status);
			return 0;
		}

		PdhAddCounter(query, TEXT("\\Processor(_Total)\\% Processor Time"),0,&counter); // A total of ALL CPU's in the system
		//PdhAddCounter(query, TEXT("\\Processor(0)\\% Processor Time"),0,&counter);    // For systems with more than one CPU (Cpu0)
		//PdhAddCounter(query, TEXT("\\Processor(1)\\% Processor Time"),0,&counter);    // For systems with more than one CPU (Cpu1)
		runonce=0;
		PdhCollectQueryData(query); // No error checking here
		return 0;
	}

	status = PdhCollectQueryData(query);
	if(status != ERROR_SUCCESS)
	{
		printf("PhdCollectQueryData() ***Error: 0x%X\n",status);
		if(status==PDH_INVALID_HANDLE) 
			printf("PDH_INVALID_HANDLE\n");
		else if(status==PDH_NO_DATA)
			printf("PDH_NO_DATA\n");
		else
			printf("Unknown error\n");
		return 0;
	}

	status = PdhGetFormattedCounterValue(counter, PDH_FMT_DOUBLE | PDH_FMT_NOCAP100 ,&ret, &value);
	if(status != ERROR_SUCCESS)
	{
		printf("PdhGetFormattedCounterValue() ***Error: 0x%X\n",status);
		return 0;
	}
	cput = value.doubleValue;

	printf("\n\nCPU Total usage: %3d%%\n",cput);

	return cput;
}
Ejemplo n.º 12
0
void TextClass::Render()
{
	INT64 currentTime;
	float timeDifference;

	PDH_FMT_COUNTERVALUE value;

	// Set timer


	QueryPerformanceCounter((LARGE_INTEGER*)&currentTime);

	timeDifference = (float)(currentTime - m_startTime);

	m_frameTime = timeDifference / m_ticksPerMs;

	m_startTime = currentTime;


	// Set fps
	m_count++;

	// If one second has passed then update the frame per second speed.
	if (timeGetTime() >= (m_startTimeFps + 1000))
	{
		m_fps = m_count;
		m_count = 0;

		m_startTimeFps = timeGetTime();
	}

	// Set cpu


	if (m_canReadCpu)
	{
		// If it has been 1 second then update the current cpu usage and reset the 1 second timer again.
		if ((m_lastSampleTime + 1000) < GetTickCount())
		{
			m_lastSampleTime = GetTickCount();

			PdhCollectQueryData(m_queryHandle);

			PdhGetFormattedCounterValue(m_counterHandle, PDH_FMT_LONG, NULL, &value);

			m_cpuUsage = value.longValue;
		}
	}

	
	return;
}
    void
    Windows_Monitor::update_i (void)
    {
      PdhCollectQueryData (this->query_);
      PDH_FMT_COUNTERVALUE pdh_value;

      PdhGetFormattedCounterValue (this->counter_,
                                   PDH_FMT_DOUBLE,
                                   0,
                                   &pdh_value);

      this->value_ = pdh_value.doubleValue;
    }
Ejemplo n.º 14
0
JNIEXPORT jdouble JNICALL Java_org_hyperic_hq_plugin_mssql_PDH_PdhGetFormattedCounterValue(JNIEnv *env, jclass, jlong counter) {
    HCOUNTER  h_counter = (HCOUNTER)counter;
    PDH_FMT_COUNTERVALUE fmt_value;

	PDH_STATUS status = PdhGetFormattedCounterValue(h_counter, PDH_FMT_DOUBLE, (LPDWORD)NULL, &fmt_value);

    if (status != ERROR_SUCCESS) {
        plugin_throw_exception(env, get_error_message(status));
        return 0;
    }

    return fmt_value.doubleValue;
}
Ejemplo n.º 15
0
Archivo: Cpu.cpp Proyecto: Elbe2/Gundby
void CCpu::Frame(void)
{
	PDH_FMT_COUNTERVALUE value;
	if(m_CanReadCPU)
	{
		if((m_LastSampleTime + 1000) < GetTickCount())
		{
			m_LastSampleTime=GetTickCount();
			PdhCollectQueryData(m_QueryHandle);
			PdhGetFormattedCounterValue(m_CounterHandle,PDH_FMT_LONG,NULL,&value);
			m_CPUUsage=value.longValue;
		}
	}
}
Ejemplo n.º 16
0
Archivo: pdh.c Proyecto: 40a/sigar
JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetValue)
(JNIEnv *env, jclass cur, jlong query, jlong counter, jboolean fmt)
{
    HCOUNTER              h_counter      = (HCOUNTER)counter;
    HQUERY                h_query        = (HQUERY)query;
    PDH_STATUS            status;
    PDH_RAW_COUNTER raw_value;
    PDH_FMT_COUNTERVALUE fmt_value;
    DWORD type;

    status = PdhCollectQueryData(h_query);
   
    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return 0;
    }

    if (fmt) {
        /* may require 2 counters, see msdn docs */
        int i=0;
        for (i=0; i<2; i++) {
            status = PdhGetFormattedCounterValue(h_counter,
                                                 PDH_FMT_DOUBLE,
                                                 (LPDWORD)NULL,
                                                 &fmt_value);
            if (status == ERROR_SUCCESS) {
                break;
            }

            PdhCollectQueryData(h_query);
        }
    }
    else {
        status = PdhGetRawCounterValue(h_counter, &type, &raw_value);
    }

    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return 0;
    }

    if (fmt) {
        return fmt_value.doubleValue;
    }
    else {
        return (jdouble)raw_value.FirstValue;
    }
}
Ejemplo n.º 17
0
// Function name	: CPerfMon::UpdateValue
// Description	    : Updates the counter value for the counter in pCounter
// Return type		: BOOL ; false fail ; true success
// Argument         : PPDHCOUNTERSTRUCT pCounter
//
// R E V I S I O N S:
// DATE       PROGRAMMER      CHANGES
//
BOOL CPerfMon::UpdateValue(PPDHCOUNTERSTRUCT pCounter)
{
	PDH_FMT_COUNTERVALUE pdhFormattedValue;

	// get the value from the PDH
	if (PdhGetFormattedCounterValue(pCounter->hCounter, PDH_FMT_LONG, NULL, &pdhFormattedValue) != ERROR_SUCCESS)
		return false;

	// test the value for validity
	if (pdhFormattedValue.CStatus != ERROR_SUCCESS)
		return false;

	// set value
	pCounter->lValue = pdhFormattedValue.longValue;

	return true;
}
Ejemplo n.º 18
0
double getCpuLoad(){
    PDH_HCOUNTER Counter;
	DWORD dwType;
	PDH_FMT_COUNTERVALUE Value;
	double ret = 0;
	PDH_HQUERY cpu_load_query = NULL;
	
	if(PdhOpenQuery(NULL, 0, &cpu_load_query) == ERROR_SUCCESS) {
		if(PdhAddCounter(cpu_load_query, "\\Processor(_Total)\\% Processor Time", 0, &Counter) == ERROR_SUCCESS &&
		PdhCollectQueryData(cpu_load_query) == ERROR_SUCCESS &&
		PdhGetFormattedCounterValue(Counter, PDH_FMT_DOUBLE, &dwType, &Value) == ERROR_SUCCESS) {
			ret = (Value.doubleValue * getCpuNum()) / 100.0;
		}
		if (cpu_load_query) PdhCloseQuery(cpu_load_query);
	}
	return ret;
}
Ejemplo n.º 19
0
void SCTStatistics::CalculateCpuStats()
{
	PDH_FMT_COUNTERVALUE value; 

	if(mCanReadCpu)
	{
		if((mLastSampleTime + 1000) < GetTickCount())
		{
			mLastSampleTime = GetTickCount(); 

			PdhCollectQueryData(mQueryHandle);
        
			PdhGetFormattedCounterValue(mCounterHandle, PDH_FMT_LONG, NULL, &value);

			mCpuUsage = value.longValue;
		}
	}
}
Ejemplo n.º 20
0
uint64_t readFormattedCounter(char* path)
{
    PDH_HQUERY Query = NULL;
    PDH_HCOUNTER Counter;
	DWORD dwType;
	PDH_FMT_COUNTERVALUE Value;
	LONGLONG ret = 0;

    if(PdhOpenQuery(NULL, 0, &Query) == ERROR_SUCCESS) {
		if(PdhAddCounter(Query, path, 0, &Counter) == ERROR_SUCCESS && 
           PdhCollectQueryData(Query) == ERROR_SUCCESS &&
		   PdhGetFormattedCounterValue(Counter, PDH_FMT_LARGE, &dwType, &Value) == ERROR_SUCCESS) { 
			ret = Value.largeValue;
		}
		if (Query) PdhCloseQuery(Query);
    }
	return (uint64_t)ret;
}
Ejemplo n.º 21
0
bool TSmartServer::GetSysItemInfo(HQUERY	hQuery, 
								 char *pszPath, 
								 DWORD nType, 
								 PDH_FMT_COUNTERVALUE& fmtValue)
{
	DWORD dwType;
	HCOUNTER  hCounter ;
	if( PdhAddCounter(hQuery, pszPath, 0, &hCounter) != ERROR_SUCCESS )
		return false;

	if( PdhCollectQueryData(hQuery) != ERROR_SUCCESS )
		return false;

	if( PdhGetFormattedCounterValue(hCounter, nType, &dwType, &fmtValue) != ERROR_SUCCESS )
		return false;

	return true;
}
Ejemplo n.º 22
0
void DXFrame::CPUCounter::Update(DXManager* manager, Font* font)
{
	PDH_FMT_COUNTERVALUE value;
	if ((m_LastSampleTime + 1000) < GetTickCount64())
	{
		m_LastSampleTime = (unsigned long)GetTickCount64();
		PdhCollectQueryData(m_HandleQuery);
		PdhGetFormattedCounterValue(m_HandleCounter, PDH_FMT_LONG, NULL, &value);
		m_CPUUsage = (int)value.longValue;
		m_CPUText->SetText(manager, font, "CPU:" + std::to_string(m_CPUUsage) + "%");

		if (m_CPUUsage <= 30)
			m_CPUText->SetColor(D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f));
		else if (m_CPUUsage >= 30 && m_CPUUsage < 60)
			m_CPUText->SetColor(D3DXVECTOR4(1.0f, 1.0f, 0.0f, 0.9f));
		else if (m_CPUUsage >= 60)
			m_CPUText->SetColor(D3DXVECTOR4(1.0f, 0.0f, 0.0f, 0.9f));
	}
}
Ejemplo n.º 23
0
JNIEXPORT jdouble JNICALL Java_org_krakenapps_winapi_PerformanceCounter_nextValue(JNIEnv *env, jobject obj, jint queryHandle, jint counterHandle) {
	PDH_HQUERY phQuery = (PDH_HQUERY)queryHandle;
	PDH_HCOUNTER phCounter = (PDH_HCOUNTER)counterHandle;
	PDH_FMT_COUNTERVALUE pValue;
	PDH_STATUS stat = 0;

	stat = PdhCollectQueryData(phQuery);
	if(stat != ERROR_SUCCESS) {
		fprintf(stderr, "PdhCollectQueryData: 0x%x\n", stat);
		return 0;
	}

	stat = PdhGetFormattedCounterValue(phCounter, PDH_FMT_DOUBLE, NULL, &pValue);
	if(stat != ERROR_SUCCESS) {
		fprintf(stderr, "PdhGetFormattedCounterValue: 0x%x\n", stat);
		return 0;
	}

	return pValue.doubleValue;
}
Ejemplo n.º 24
0
// |----------------------------------------------------------------------------|
// |						        Frame										|
// |----------------------------------------------------------------------------|
void CpuClass::Frame()
{
	PDH_FMT_COUNTERVALUE value; 

	if(m_canReadCpu)
	{
		if((m_lastSampleTime + 1000) < GetTickCount())
		{
			m_lastSampleTime = GetTickCount(); 

			PdhCollectQueryData(m_queryHandle);
        
			PdhGetFormattedCounterValue(m_counterHandle, PDH_FMT_LONG, NULL, &value);

			m_cpuUsage = value.longValue;
		}
	}

	return;
}
Ejemplo n.º 25
0
void InfoCPU::Update()
{
	PDH_FMT_COUNTERVALUE value;

	if (mcanReadCpu)
	{
		if ((mlastSampleTime + 1000) < GetTickCount())
		{
			mlastSampleTime = GetTickCount();

			PdhCollectQueryData(mqueryHandle);

			PdhGetFormattedCounterValue(mcounterHandle, PDH_FMT_LONG, NULL, &value);

			mcpuUsage = value.longValue;
		}
	}

	return;
}
Ejemplo n.º 26
0
Status PerfCounterCollector::collectCounters(const std::vector<CounterInfo>& counters,
                                             BSONObjBuilder* builder) {
    for (const auto& counterInfo : counters) {

        DWORD dwType = 0;

        // Elapsed Time is an unusual counter in that being able to control the sample period for
        // the counter is uninteresting even though it is computed from two values. Just return the
        // computed value instead.
        if (counterInfo.type == PERF_ELAPSED_TIME) {
            PDH_FMT_COUNTERVALUE counterValue = {0};
            PDH_STATUS status = PdhGetFormattedCounterValue(
                counterInfo.handle, PDH_FMT_DOUBLE, &dwType, &counterValue);
            if (status != ERROR_SUCCESS) {
                return {ErrorCodes::WindowsPdhError,
                        formatFunctionCallError("PdhGetFormattedCounterValue", status)};
            }

            builder->append(counterInfo.firstName, counterValue.doubleValue);

        } else {

            PDH_RAW_COUNTER rawCounter = {0};
            PDH_STATUS status = PdhGetRawCounterValue(counterInfo.handle, &dwType, &rawCounter);
            if (status != ERROR_SUCCESS) {
                return {ErrorCodes::WindowsPdhError,
                        formatFunctionCallError("PdhGetRawCounterValue", status)};
            }

            if (counterInfo.hasSecondValue) {
                // Precise counters require the second value in the raw counter information
                builder->append(counterInfo.firstName, rawCounter.FirstValue);
                builder->append(counterInfo.secondName, rawCounter.SecondValue);
            } else {
                builder->append(counterInfo.firstName, rawCounter.FirstValue);
            }
        }
    }

    return Status::OK();
}
Ejemplo n.º 27
0
void CpuClass::Frame()
{
	PDH_FMT_COUNTERVALUE value; 

	if(m_canReadCpu)
	{
		// If it has been 1 second then update the current cpu usage and reset the 1 second timer again.
		if((m_lastSampleTime + 1000) < GetTickCount())
		{
			m_lastSampleTime = GetTickCount(); 

			PdhCollectQueryData(m_queryHandle);
        
			PdhGetFormattedCounterValue(m_counterHandle, PDH_FMT_LONG, NULL, &value);

			m_cpuUsage = value.longValue;
		}
	}

	return;
}
int DiskTimeMuninNodePlugin::GetValues(char *buffer, int len)
{
  PDH_STATUS status;
  PDH_FMT_COUNTERVALUE diskTimeValue;
  int printCount;

  status = PdhCollectQueryData(m_PerfQuery);
  if (status != ERROR_SUCCESS)
    return -1;
  
  for (size_t i = 0; i < m_DiskTimeCounters.size(); i++) {
    // Get the formatted counter value    
    status = PdhGetFormattedCounterValue(m_DiskTimeCounters[i], PDH_FMT_DOUBLE, NULL, &diskTimeValue);
    if (status != ERROR_SUCCESS)
      return -1;
    printCount = _snprintf(buffer, len, "disktime_%i_.value %.2f\n", i, diskTimeValue.doubleValue);
    len -= printCount;
    buffer += printCount;
  }
  strncat(buffer, ".\n", len);
  return 0;
}
Ejemplo n.º 29
0
int read_counter_double(pdh_enum counter, double *result)
{
	PDH_STATUS pdh_status;
	PDH_FMT_COUNTERVALUE *item_buf;
	HCOUNTER hcounter = current_han[counter];

	if(hcounter == NULL)
		return -1;

	item_buf = sg_malloc(sizeof(PDH_FMT_COUNTERVALUE));
	if (item_buf == NULL) {
		return -1;
	}

	pdh_status = PdhGetFormattedCounterValue(hcounter, PDH_FMT_DOUBLE, NULL,
			item_buf);
	if(pdh_status != ERROR_SUCCESS) {
		free(item_buf);
		return -1;
	}
	*result = item_buf->doubleValue;
	free(item_buf);
	return 0;
}
Ejemplo n.º 30
0
static BOOL
collect_profile(PDH_profile *prof)
{

	BOOL ret = FALSE;
	PDH_FMT_COUNTERVALUE counter_val;
	PDH_STATUS rval;

	__try {
		if ((rval=PdhCollectQueryData(prof->hQuery)) == ERROR_SUCCESS) {
			if (PdhGetFormattedCounterValue(prof->hCounter,
				PDH_FMT_LONG, NULL, &counter_val) == ERROR_SUCCESS) {
				if (counter_val.CStatus == ERROR_SUCCESS) {
					prof->value = counter_val.longValue;
					ret = TRUE;
				}
			}
		}
	}
	__except(EXCEPTION_EXECUTE_HANDLER) {
		ret = FALSE;
	}
	return (ret);
}