例子:
PID=0,缺省为当前进程,但最好是获取当前进程ID传递进去,当然也可以选择其它进程的ID。
PerformanceCounter pc;
pc.Open(0, "//Processor(_Total)//% Processor Time");
源实现:
#include <windows.h>
#include <pdh.h>
class PerformanceCounter
{
public:
PerformanceCounter() noexcept;
virtual ~PerformanceCounter() noexcept;
public:
virtual double Next() noexcept;
virtual void Open(int pid, LPCSTR counter);
virtual void Dispose() noexcept;
private:
void Release() noexcept;
private:
std::atomic<void*> m_phQuery = NULL;
std::atomic<void*> m_phCounter = NULL;
};
PerformanceCounter::PerformanceCounter() noexcept
: m