Example #1
0
 internal static void AddPerformanceCountersForEndpoint(ServiceHostBase serviceHost, ContractDescription contractDescription, EndpointDispatcher endpointDispatcher)
 {
     if ((PerformanceCountersEnabled || MinimalPerformanceCountersEnabled) && endpointDispatcher.SetPerfCounterId())
     {
         ServiceModelPerformanceCounters counters;
         lock (perfCounterDictionarySyncObject)
         {
             if (!PerformanceCountersForEndpoint.TryGetValue(endpointDispatcher.PerfCounterId, out counters))
             {
                 counters = new ServiceModelPerformanceCounters(serviceHost, contractDescription, endpointDispatcher);
                 if (!counters.Initialized)
                 {
                     return;
                 }
                 PerformanceCountersForEndpoint.Add(endpointDispatcher.PerfCounterId, counters);
                 int num = PerformanceCountersForEndpointList.FindIndex(c => c == null);
                 if (num >= 0)
                 {
                     PerformanceCountersForEndpointList[num] = counters;
                 }
                 else
                 {
                     PerformanceCountersForEndpointList.Add(counters);
                     num = PerformanceCountersForEndpointList.Count - 1;
                 }
                 endpointDispatcher.PerfCounterInstanceId = num;
             }
         }
         lock (perfCounterDictionarySyncObject)
         {
             ServiceModelPerformanceCountersEntry entry;
             if (!PerformanceCountersForBaseUri.TryGetValue(endpointDispatcher.PerfCounterBaseId, out entry))
             {
                 if (PerformanceCountersEnabled)
                 {
                     entry = new ServiceModelPerformanceCountersEntry(serviceHost.Counters);
                 }
                 else if (MinimalPerformanceCountersEnabled)
                 {
                     entry = new ServiceModelPerformanceCountersEntry(serviceHost.DefaultCounters);
                 }
                 PerformanceCountersForBaseUri.Add(endpointDispatcher.PerfCounterBaseId, entry);
             }
             entry.Add(counters);
         }
     }
 }
Example #2
0
 internal static void ReleasePerformanceCountersForEndpoint(string id, string baseId)
 {
     if (PerformanceCountersEnabled)
     {
         lock (perfCounterDictionarySyncObject)
         {
             ServiceModelPerformanceCounters counters;
             if (!string.IsNullOrEmpty(id) && PerformanceCountersForEndpoint.TryGetValue(id, out counters))
             {
                 PerformanceCountersForEndpoint.Remove(id);
                 int index = PerformanceCountersForEndpointList.IndexOf(counters);
                 PerformanceCountersForEndpointList[index] = null;
             }
             if (!string.IsNullOrEmpty(baseId))
             {
                 PerformanceCountersForBaseUri.Remove(baseId);
             }
         }
     }
 }