简单的创建一个性能计数器

  

<强>一、性能监控的作用

,,,,,,,,性能监控可以用于获取关于应用程序的正常行为的一般消息,性能监控是一个强大的工具,有助于理解系统的工作负载,观察变化和趋势,尤其是运行在服务器上的应用程序

,

<强>二、性能监控类(系统。诊断):
PerformanceCounter类:监控计数与写入计数。还可以使用这个类创建新的性能类别
PerformanceCounterCategory类:可以查看所有的已有的类别,以及创建类别。可以以编程的方式获得一个类别中的所有计数器
performanceCounterInstall类:用于安装性能计数器

,

,

三、创建性能类别(两种创建方式):

1,图形化创建:

简单的创建一个性能计数器

简单的创建一个性能计数器

,

2代码创建+操作(可以监控不同应用程序的性能计数):

简单的创建一个性能计数器

, using 系统;   using  System.Collections.Generic;   using  System.ComponentModel;   using  System.Data;   using  System.Drawing;   using 来;   using 包含;   using  System.Threading.Tasks;   using  System.Windows.Forms;   using  System.Windows.Threading;   using  System.Diagnostics;   namespace  PerformanceCountTest2   {   ,,,public  partial  class  Form1 :形式   ,,,{   ,,,,,,,//性能计数器的实例名称   ,,,,,,,private  const  string  _NewPerformanceCounterName =,“PerformanceCountTest2”;   ,,,,,,,//性能计数器的类型名称   ,,,,,,,private  const  string  _PerformanceCounterCategoryName =,“MyZhangDi”;   ,,,,,,,//性能计数器名称   ,,,,,,,private  SortedList<字符串,Tuple<字符串,string>祝辞,_PerformanceCounterNames;   ,,,,,,,//- - - - - -性能计数器(组件)   ,,,,,,,//记录按钮点击的次数   ,,,,,,,private  PerformanceCounter  buttonClickCount;   ,,,,,,,//记录按钮每秒点击的次数   ,,,,,,,private  PerformanceCounter  buttonClickCountSec;   ,,,,,,,//存放按钮每秒点击的次数的变量   ,,,,,,,private  int  Record_buttonClickCount =, 0;   ,,,,,,,//初始化性能计数器名称   ,,,,,,,private  void  InitialziePerformanceCounterNames ()   ,,,,,,,{   ,,,,,,,,,,,_PerformanceCounterNames =, new  SortedList<字符串,Tuple<字符串,string>在();   ,,,,,,,,,,,_PerformanceCounterNames.Add (“buttonClickCount”, Tuple.Create (“buttonClickCount”,“记录按钮点击的次数"));   ,,,,,,,,,,,_PerformanceCounterNames.Add (“buttonClickCountSec”, Tuple.Create (“buttonClickCountSec”,“记录按钮每秒点击的次数"));   ,,,,,,,}   ,,,,,,,//初始化性能计数器(组件)   ,,,,,,,private  void  InitializePerformanceCounter ()   ,,,,,,,{   ,,,,,,,,,,,buttonClickCount =new  PerformanceCounter   ,,,,,,,,,,,{   ,,,,,,,,,,,,,,,CategoryName =, _PerformanceCounterCategoryName,//性能计数器类型名称   ,,,,,,,,,,,,,,,CounterName =, _PerformanceCounterNames“buttonClickCount .Item1,//性能计数器名称   ,,,,,,,,,,,,,,,MachineName =,“。”,//本地计算机   ,,,,,,,,,,,,,,,InstanceLifetime =, PerformanceCounterInstanceLifetime.Process,//生命周期   ,,,,,,,,,,,,,,,ReadOnly =,假的,//可写   ,,,,,,,,,,,,,,,InstanceName =, _NewPerformanceCounterName//实例名称   ,,,,,,,,,,,};   ,,,,,,,,,,,buttonClickCountSec =new  PerformanceCounter   ,,,,,,,,,,,{   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

简单的创建一个性能计数器