CPU使用率:
int GetProcessInfo::GetProcessNumber()
{
SYSTEM_INFO info;
GetSystemInfo(&info);
return (int)info.dwNumberOfProcessors;
}
// 时间格式转换
__int64 GetProcessInfo::FileTimeToInt64(const FILETIME& time)
{
ULARGE_INTEGER tt;
tt.LowPart = time.dwLowDateTime;
tt.HighPart = time.dwHighDateTime;
return(tt.QuadPart);
}
double GetProcessInfo::get_cpu_usage()
{
//cpu数量
static int processor_count_ = -1;
//上一次的时间
static __int64 last_time_ = 0;
static __int64 last_system_time_ = 0;
FILETIME now;
FILETIME creation_time;
FILETIME exit_time;
FILETIME kernel_time;
FILETIME user_time;
__int64 system_time;
__int64 time;
// __int64 system_time_delta;
// __int64 time_delta;
double cpu = -1;
if(processor_count_ == -1)
{
processor_count_ = GetProcessNumber();
}
GetSystemTimeAsFileTime(&now);
HANDLE hProcess = OpenProcess(PROCESS_Q