C#高级编程性能监视.doc
上传人:qw****27 上传时间:2024-09-12 格式:DOC 页数:7 大小:103KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

C#高级编程性能监视.doc

C#高级编程性能监视.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

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