詳細(xì)概論WCF性能計(jì)數(shù)器啟用問題
WCF框架是一個(gè)比較復(fù)雜的開發(fā)工具,我們需要從實(shí)踐中不斷的去探索其中的功能應(yīng)用。其中WCF性能計(jì)數(shù)器是一個(gè)可以幫助我們衡量應(yīng)用程序性能的集合。#t#
您可以通過 WCF 服務(wù)的 app.config 配置文件啟用WCF性能計(jì)數(shù)器,如下所示:
- < configuration>
- < system.serviceModel>
- < diagnostics performance
Counters="All" /> - < /system.serviceModel>
- < /configuration>
可以將 performanceCounters 屬性設(shè)置為啟用特定類型的性能計(jì)數(shù)器。有效值為
All:?jiǎn)⒂盟蓄悇e計(jì)數(shù)器(ServiceModelService、ServiceModelEndpoint 和 ServiceModelOperation)。
ServiceOnly:僅啟用 ServiceModelService 類別計(jì)數(shù)器。
Off:禁用 ServiceModel* 性能計(jì)數(shù)器。這是默認(rèn)值。
如果要啟用所有WCF性能計(jì)數(shù)器,則可以將配置設(shè)置放置到 Machine.config 文件中。有關(guān)在計(jì)算機(jī)上為性能計(jì)數(shù)器配置足夠內(nèi)存的更多信息,請(qǐng)參見“增加性能計(jì)數(shù)器的內(nèi)存大小”(可能為英文網(wǎng)頁)一節(jié)。
還可以在代碼中啟用WCF性能計(jì)數(shù)器,如下所示:
- using System.Configuration;
- using System.ServiceModel.
Configuration;- using System.ServiceModel.
Diagnostics;- Configuration config =
ConfigurationManager.OpenExe
Configuration(- ConfigurationUserLevel.None);
- ServiceModelSectionGroup sg =
ServiceModelSectionGroup.
GetSectionGroup(config);- sg.Diagnostic.PerformanceCounters =
PerformanceCounterScope.All;- config.Save();