资源简介
《Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率》
http://blog.csdn.net/morewindows/article/details/8678359
配套程序。
讲解了在Windows系统下使用VC++获取系统CPU整体使用率。已经测试,能运行于WinXP和Win7系统。

代码片段和文件信息
//Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率
// 经过测试,可以在WinXP及Win7下使用
//http://blog.csdn.net/morewindows/article/details/8678359
#include
#include
#include
// 获得系统CPU使用率
// http://blog.csdn.net/morewindows/article/details/8678359
// By MoreWindows( http://blog.csdn.net/MoreWindows )
// 先调用Initialize(),然后while(true){Sleep(1000);GetCPUUseRate();}就能获得CPU使用率。
// 经过测试,可以在WinXP及Win7下使用。
class CCPUUseRate
{
public:
BOOL Initialize()
{
FILETIME ftIdle ftKernel ftUser;
BOOL flag = FALSE;
if (flag = GetSystemTimes(&ftIdle &ftKernel &ftUser))
{
m_fOldCPUIdleTime = FileTimeToDouble(ftIdle);
m_fOldCPUKernelTime = FileTimeToDouble(ftKernel);
m_fOldCPUUserTime = FileTimeToDouble(ftUser);
}
return flag;
}
//调用Initialize后要等待1秒再调用此函数
int GetCPUUseRate()
{
int nCPUUseRate = -1;
FILETIME ftIdle ftKernel ftUser;
if (GetSystemTimes(&ftIdle &ftKernel &ftUser))
{
double fCPUIdleTime = FileTimeToDouble(ftIdle);
double fCPUKernelTime = FileTimeToDouble(ftKernel);
double fCPUUserTime = FileTimeToDouble(ftUser);
nCPUUseRate= (int)(100.0 - (fCPUIdleTime - m_fOldCPUIdleTime)
/ (fCPUKernelTime - m_fOldCPUKernelTime + fCPUUserTime - m_fOldCPUUserTime)
*100.0);
m_fOldCPUIdleTime = fCPUIdleTime;
m_fOldCPUKernelTime = fCPUKernelTime;
m_fOldCPUUserTime = fCPUUserTime;
}
return nCPUUseRate;
}
private:
double FileTimeToDouble(FILETIME &filetime)
{
return (double)(filetime.dwHighDateTime * 4.294967296E9) + (double)filetime.dwLowDateTime;
}
private:
double m_fOldCPUIdleTime;
double m_fOldCPUKernelTime;
double m_fOldCPUUserTime;
};
int main()
{
printf(“ Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\n“);
printf(“ - http://blog.csdn.net/morewindows/article/details/8678359 -\n“);
printf(“ -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n“);
CCPUUseRate cpuUseRate;
if (!cpuUseRate.Initialize())
{
printf(“Error! %d\n“ GetLastError());
getch();
return -1;
}
else
{
while (true)
{
Sleep(1000);
printf(“\r当前CPU使用率为:%4d%%“ cpuUseRate.GetCPUUseRate());
}
}
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 473600 2013-03-16 18:58 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\Debug\GetCPU.exe
文件 2292 2013-03-16 18:58 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\GetCPU.cpp
文件 877 2012-12-29 16:57 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\GetCPU.sln
..A..H. 10240 2013-03-16 18:58 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\GetCPU.suo
文件 4841 2012-12-29 16:57 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\GetCPU.vcproj
文件 1425 2013-03-16 18:58 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\GetCPU.vcproj.MoreWindows_ex.Administrator.user
文件 65536 2013-03-16 18:58 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\Release\GetCPU.exe
目录 0 2013-03-16 18:58 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\Debug
目录 0 2013-03-16 18:58 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率\Release
目录 0 2013-03-16 18:58 Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率
文件 65536 2013-03-16 18:58 GetCPU.exe
文件 744 2013-03-20 10:16 ReadMe.txt
----------- --------- ---------- ----- ----
625091 12
- 上一篇:计算机图形学 课程设计 作业
- 下一篇:操作系统电梯调度算法
相关资源
- VC++ 多线程文件读写操作
- 移木块游戏,可以自编自玩,vc6.0编写
- VC++MFC小游戏实例教程(实例)+MFC类库
- VC++实现CMD命令执行与获得返回信息
- Qt5串口通信-windows
- 新编Windows API参考大全.doc
- windows hook 框架(detours )
- 获取pc上所有网卡信息
- windows网络编程_文件传输
- VC++基于OpenGL模拟的一个3维空间模型
- Windows扩展命令程序(源码)
- LabwindowsCVI 串口编程及事例.docx
- 基于VC++的SolidWorks二次开发SolidWorks
- Windows_API_函数大全 C/C++
- 派克变换VC++源码(附文档)
- VC++ 串口
- VC++ 大富翁4_大富翁游戏源码
- VC++ 摄像头视频采集与回放源程序
- 转 VC++ 实现电子邮件(Email)发送
- 基于MFC的VC++仿QQ浏览器源码(雏形)
- VC++ 服务程序编写及安装与卸载
- VC++6.0番茄西红柿VAXvirsual assist X完美破
- 基于改进的fcm算法的图像分割vc++
- VC++6.0 绿色版,免安装,非常好用。
- Microsoft Visual C++ 2005 Redistributable Pack
- VC++MFC课程设计的学生成绩管理系统
- 大智慧365DLL插件设计
- VC++6.0汉化包
- VC++完整商业界面源码(再上传)
- VC++编程技术600个大型项目源码.rar
评论
共有 条评论