欢迎来到天天文库
浏览记录
ID:41033143
大小:103.00 KB
页数:7页
时间:2019-08-14
《C#高级编程性能监视》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、·性能监视可以用于获取正常运行的服务的信息。性能监视是一个很好的工具,它能帮助我们了解系统的工作负荷,观察变化及趋势。Windows2000有许多性能对象,例如System、Memory、Objects、Process、Processor、Thread和Cache等。这些对象都有许多的监视点。例如,使用Process对象,可以监视所有进程或某一具体进程的用户时间、句柄数、页错误和线程数等。一些应用程序也添加具体的对象,例如SQLServer。对于QuoteService示例应用程序而言,要获取的信息是客户请求的数量和通过网络发送的数据有多少等。1.性能监视类S
2、ystem.Diagnostics命名空间中包含下述性能监视类:●PerformanceCounter类可以用于监视数量和编写数量。此外,使用这个类还可以创建新的性能种类。●使用PerformanceCounterCategory可以遍历所有现有的种类并创建新的种类。可以编程获取种类的记数器。●PerformanceCounterInstaller类用于性能记数器的安装。这个类的用法与前面的EventLogInstaller相似。2.PerformanceCounterBuilder要创建新的性能记数器种类,可以选择ServerExplorer中的性能记数器,
3、再在弹出的菜单中选择菜单项CreateNewCategory…,这将启动PerformanceCounterBuilder,如图32-25所示。图 32-25把性能记数器种类设置为QuoteService。表32-6中给出了服务的所有性能记数器。表 32-6名 称描 述类 型#ofBytessent发送给客户机的#字节总量NumberOfItems32#ofBytessent/sec一秒内发送给客户机的#字节NumberOfItems32#ofRequests请求的总数#NumberOfItems32#ofRequests/sec一秒内请求的总数#Number
4、OfItems32PerformanceCounterBuilder把配置写到性能数据库中。使用System.Diagnostics命名空间中PerformanceCategory类的Create()方法,可以动态地把配置写到性能数据库中。使用VisualStudio.NET,可以在以后为其他系统添加安装程序。3.添加PerformanceCounter组件接下来,要从工具箱中添加PerformanceCounter组件。这里不使用工具箱的种类组件,而是直接把前面创建的性能计数从ServerExplorer拖放到设计视图上。这样实例会自动配置:所有对象的Cat
5、egoryName属性都设置为QuoteServiceCount,CounterName属性设置为选中种类中的一个可用值。这个应用程序不是读取性能计数,而是写入,所以必须把ReadOnly属性设置为false。privatevoidInitializeComponent(){ //... //performanceCounterRequestsPerSec // this.performanceCounterRequestsPerSec.CategoryName="QuoteServiceCounts"; this.performanceCounterRequ
6、estsPerSec.CounterName="#ofRequests/sec"; this.performanceCounterBytesSentTotal.MachineName="NAGELC" this.performanceCounterRequestsPerSec.ReadOnly=false; // //performanceCounterBytesSentTotal // this.performanceCounterBytesSentTotal.CategoryName="QuoteServiceCounts"; this.performan
7、ceCounterBytesSentTotal.CounterName="#ofBytessent"; this.performanceCounterBytesSentTotal.MachineName="NAGELC" this.performanceCounterBytesSentTotal.ReadOnly=false; // //performanceCounterBytesSentPerSec // this.performanceCounterBytesSentPerSec.CategoryName="QuoteServiceCounts"; th
8、is.performanceCount
此文档下载收益归作者所有