如何获取某个进程的cpu时间?即任务管理器中,进程页面有一栏叫“cpu时间”,请问该如何获得?
解决方案 »
- 为什么总是Ex APIs are not present
- AfxBeginThread启动线程数量的问题
- 在有限的时间内,研究VC++,mfcgeng更有价值还是学习C#更有价值?
- ADO 操作Access数据库问题
- 受不了了,用VC2005总是"正在更新Intellsense"...
- 请问:下面的构造函数到底怎么匹配?
- 困惑?怎么通过已经连接到的客户IE的SOCKET象IE发送?
- 如何修改sybase数据库的表结构
- 介绍本了解IE内部工作原理的书吧,主要想知道IE内部如何使用 IHTML打头的众多COM对象
- 我是初学者请问声明和定义有什么区别 谢谢
- 请教公用体的详细用法???
- 在treectrl的click事件中,执行GetSelectedItem,得到的都是上次选中的Item?
status = NtQuerySystemInformation(3,&SysTimeInfo,sizeof(SysTimeInfo),0);
if (status!=NO_ERROR)
{
MessageBox("failed to get system time!");
} // get cpu idle time
status = NtQuerySystemInformation(2,&SysPerfInfo,sizeof(SysPerfInfo),NULL);
if (status != NO_ERROR)
{
MessageBox("failed to get cpu time");
}
if (liOldIdleTime.QuadPart != 0)
{
// new cpu Time = NewTime - OldTime
dbCpuIdleTime =LI64ToDouble(SysPerfInfo.liIdleTime)-LI64ToDouble(liOldIdleTime);
dbSysTime =LI64ToDouble(SysTimeInfo.liKeSystemTime)-LI64ToDouble(liOldSysTime);
//get cpu usage
unCpuUsage=100 - 100*(dbCpuIdleTime/dbSysTime)/(double)SysBaseInfo.bKeNumberProcessors+0.5;
} wsprintf(CpuUsage,"%d%%",(UINT)unCpuUsage);
m_sCpuUsage=(CString)CpuUsage; //if cpu usage ==0% then shutdown os
if(bSetAuto&&(UINT)dbCpuIdleTime==0)
{
//MessageBox("shutdown os!");
ShutDown();
}
// store new cpu idle and system time
liOldIdleTime = SysPerfInfo.liIdleTime;
liOldSysTime = SysTimeInfo.liKeSystemTime;
另:GetProcessTimes不能取到cpu时间,
BOOL GetProcessTimes(
HANDLE hProcess, // specifies the process of interest
LPFILETIME lpCreationTime, // when the process was created
LPFILETIME lpExitTime, // when the process exited
LPFILETIME lpKernelTime, // time the process has spent in kernel
// mode
LPFILETIME lpUserTime // time the process has spent in user mode
);
那么取得使用的时间有什么意思呢
只有在巨型或大型机上,按照CPU的资源使用率来计算才是有意义的呀(用来计算费用)
不是吗?