Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / SMSvcHost / System / ServiceModel / Activation / Diagnostics / ListenerPerfCounters.cs / 1 / ListenerPerfCounters.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Activation.Diagnostics { using System; using System.Collections.Generic; using System.Diagnostics; using System.ServiceModel.Diagnostics; using System.Runtime.InteropServices; using System.ServiceModel.Activation.Configuration; static class ListenerPerfCounters { static readonly string CategoryName = PerformanceCounterStrings.SMSVCHOST.SMSvcHostPerfCounters; static PerformanceCounter perfCounterConnectionsAcceptedNamedPipe; static PerformanceCounter perfCounterConnectionsAcceptedTcp; static PerformanceCounter perfCounterDispatchFailuresNamedPipe; static PerformanceCounter perfCounterDispatchFailuresTcp; static PerformanceCounter perfCounterProtocolFailuresNamedPipe; static PerformanceCounter perfCounterProtocolFailuresTcp; static PerformanceCounter perfCounterUrisRegisteredNamedPipe; static PerformanceCounter perfCounterUrisRegisteredTcp; static PerformanceCounter perfCounterRegistrationsActiveNamedPipe; static PerformanceCounter perfCounterRegistrationsActiveTcp; static PerformanceCounter perfCounterConnectionsDispatchedNamedPipe; static PerformanceCounter perfCounterConnectionsDispatchedTcp; static PerformanceCounter perfCounterUrisUnregisteredNamedPipe; static PerformanceCounter perfCounterUrisUnregisteredTcp; static ListperfList; static object syncObject = new object(); static ListenerPerfCounters() { if (ListenerConfig.PerformanceCountersEnabled) { ListenerPerfCounters.AddCounterToList(perfCounterConnectionsDispatchedTcp = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.ConnectionsDispatchedTcp, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterConnectionsDispatchedNamedPipe = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.ConnectionsDispatchedNamedPipe, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterDispatchFailuresTcp = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.DispatchFailuresTcp, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterDispatchFailuresNamedPipe = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.DispatchFailuresNamedPipe, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterUrisRegisteredTcp = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.UrisRegisteredTcp, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterUrisRegisteredNamedPipe = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.UrisRegisteredNamedPipe, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterUrisUnregisteredTcp = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.UrisUnregisteredTcp, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterUrisUnregisteredNamedPipe = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.UrisUnregisteredNamedPipe, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterRegistrationsActiveTcp = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.RegistrationsActiveTcp, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterRegistrationsActiveNamedPipe = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.RegistrationsActiveNamedPipe, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterConnectionsAcceptedTcp = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.ConnectionsAcceptedTcp, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterConnectionsAcceptedNamedPipe = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.ConnectionsAcceptedNamedPipe, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterProtocolFailuresTcp = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.ProtocolFailuresTcp, string.Empty, PerformanceCounterInstanceLifetime.Global)); ListenerPerfCounters.AddCounterToList(perfCounterProtocolFailuresNamedPipe = ListenerPerfCounters.GetListenerPerformanceCounter(CategoryName, PerformanceCounterStrings.SMSVCHOST.ProtocolFailuresNamedPipe, string.Empty, PerformanceCounterInstanceLifetime.Global)); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ListenerPerfCounters.ExitOrUnloadEventHandler); AppDomain.CurrentDomain.DomainUnload += new EventHandler(ListenerPerfCounters.ExitOrUnloadEventHandler); AppDomain.CurrentDomain.ProcessExit += new EventHandler(ListenerPerfCounters.ExitOrUnloadEventHandler); } } static PerformanceCounter GetListenerPerformanceCounter(string categoryName, string perfCounterName, string instanceName, PerformanceCounterInstanceLifetime instanceLifetime) { return PerformanceCounters.GetPerformanceCounterInternal(categoryName, perfCounterName, instanceName, instanceLifetime); } static void AddCounterToList(PerformanceCounter counter) { if (counter != null) { ListenerPerfCounters.PerformanceList.Add(counter); } } static List PerformanceList { get { if (ListenerPerfCounters.perfList == null) { lock (ListenerPerfCounters.syncObject) { if (ListenerPerfCounters.perfList == null) { ListenerPerfCounters.perfList = new List (); } } } return ListenerPerfCounters.perfList; } } internal static void DecrementRegistrationsActiveNamedPipe() { ListenerPerfCounters.DecrementCounter(ref perfCounterRegistrationsActiveNamedPipe); } internal static void DecrementRegistrationsActiveTcp() { ListenerPerfCounters.DecrementCounter(ref perfCounterRegistrationsActiveTcp); } internal static void IncrementConnectionsAcceptedNamedPipe() { ListenerPerfCounters.IncrementCounter(ref perfCounterConnectionsAcceptedNamedPipe); } internal static void IncrementConnectionsAcceptedTcp() { ListenerPerfCounters.IncrementCounter(ref perfCounterConnectionsAcceptedTcp); } internal static void IncrementDispatchFailuresNamedPipe() { ListenerPerfCounters.IncrementCounter(ref perfCounterDispatchFailuresNamedPipe); } internal static void IncrementDispatchFailuresTcp() { ListenerPerfCounters.IncrementCounter(ref perfCounterDispatchFailuresTcp); } internal static void IncrementProtocolFailuresNamedPipe() { ListenerPerfCounters.IncrementCounter(ref perfCounterProtocolFailuresNamedPipe); } internal static void IncrementProtocolFailuresTcp() { ListenerPerfCounters.IncrementCounter(ref perfCounterProtocolFailuresTcp); } internal static void IncrementUrisRegisteredNamedPipe() { ListenerPerfCounters.IncrementCounter(ref perfCounterUrisRegisteredNamedPipe); } internal static void IncrementUrisRegisteredTcp() { ListenerPerfCounters.IncrementCounter(ref perfCounterUrisRegisteredTcp); } internal static void IncrementRegistrationsActiveNamedPipe() { ListenerPerfCounters.IncrementCounter(ref perfCounterRegistrationsActiveNamedPipe); } internal static void IncrementRegistrationsActiveTcp() { ListenerPerfCounters.IncrementCounter(ref perfCounterRegistrationsActiveTcp); } internal static void IncrementConnectionsDispatchedNamedPipe() { ListenerPerfCounters.IncrementCounter(ref perfCounterConnectionsDispatchedNamedPipe); } internal static void IncrementConnectionsDispatchedTcp() { ListenerPerfCounters.IncrementCounter(ref perfCounterConnectionsDispatchedTcp); } internal static void IncrementUrisUnregisteredNamedPipe() { ListenerPerfCounters.IncrementCounter(ref perfCounterUrisUnregisteredNamedPipe); } internal static void IncrementUrisUnregisteredTcp() { ListenerPerfCounters.IncrementCounter(ref perfCounterUrisUnregisteredTcp); } static void IncrementCounter(ref PerformanceCounter counter) { if (counter != null) { try { counter.Increment(); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception exception) { if (DiagnosticUtility.IsFatal(exception)) { throw; } ListenerPerfCounters.TracePerformanceCounterUpdateFailure(counter.InstanceName, counter.CounterName); counter = null; } } } static void DecrementCounter(ref PerformanceCounter counter) { if (counter != null) { try { counter.Decrement(); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception exception) { if (DiagnosticUtility.IsFatal(exception)) { throw; } ListenerPerfCounters.TracePerformanceCounterUpdateFailure(counter.InstanceName, counter.CounterName); counter = null; } } } static internal void TracePerformanceCounterUpdateFailure(string instanceName, string perfCounterName) { if (DiagnosticUtility.ShouldTraceError) { DiagnosticUtility.DiagnosticTrace.TraceEvent( System.Diagnostics.TraceEventType.Error, TraceCode.PerformanceCountersFailedDuringUpdate, SR.GetString(System.ServiceModel.SR.TraceCodePerformanceCountersFailedDuringUpdate, perfCounterName + "::" + instanceName)); } } static void ExitOrUnloadEventHandler(object sender, EventArgs e) { List countersToRemove = null; if (ListenerPerfCounters.perfList != null) { lock (syncObject) { if (ListenerPerfCounters.perfList != null) { countersToRemove = ListenerPerfCounters.perfList; ListenerPerfCounters.perfList = null; } } } if (null != countersToRemove) { foreach (PerformanceCounter counter in countersToRemove) { string counterName = counter.CounterName; string categoryName = counter.CategoryName; string instanceName = counter.InstanceName; try { counter.RemoveInstance(); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception exception) { if (DiagnosticUtility.IsFatal(exception)) { throw; } ListenerTraceUtility.EventLog.LogEvent( TraceEventType.Error, EventLogCategory.PerformanceCounter, EventLogEventId.FailedToRemovePerformanceCounter, false, categoryName, counterName, instanceName, exception.ToString()); } } } } } } // 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
- IfElseDesigner.xaml.cs
- ShaderEffect.cs
- WhitespaceRule.cs
- baseaxisquery.cs
- DbXmlEnabledProviderManifest.cs
- WebHostedComPlusServiceHost.cs
- MSAAEventDispatcher.cs
- MouseGestureValueSerializer.cs
- NameValuePair.cs
- StaticResourceExtension.cs
- SerTrace.cs
- UriScheme.cs
- XsltContext.cs
- VerbConverter.cs
- Rfc2898DeriveBytes.cs
- TypeInfo.cs
- MergePropertyDescriptor.cs
- TraceHwndHost.cs
- ToolBar.cs
- Timer.cs
- PublisherMembershipCondition.cs
- HwndStylusInputProvider.cs
- SafeMarshalContext.cs
- Exceptions.cs
- TraceSection.cs
- CultureInfoConverter.cs
- DataException.cs
- AuthenticationModuleElementCollection.cs
- ScrollableControl.cs
- StringSource.cs
- sqlmetadatafactory.cs
- nulltextcontainer.cs
- GenerateScriptTypeAttribute.cs
- CatalogPartDesigner.cs
- TraceUtility.cs
- AlphabetConverter.cs
- BeginStoryboard.cs
- OptimizedTemplateContentHelper.cs
- XmlDocumentFieldSchema.cs
- CompressedStack.cs
- TemplateBamlTreeBuilder.cs
- SingleAnimation.cs
- AssemblyBuilder.cs
- RoleBoolean.cs
- TypeDelegator.cs
- NameGenerator.cs
- DataGridViewCellCollection.cs
- TagMapCollection.cs
- ArcSegment.cs
- FileChangesMonitor.cs
- UserControlCodeDomTreeGenerator.cs
- SystemIcmpV4Statistics.cs
- SplitContainer.cs
- FormViewRow.cs
- base64Transforms.cs
- PropertyMap.cs
- PipelineModuleStepContainer.cs
- RewritingSimplifier.cs
- DataGridViewCellPaintingEventArgs.cs
- XPathDocumentNavigator.cs
- WebPartExportVerb.cs
- EntityCollection.cs
- QilNode.cs
- Vector3D.cs
- CreateUserWizardDesigner.cs
- PairComparer.cs
- HwndTarget.cs
- FaultReason.cs
- GrammarBuilderDictation.cs
- Path.cs
- XmlSchemaSimpleType.cs
- GraphicsPath.cs
- SmiContextFactory.cs
- ManipulationDelta.cs
- LocationSectionRecord.cs
- DeviceContext2.cs
- LocalFileSettingsProvider.cs
- JpegBitmapDecoder.cs
- FullTextLine.cs
- RoutedEventHandlerInfo.cs
- ControlType.cs
- DetailsViewUpdatedEventArgs.cs
- securitycriticaldataClass.cs
- DetailsViewInsertEventArgs.cs
- PartialCachingAttribute.cs
- AdvancedBindingEditor.cs
- WebPartEditorOkVerb.cs
- SchemaElementDecl.cs
- ListControl.cs
- GuidelineCollection.cs
- ObjectStateManager.cs
- HGlobalSafeHandle.cs
- COM2ExtendedUITypeEditor.cs
- Variable.cs
- ValidatorCollection.cs
- __ComObject.cs
- nulltextcontainer.cs
- EndpointAddressAugust2004.cs
- DataGridViewDataErrorEventArgs.cs
- UserControl.cs