作者: 大数据观察来源: 大数据观察时间:2017-02-28 12:36:330
本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5160810
转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8678359
欢迎关注微博:http://weibo.com/MoreWindows
上一篇《Windows系统CPU内存网络性能统计第一篇内存》(http://blog.csdn.net/morewindows/article/details/8459219)介绍了在Windows系统下如何查看系统内存总量,使用率等信息。接下在将用三篇博客来介绍如何获取CPU整体使用率及多核CPU各核的使用率。
Windows系统CPU内存网络性能统计博客目录:
1.《Windows系统CPU内存网络性能统计第一篇内存》
http://blog.csdn.net/morewindows/article/details/8459219
2.《Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率》
http://blog.csdn.net/morewindows/article/details/8678359
3.《Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率 C#》
http://blog.csdn.net/morewindows/article/details/8678382
4.《Windows系统CPU内存网络性能统计第四篇 CPU多核CPU各核使用率 C++》
http://blog.csdn.net/morewindows/article/details/8678396
如何获取CPU整体使用率及多核CPU各核的使用率在网上已经有很多文章了,在各大论坛上也有很多人在提问。本人在网上搜索了下,之前很多文章都是介绍使用ntdll.dll中一个未公开的API函数——NtQuerySystemInformation。基本代码结构如下:
// 获得系统CPU使用率 By MoreWindows( http://blog.csdn.net/MoreWindows )
typedef LONG (WINAPI *PROCNTQSI)(UINT, PVOID, ULONG, PULONG);
pFunNtQuerySystemInf = (PROCNTQSI)GetProcAddress(GetModuleHandle("ntdll"), "NtQuerySystemInformation");
这种方法肯定不太好,这个API函数既然未公开,那么说明微软公司不支持开发应用程序时直接使用这个函数,并且在以后的系统升级中ntdll.dll很可能去掉这个API函数。经过本人MoreWindows(http://weibo.com/MoreWindows)的实地测试,这种使用NtQuerySystemInformation的程序在Win7下都无法获取CPU使用率。
为了让我们的代码能在WinXP及Win7多系统中正常运行。本人实现了一个CCPUUseRate类。下面是这个CCPUUseRate类的实现代码:
// 获得系统CPU使用率 // http://blog.csdn.net/morewindows/article/details/8678359 // By MoreWindows( http://blog.csdn.net/MoreWindows ) // 先调用Initialize(),然后while(true)
在WinXP系统运行结果如下(本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5160810):
在Win7系统运行结果如下(本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5160810):
本文《Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率》(http://blog.csdn.net/morewindows/article/details/8678359)介绍的是如何获取CPU的整体使用率,现大多为多核的CPU,因此如何获取多核CPU各核的使用率了。请看下面二篇——
3.Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率 C#
http://blog.csdn.net/morewindows/article/details/8678382
4.Windows系统CPU内存网络性能统计第四篇 CPU多核CPU各核使用率 C++
http://blog.csdn.net/morewindows/article/details/8678396
本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5160810
转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8678359
欢迎关注微博:http://weibo.com/MoreWindows
永洪科技
致力于打造全球领先的数据技术厂商