more monitor added.
This commit is contained in:
parent
c32d2fe4d7
commit
8f246d5bdb
|
@ -1,40 +1,46 @@
|
|||
#include "stdafx.h"
|
||||
#include "Monitor.h"
|
||||
|
||||
MONITOR_API double GetCpuUsage(int sleepTime)
|
||||
PDH_FMT_COUNTERVALUE GetCounterValue(wchar_t * fullCounterPath,unsigned long format)
|
||||
{
|
||||
PDH_STATUS status;
|
||||
HQUERY hquery;
|
||||
status=PdhOpenQuery(NULL,NULL,&hquery);
|
||||
if(status!=ERROR_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
PdhOpenQuery(NULL,NULL,&hquery);
|
||||
HCOUNTER counter=NULL;
|
||||
wchar_t * fullCounterPath=L"\\Processor(*)\\% Processor Time";
|
||||
PdhAddCounter(hquery, fullCounterPath, NULL, &counter);
|
||||
status = PdhCollectQueryData(hquery);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
Sleep(sleepTime);
|
||||
status = PdhCollectQueryData(hquery);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
PdhCollectQueryData(hquery);
|
||||
PDH_FMT_COUNTERVALUE counterValue;
|
||||
status = PdhGetFormattedCounterValue(counter,PDH_FMT_DOUBLE,NULL,&counterValue);
|
||||
if(status != ERROR_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
status = PdhCloseQuery(hquery);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return counterValue.doubleValue;
|
||||
PdhGetFormattedCounterValue(counter,format,NULL,&counterValue);
|
||||
PdhCloseQuery(hquery);
|
||||
return counterValue;
|
||||
}
|
||||
|
||||
PDH_FMT_COUNTERVALUE GetCounterValueWithSleep(wchar_t * fullCounterPath,unsigned long format,int sleepTime)
|
||||
{
|
||||
HQUERY hquery;
|
||||
PdhOpenQuery(NULL,NULL,&hquery);
|
||||
HCOUNTER counter=NULL;
|
||||
PdhAddCounter(hquery, fullCounterPath, NULL, &counter);
|
||||
PdhCollectQueryData(hquery);
|
||||
Sleep(sleepTime);
|
||||
PdhCollectQueryData(hquery);
|
||||
PDH_FMT_COUNTERVALUE counterValue;
|
||||
PdhGetFormattedCounterValue(counter,format,NULL,&counterValue);
|
||||
PdhCloseQuery(hquery);
|
||||
return counterValue;
|
||||
}
|
||||
|
||||
MONITOR_API double GetCpuUsage(int sleepTime)
|
||||
{
|
||||
wchar_t * fullCounterPath=L"\\Processor(*)\\% Processor Time";
|
||||
unsigned long format=PDH_FMT_DOUBLE;
|
||||
double ret=GetCounterValueWithSleep(fullCounterPath,format,sleepTime).doubleValue;
|
||||
return ret;
|
||||
}
|
||||
|
||||
MONITOR_API double GetFileReadBytesPerSecond(int sleepTime)
|
||||
{
|
||||
wchar_t * fullCounterPath=L"\\System\\File Read Bytes/sec";
|
||||
unsigned long format=PDH_FMT_DOUBLE;
|
||||
double ret=GetCounterValueWithSleep(fullCounterPath,format,sleepTime).doubleValue;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
#endif
|
||||
|
||||
MONITOR_API double GetCpuUsage(int sleepTime);
|
||||
MONITOR_API double GetFileReadBytesPerSecond(int sleepTime);
|
||||
|
|
|
@ -4,4 +4,5 @@
|
|||
#define MONITOR_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
MONITOR_API double GetCpuUsage(int sleepTime);
|
||||
MONITOR_API double GetCpuUsage(int sleepTime);
|
||||
MONITOR_API double GetFileReadBytesPerSecond(int sleepTime);
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#pragma comment(lib,"../x64/Debug/Monitor.lib")
|
||||
#pragma comment(lib,"../x64/Release/Monitor.lib")
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
|
|
@ -4,4 +4,5 @@
|
|||
#define MONITOR_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
MONITOR_API double GetCpuUsage(int sleepTime);
|
||||
MONITOR_API double GetCpuUsage(int sleepTime);
|
||||
MONITOR_API double GetFileReadBytesPerSecond(int sleepTime);
|
|
@ -3,8 +3,10 @@
|
|||
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
printf("%lf",GetCpuUsage(100));
|
||||
system("pause");
|
||||
while(1)
|
||||
{
|
||||
printf("%lf\n",GetFileReadBytesPerSecond(500));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#pragma comment(lib,"../x64/Debug/Monitor.lib")
|
||||
#pragma comment(lib,"../x64/Release/Monitor.lib")
|
||||
|
||||
#include <tchar.h>
|
||||
#include <iostream>
|
||||
|
|
Loading…
Reference in New Issue