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
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Diagnostics
{
using System.Diagnostics;
using System.Runtime;
using System.ServiceModel;
internal class DefaultPerformanceCounters : PerformanceCountersBase
{
string instanceName;
enum PerfCounters : int
{
Instances = 0,
TotalCounters = Instances + 1
}
string[] perfCounterNames =
{
PerformanceCounterStrings.SERVICEMODELSERVICE.SInstances,
};
const int maxCounterLength = 64;
const int hashLength = 2;
[Flags]
enum truncOptions : uint
{
NoBits = 0,
service32 = 0x01,
uri31 = 0x04
}
internal PerformanceCounter[] Counters { get; set; }
internal override string InstanceName
{
get
{
return this.instanceName;
}
}
internal override string[] CounterNames
{
get
{
return this.perfCounterNames;
}
}
internal override int PerfCounterStart
{
get { return (int)PerfCounters.Instances; }
}
internal override int PerfCounterEnd
{
get { return (int)PerfCounters.TotalCounters; }
}
static internal string CreateFriendlyInstanceName(ServiceHostBase serviceHost)
{
// It is a shared instance across all services which have the default counter enabled
return "_WCF_Admin";
}
internal DefaultPerformanceCounters(ServiceHostBase serviceHost)
{
this.instanceName = DefaultPerformanceCounters.CreateFriendlyInstanceName(serviceHost);
this.Counters = new PerformanceCounter[(int)PerfCounters.TotalCounters];
for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
{
try
{
PerformanceCounter counter = PerformanceCounters.GetDefaultPerformanceCounter(this.perfCounterNames[i], this.instanceName);
if (counter != null)
{
this.Counters[i] = counter;
}
else
{
break;
}
}
#pragma warning suppress 56500 // covered by FxCOP
catch (Exception e)
{
if (Fx.IsFatal(e))
{
throw;
}
if (DiagnosticUtility.ShouldTraceError)
{
TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PerformanceCountersFailedForService,
SR.GetString(SR.TraceCodePerformanceCountersFailedForService), null, e);
}
break;
}
}
}
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);
}
}
}
}
|