本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5160822

转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8678382

欢迎关注微博:http://weibo.com/MoreWindows

 

Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率 C#

http://blog.csdn.net/morewindows/article/details/8678382

 

    前面《Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率》介绍了在Windows XPWindows 7系统下获取CPU整体使用率,而目前大多数CPU都是多核CPU,因此本文来介绍如何获取多核CPU下各核的使用率

Windows系统CPU内存网络性能统计博客目录:

1Windows系统CPU内存网络性能统计第一篇内存

http://blog.csdn.net/morewindows/article/details/8459219

2Windows系统CPU内存网络性能统计第二篇 CPU CPU整体使用率

http://blog.csdn.net/morewindows/article/details/8678359

3Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率 C#

http://blog.csdn.net/morewindows/article/details/8678382

4Windows系统CPU内存网络性能统计第四篇 CPU多核CPU各核使用率 C++

http://blog.csdn.net/morewindows/article/details/8678396

 

使用C#来获取多核CPU下各核的使用率是非常方便的。短短几行就能搞定,并且程序能正常运行于Windows XPWindows 7系统中。下面先给出代码。

//Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率 C#// 经过测试,可以在WinXP及Win7下使用//http://blog.csdn.net/morewindows/article/details/8678382using System;using System.Diagnostics;using System.Threading;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            Console.WriteLine("    Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率 C#");            Console.WriteLine(" - http://blog.csdn.net/morewindows/article/details/8678382 -");            Console.WriteLine(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n");             PerformanceCounter[] counters = new PerformanceCounter[ System.Environment.ProcessorCount ];             for(int i = 0; i < counters.Length; i++)                    {                            counters[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString());             }                    while(true)                    {                          for(int i = 0; i < counters.Length; i++)                       {                                 float f = counters[i].NextValue();                       Console.Write("CPU-{0}: {1:f}%  ", i + 1, f);                     }                          Console.WriteLine();                        Thread.Sleep(1000);                   }           }    }}

由代码可以看出,主要是使用了System.Diagnostics中的PerformanceCounter类。这个类的功能强大,可以查阅MSDN得到详细解释。

 

WinXP系统运行结果如下(本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5160822):

 Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率C

Win7系统运行结果如下(本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5160822):

 Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率C

由本篇《Windows系统CPU内存网络性能统计第三篇 CPU 多核CPU各核使用率 C#》(http://blog.csdn.net/morewindows/article/details/8678382)可以看出,C#无疑是一门很方便的语言,对C/C++程序员来说,了解下C#是非常有帮助的。

下一篇《Windows系统CPU内存网络性能统计第四篇 CPU多核CPU各核使用率 C++》(http://blog.csdn.net/morewindows/article/details/8678396)将介绍使用C++代码来引用C#编写的DLL来完成在C++下获取多核CPU各核使用率。

 

本文配套程序下载地址为:http://download.csdn.net/detail/morewindows/5160822

转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8678382

欢迎关注微博:http://weibo.com/MoreWindows


 

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
  • 2021-05-16
  • 2022-02-11
  • 2021-12-28
  • 2022-12-23
  • 2021-11-13
猜你喜欢
  • 2022-01-20
  • 2021-10-25
  • 2021-07-11
  • 2022-12-23
  • 2021-05-09
相关资源
相似解决方案