1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Diagnostics
{
using System.Diagnostics;
using System.Runtime;
sealed class OperationPerformanceCounters : OperationPerformanceCountersBase
{
internal PerformanceCounter[] Counters { get; set; }
internal OperationPerformanceCounters(string service, string contract, string operationName, string uri)
: base(service, contract, operationName, uri)
{
this.Counters = new PerformanceCounter[(int)PerfCounters.TotalCounters];
for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
{
PerformanceCounter counter = PerformanceCounters.GetOperationPerformanceCounter(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 (Fx.IsFatal(e))
{
throw;
}
if (DiagnosticUtility.ShouldTraceError)
{
TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PerformanceCounterFailedToLoad,
SR.GetString(SR.TraceCodePerformanceCounterFailedToLoad), null, e);
}
break;
}
}
else
{
break;
}
}
}
void Increment(int counter)
{
this.Increment(this.Counters, counter);
}
void IncrementBy(int counter, long time)
{
this.IncrementBy(this.Counters, counter, time);
}
void Decrement(int counter)
{
this.Decrement(this.Counters, counter);
}
internal override void MethodCalled()
{
Increment((int)PerfCounters.Calls);
Increment((int)PerfCounters.CallsPerSecond);
Increment((int)PerfCounters.CallsOutstanding);
}
internal override void MethodReturnedSuccess()
{
Decrement((int)PerfCounters.CallsOutstanding);
}
internal override void MethodReturnedError()
{
Increment((int)PerfCounters.CallsFailed);
Increment((int)PerfCounters.CallsFailedPerSecond);
Decrement((int)PerfCounters.CallsOutstanding);
}
internal override void MethodReturnedFault()
{
Increment((int)PerfCounters.CallsFaulted);
Increment((int)PerfCounters.CallsFaultedPerSecond);
Decrement((int)PerfCounters.CallsOutstanding);
}
internal override void SaveCallDuration(long time)
{
IncrementBy((int)PerfCounters.CallDuration, time);
Increment((int)PerfCounters.CallDurationBase);
}
internal override void AuthenticationFailed()
{
Increment((int)PerfCounters.SecurityValidationAuthenticationFailures);
Increment((int)PerfCounters.SecurityValidationAuthenticationFailuresPerSecond);
}
internal override void AuthorizationFailed()
{
Increment((int)PerfCounters.CallsNotAuthorized);
Increment((int)PerfCounters.CallsNotAuthorizedPerSecond);
}
internal override void TxFlowed()
{
Increment((int)PerfCounters.TxFlowed);
Increment((int)PerfCounters.TxFlowedPerSecond);
}
internal override bool Initialized
{
get { return this.Counters != null; }
}
protected override void Dispose(bool disposing)
{
try
{
if (disposing)
{
if (PerformanceCounters.PerformanceCountersEnabled)
{
if (null != this.Counters)
{
for (int ctr = this.PerfCounterStart; ctr < this.PerfCounterEnd; ++ctr)
{
PerformanceCounter counter = this.Counters[ctr];
if (counter != null)
{
PerformanceCounters.ReleasePerformanceCounter(ref counter);
}
this.Counters[ctr] = null;
}
this.Counters = null;
}
}
}
}
finally
{
base.Dispose(disposing);
}
}
}
}
|