Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Diagnostics / ServiceModelPerformanceCounters.cs / 1 / ServiceModelPerformanceCounters.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Diagnostics { using System; using System.ServiceModel; using System.ServiceModel.Dispatcher; using System.ServiceModel.Description; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Diagnostics; using System.Globalization; using System.Runtime.Remoting.Messaging; using System.ServiceModel.Channels; using System.ServiceModel.Configuration; using System.ServiceModel.Diagnostics; using System.Text; using System.Xml; internal class ServiceModelPerformanceCounters { DictionaryoperationPerfCounters; SortedList actionToOperation; EndpointPerformanceCounters endpointPerfCounters; ServicePerformanceCounters servicePerfCounters; DefaultPerformanceCounters defaultPerfCounters; bool initialized; string perfCounterId; internal ServiceModelPerformanceCounters( ServiceHostBase serviceHost, ContractDescription contractDescription, EndpointDispatcher endpointDispatcher) { this.perfCounterId = endpointDispatcher.PerfCounterId; if (PerformanceCounters.Scope == PerformanceCounterScope.All) { this.operationPerfCounters = new Dictionary (contractDescription.Operations.Count); this.actionToOperation = new SortedList (contractDescription.Operations.Count); foreach (OperationDescription opDescription in contractDescription.Operations) { DiagnosticUtility.DebugAssert(null != opDescription.Messages, "OperationDescription.Messages should not be null"); DiagnosticUtility.DebugAssert(opDescription.Messages.Count > 0, "OperationDescription.Messages should not be empty"); DiagnosticUtility.DebugAssert(null != opDescription.Messages[0], "OperationDescription.Messages[0] should not be null"); if (null != opDescription.Messages[0].Action && !this.actionToOperation.Keys.Contains(opDescription.Messages[0].Action)) { this.actionToOperation.Add(opDescription.Messages[0].Action, opDescription.Name); } OperationPerformanceCounters c; if (!this.operationPerfCounters.TryGetValue(opDescription.Name, out c)) { OperationPerformanceCounters counters = new OperationPerformanceCounters(serviceHost.Description.Name, contractDescription.Name, opDescription.Name, endpointDispatcher.PerfCounterBaseId); if (counters.Initialized) { this.operationPerfCounters.Add(opDescription.Name, counters); } else { // cleanup the others and return. this.ReleasePerformanceCounters(); this.initialized = false; return; } } } // add endpoint scoped perf counters EndpointPerformanceCounters endpointCounters = new EndpointPerformanceCounters(serviceHost.Description.Name, contractDescription.Name, endpointDispatcher.PerfCounterBaseId); if (endpointCounters.Initialized) { this.endpointPerfCounters = endpointCounters; } } if (PerformanceCounters.PerformanceCountersEnabled) { this.servicePerfCounters = serviceHost.Counters; } if (PerformanceCounters.MinimalPerformanceCountersEnabled) { this.defaultPerfCounters = serviceHost.DefaultCounters; } this.initialized = true; } internal OperationPerformanceCounters GetOperationPerformanceCountersFromMessage(Message message) { DiagnosticUtility.DebugAssert(null != message, "message must not be null"); DiagnosticUtility.DebugAssert(null != message.Headers, "message headers must not be null"); DiagnosticUtility.DebugAssert(null != message.Headers.Action, "action must not be null"); string operation; if (this.actionToOperation.TryGetValue(message.Headers.Action, out operation)) { return this.GetOperationPerformanceCounters(operation); } else { return null; } } internal OperationPerformanceCounters GetOperationPerformanceCounters(string operation) { DiagnosticUtility.DebugAssert(PerformanceCounters.Scope == PerformanceCounterScope.All, "Only call GetOparationPerformanceCounters when performance counter scope is All"); OperationPerformanceCounters counters; Dictionary opPerfCounters = this.operationPerfCounters; if (opPerfCounters != null && opPerfCounters.TryGetValue(operation, out counters)) { return counters; } return null; } internal bool Initialized { get { return this.initialized; } } internal EndpointPerformanceCounters EndpointPerformanceCounters { get { return this.endpointPerfCounters; } } internal ServicePerformanceCounters ServicePerformanceCounters { get { return this.servicePerfCounters; } } internal DefaultPerformanceCounters DefaultPerformanceCounters { get { return this.defaultPerfCounters; } } internal string PerfCounterId { get { return this.perfCounterId; } } internal void ReleasePerformanceCounters() { if (PerformanceCounters.Scope == PerformanceCounterScope.All) { if (this.operationPerfCounters != null) { try { IDictionaryEnumerator e = this.operationPerfCounters.GetEnumerator(); while (e.MoveNext()) { OperationPerformanceCounters op = (OperationPerformanceCounters)e.Value; op.ReleasePerformanceCounters(); } } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (ExceptionUtility.IsFatal(e)) throw; if (DiagnosticUtility.ShouldTraceError) TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PerformanceCountersFailedOnRelease, null, e); } this.operationPerfCounters.Clear(); this.operationPerfCounters = null; } if (this.endpointPerfCounters != null) { this.endpointPerfCounters.ReleasePerformanceCounters(); this.endpointPerfCounters = null; } } // ServicePerformanceCounters will be released by ServiceHost this.servicePerfCounters = null; this.defaultPerfCounters = null; } } internal class ServiceModelPerformanceCountersEntry { ServicePerformanceCounters servicePerformanceCounters; DefaultPerformanceCounters defaultPerformanceCounters; List performanceCounters; public ServiceModelPerformanceCountersEntry(ServicePerformanceCounters serviceCounters) { this.servicePerformanceCounters = serviceCounters; this.performanceCounters = new List (); } public ServiceModelPerformanceCountersEntry(DefaultPerformanceCounters defaultServiceCounters) { this.defaultPerformanceCounters = defaultServiceCounters; this.performanceCounters = new List (); } public void Add(ServiceModelPerformanceCounters counters) { this.performanceCounters.Add(counters); } public void Remove(string id) { for (int i = 0; i < this.performanceCounters.Count; ++i) { if (this.performanceCounters[i].PerfCounterId.Equals(id)) { this.performanceCounters.RemoveAt(i); break; } } } public void Clear() { this.performanceCounters.Clear(); } public ServicePerformanceCounters ServicePerformanceCounters { get { return this.servicePerformanceCounters; } set { this.servicePerformanceCounters = value; } } public DefaultPerformanceCounters DefaultPerformanceCounters { get { return this.defaultPerformanceCounters; } set { this.defaultPerformanceCounters = value; } } public List CounterList { get { return this.performanceCounters; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- NominalTypeEliminator.cs
- BuildDependencySet.cs
- HelloOperationAsyncResult.cs
- ConfigurationStrings.cs
- IndexerHelper.cs
- ContainerVisual.cs
- StatusBar.cs
- ImportedNamespaceContextItem.cs
- DescendantOverDescendantQuery.cs
- SmtpException.cs
- DataGridViewTopRowAccessibleObject.cs
- HttpCapabilitiesSectionHandler.cs
- CompiledQueryCacheKey.cs
- MarkupExtensionParser.cs
- VideoDrawing.cs
- Listbox.cs
- CacheEntry.cs
- AsyncStreamReader.cs
- odbcmetadatacolumnnames.cs
- TextTreeTextElementNode.cs
- WindowsMenu.cs
- SecurityDocument.cs
- SqlTriggerContext.cs
- ElementHostAutomationPeer.cs
- PerformanceCounterLib.cs
- ReadOnlyHierarchicalDataSource.cs
- NumberAction.cs
- ChangeProcessor.cs
- RC2.cs
- MulticastNotSupportedException.cs
- SessionSwitchEventArgs.cs
- Part.cs
- CryptoConfig.cs
- OdbcParameter.cs
- CheckBoxPopupAdapter.cs
- RuntimeResourceSet.cs
- LogArchiveSnapshot.cs
- RadioButtonBaseAdapter.cs
- Int32Animation.cs
- ICspAsymmetricAlgorithm.cs
- SqlUtils.cs
- StylusSystemGestureEventArgs.cs
- ClosableStream.cs
- ConnectionPoint.cs
- CryptoKeySecurity.cs
- ProfileEventArgs.cs
- MsmqEncryptionAlgorithm.cs
- CreateUserWizardStep.cs
- SqlBuilder.cs
- ControlTemplate.cs
- _NegoStream.cs
- KeyValuePair.cs
- XmlDataSourceView.cs
- AutoGeneratedFieldProperties.cs
- TextDecoration.cs
- WizardPanel.cs
- Timeline.cs
- ResourceBinder.cs
- ScriptResourceInfo.cs
- UiaCoreApi.cs
- HMACMD5.cs
- PropertyTabChangedEvent.cs
- FontFamilyIdentifier.cs
- InputLangChangeEvent.cs
- TabletDeviceInfo.cs
- CategoryGridEntry.cs
- BindingNavigatorDesigner.cs
- ContextMenuService.cs
- Executor.cs
- WebServicesInteroperability.cs
- TextRangeProviderWrapper.cs
- ComPlusContractBehavior.cs
- UnSafeCharBuffer.cs
- MultipleCopiesCollection.cs
- Viewport3DVisual.cs
- BookmarkScopeInfo.cs
- HttpEncoderUtility.cs
- _DigestClient.cs
- BaseParaClient.cs
- TokenBasedSetEnumerator.cs
- DropTarget.cs
- MasterPageCodeDomTreeGenerator.cs
- SchemaContext.cs
- PolicyVersionConverter.cs
- TypeConstant.cs
- NativeMethodsCLR.cs
- InputGestureCollection.cs
- GcHandle.cs
- SqlDataSourceConfigureFilterForm.cs
- IndexedEnumerable.cs
- SQLBytes.cs
- securestring.cs
- UrlPath.cs
- MsmqBindingFilter.cs
- JsonByteArrayDataContract.cs
- TableCell.cs
- CompilerErrorCollection.cs
- SubMenuStyle.cs
- LassoHelper.cs
- SettingsAttributes.cs