Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Diagnostics / EndpointPerformanceCounters.cs / 1 / EndpointPerformanceCounters.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Diagnostics { using System.Collections.Generic; using System.ServiceModel.Channels; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.ServiceModel.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; internal class EndpointPerformanceCounters : PerformanceCountersBase { string instanceName; PerformanceCounter[] counters = null; enum PerfCounters : int { Calls = 0, CallsPerSecond, CallsOutstanding, CallsFailed, CallsFailedPerSecond, CallsFaulted, CallsFaultedPerSecond, CallDuration, CallDurationBase, SecurityValidationAuthenticationFailures, SecurityValidationAuthenticationFailuresPerSecond, CallsNotAuthorized, CallsNotAuthorizedPerSecond, RMSessionsFaulted, RMSessionsFaultedPerSecond, RMMessagesDropped, RMMessagesDroppedPerSecond, TxFlowed, TxFlowedPerSecond, TotalCounters = TxFlowedPerSecond + 1 } string[] perfCounterNames = { PerformanceCounterStrings.SERVICEMODELENDPOINT.ECalls, PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsPerSecond, PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsOutstanding, PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsFailed, PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsFailedPerSecond, PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsFaulted, PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsFaultedPerSecond, PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallDuration, PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallDurationBase, PerformanceCounterStrings.SERVICEMODELENDPOINT.ESecurityValidationAuthenticationFailures, PerformanceCounterStrings.SERVICEMODELENDPOINT.ESecurityValidationAuthenticationFailuresPerSecond, PerformanceCounterStrings.SERVICEMODELENDPOINT.ESecurityCallsNotAuthorized, PerformanceCounterStrings.SERVICEMODELENDPOINT.ESecurityCallsNotAuthorizedPerSecond, PerformanceCounterStrings.SERVICEMODELENDPOINT.ERMSessionsFaulted, PerformanceCounterStrings.SERVICEMODELENDPOINT.ERMSessionsFaultedPerSecond, PerformanceCounterStrings.SERVICEMODELENDPOINT.ERMMessagesDropped, PerformanceCounterStrings.SERVICEMODELENDPOINT.ERMMessagesDroppedPerSecond, PerformanceCounterStrings.SERVICEMODELENDPOINT.ETxFlowed, PerformanceCounterStrings.SERVICEMODELENDPOINT.ETxFlowedPerSecond, }; const int maxCounterLength = 64; const int hashLength = 2; [Flags] enum truncOptions : uint { NoBits = 0, service15 = 0x01, contract16 = 0x02, uri31 = 0x04 } internal EndpointPerformanceCounters(string service, string contract, string uri) { this.instanceName = EndpointPerformanceCounters.CreateFriendlyInstanceName(service, contract, uri); this.counters = new PerformanceCounter[(int)PerfCounters.TotalCounters]; for (int i = 0; i < (int)PerfCounters.TotalCounters; i++) { PerformanceCounter counter = PerformanceCounters.GetEndpointPerformanceCounter(this.perfCounterNames[i], this.instanceName); if (counter != null) { try { counter.RawValue = 0; this.counters[i] = counter; } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (ExceptionUtility.IsFatal(e)) throw; if (DiagnosticUtility.ShouldTraceError) TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PerformanceCounterFailedToLoad, null, e); break; } } else { break; } } } internal static string CreateFriendlyInstanceName(string service, string contract, string uri) { // instance name is: serviceName.interfaceName.operationName@uri int length = service.Length + contract.Length + uri.Length + 2; if (length > maxCounterLength) { int count = 0; truncOptions tasks = EndpointPerformanceCounters.GetCompressionTasks( length, service.Length, contract.Length, uri.Length); //if necessary, compress service name to 13 chars with a 2 char hash code if ((tasks & truncOptions.service15) > 0) { count = 15; service = GetHashedString(service, count - hashLength, service.Length - count + hashLength, true); } //if necessary, compress contract name to 14 chars with a 2 char hash code if ((tasks & truncOptions.contract16) > 0) { count = 16; contract = GetHashedString(contract, count - hashLength, contract.Length - count + hashLength, true); } //if necessary, compress uri to 29 chars with a 2 char hash code if ((tasks & truncOptions.uri31) > 0) { count = 31; uri = GetHashedString(uri, 0, uri.Length - count + hashLength, false); } } // replace '/' with '|' because perfmon fails when '/' is in perfcounter instance name return service + "." + contract + "@" + uri.Replace('/', '|'); } private static truncOptions GetCompressionTasks(int totalLen, int serviceLen, int contractLen, int uriLen) { truncOptions bitmask = 0; if (totalLen > maxCounterLength) { int workingLen = totalLen; //note: order of if statements important (see spec)! if (workingLen > maxCounterLength && serviceLen > 15) { bitmask |= truncOptions.service15; //compress service name to 16 chars workingLen -= serviceLen - 15; } if (workingLen > maxCounterLength && contractLen > 16) { bitmask |= truncOptions.contract16; //compress contract name to 8 chars workingLen -= contractLen - 16; } if (workingLen > maxCounterLength && uriLen > 31) { bitmask |= truncOptions.uri31; //compress uri to 31 chars } } return bitmask; } internal override PerformanceCounter[] Counters { get { return this.counters; } set { this.counters = value; } } internal override string InstanceName { get { return this.instanceName; } } internal override string[] CounterNames { get { return this.perfCounterNames; } } internal override int PerfCounterStart { get { return (int)PerfCounters.Calls; } } internal override int PerfCounterEnd { get { return (int)PerfCounters.TotalCounters; } } internal void MethodCalled() { Increment((int)PerfCounters.Calls); Increment((int)PerfCounters.CallsPerSecond); Increment((int)PerfCounters.CallsOutstanding); } internal void MethodReturnedSuccess() { Decrement((int)PerfCounters.CallsOutstanding); } internal void MethodReturnedError() { Increment((int)PerfCounters.CallsFailed); Increment((int)PerfCounters.CallsFailedPerSecond); Decrement((int)PerfCounters.CallsOutstanding); } internal void MethodReturnedFault() { Increment((int)PerfCounters.CallsFaulted); Increment((int)PerfCounters.CallsFaultedPerSecond); Decrement((int)PerfCounters.CallsOutstanding); } internal void SaveCallDuration(long time) { IncrementBy((int)PerfCounters.CallDuration, time); Increment((int)PerfCounters.CallDurationBase); } internal void AuthenticationFailed() { Increment((int)PerfCounters.SecurityValidationAuthenticationFailures); Increment((int)PerfCounters.SecurityValidationAuthenticationFailuresPerSecond); } internal void AuthorizationFailed() { Increment((int)PerfCounters.CallsNotAuthorized); Increment((int)PerfCounters.CallsNotAuthorizedPerSecond); } internal void SessionFaulted() { Increment((int)PerfCounters.RMSessionsFaulted); Increment((int)PerfCounters.RMSessionsFaultedPerSecond); } internal void MessageDropped() { Increment((int)PerfCounters.RMMessagesDropped); Increment((int)PerfCounters.RMMessagesDroppedPerSecond); } internal void TxFlowed() { Increment((int)PerfCounters.TxFlowed); Increment((int)PerfCounters.TxFlowedPerSecond); } internal bool Initialized { get { return this.counters != null; } } } } // 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
- EventProviderClassic.cs
- HyperLinkField.cs
- XmlObjectSerializerReadContextComplex.cs
- KeyValueSerializer.cs
- Vector.cs
- Cursor.cs
- XmlTextWriter.cs
- WebServiceData.cs
- OracleLob.cs
- ArgumentNullException.cs
- DataGridItem.cs
- SHA256CryptoServiceProvider.cs
- MenuTracker.cs
- EditorPart.cs
- XsltConvert.cs
- FixedHyperLink.cs
- StringAnimationBase.cs
- ZipIORawDataFileBlock.cs
- EncryptedPackageFilter.cs
- ReadOnlyTernaryTree.cs
- EntityDataSourceChangingEventArgs.cs
- HttpGetProtocolReflector.cs
- ListViewTableCell.cs
- StreamSecurityUpgradeProvider.cs
- WorkflowMarkupSerializerMapping.cs
- FontInfo.cs
- PasswordTextContainer.cs
- IFlowDocumentViewer.cs
- sqlpipe.cs
- HttpResponse.cs
- ScriptMethodAttribute.cs
- DbParameterHelper.cs
- InternalConfigEventArgs.cs
- NamespaceEmitter.cs
- InputMethodStateTypeInfo.cs
- TemplatePartAttribute.cs
- ipaddressinformationcollection.cs
- SoapServerProtocol.cs
- CopyNodeSetAction.cs
- SettingsAttributeDictionary.cs
- VisualBasicSettings.cs
- FacetDescriptionElement.cs
- Win32SafeHandles.cs
- AuthorizationRuleCollection.cs
- ObsoleteAttribute.cs
- DocumentPage.cs
- HtmlButton.cs
- ResolveMatchesMessage11.cs
- GPPOINTF.cs
- OutputChannelBinder.cs
- ScaleTransform3D.cs
- XmlReader.cs
- TabControlCancelEvent.cs
- IPHostEntry.cs
- TextDecorationCollectionConverter.cs
- InvalidOleVariantTypeException.cs
- ReflectionServiceProvider.cs
- TlsnegoTokenAuthenticator.cs
- DoubleAnimationClockResource.cs
- PenContexts.cs
- CellConstantDomain.cs
- Screen.cs
- CancelEventArgs.cs
- Error.cs
- CornerRadius.cs
- Point3DConverter.cs
- ManagementInstaller.cs
- OdbcRowUpdatingEvent.cs
- XslCompiledTransform.cs
- Socket.cs
- BaseTreeIterator.cs
- QuaternionRotation3D.cs
- AxisAngleRotation3D.cs
- BooleanConverter.cs
- DocumentEventArgs.cs
- SpecialTypeDataContract.cs
- EmbeddedObject.cs
- SpStreamWrapper.cs
- EventLevel.cs
- CompilationUnit.cs
- PrintEvent.cs
- InvalidPropValue.cs
- QueryContinueDragEvent.cs
- PrePrepareMethodAttribute.cs
- DataView.cs
- DataBindingsDialog.cs
- TypedDataSetSchemaImporterExtensionFx35.cs
- SolidColorBrush.cs
- UnsafeNativeMethods.cs
- WebExceptionStatus.cs
- ObjectIDGenerator.cs
- IdnMapping.cs
- CurrentChangedEventManager.cs
- AsyncPostBackTrigger.cs
- XMLDiffLoader.cs
- AutomationPropertyInfo.cs
- SafeTimerHandle.cs
- ObjectHandle.cs
- DragEvent.cs
- CompilerResults.cs