/// <summary> /// CounterSet constructor. /// </summary> /// <param name="providerGuid">ProviderGuid identifies the provider application. A provider identified by ProviderGuid could publish several CounterSets defined by different CounterSetGuids</param> /// <param name="counterSetGuid">CounterSetGuid identifies the specific CounterSet. CounterSetGuid should be unique.</param> /// <param name="instanceType">One of defined CounterSetInstanceType values</param> public CounterSet(Guid providerGuid, Guid counterSetGuid, CounterSetInstanceType instanceType) { if (!PerfProviderCollection.ValidateCounterSetInstanceType(instanceType)) { throw new ArgumentException(SR.Format(SR.Perflib_Argument_InvalidCounterSetInstanceType, instanceType), nameof(instanceType)); } _providerGuid = providerGuid; _counterSet = counterSetGuid; _instType = instanceType; PerfProviderCollection.RegisterCounterSet(_counterSet); _provider = PerfProviderCollection.QueryProvider(_providerGuid); _lockObject = new object(); _stringToId = new Dictionary <string, int>(); _idToCounter = new Dictionary <int, CounterType>(); }
internal static PerfProvider QueryProvider(Guid providerGuid) { // Most of the cases should be that the application contains 1 provider that supports several CounterSets; // that is, ContainsKey should succeed except for the first time. // lock (s_lockObject) { foreach (PerfProvider ProviderEntry in s_providerList) { if (ProviderEntry.m_providerGuid == providerGuid) { return ProviderEntry; } } PerfProvider NewProvider = new PerfProvider(providerGuid); s_providerList.Add(NewProvider); return NewProvider; } }
internal static PerfProvider QueryProvider(Guid providerGuid) { lock (s_lockObject) { foreach (PerfProvider provider in s_providerList) { if (provider.m_providerGuid == providerGuid) { return provider; } } PerfProvider item = new PerfProvider(providerGuid); s_providerList.Add(item); return item; } }
internal static PerfProvider QueryProvider(Guid providerGuid) { lock (s_lockObject) { foreach (PerfProvider provider in s_providerList) { if (provider.m_providerGuid == providerGuid) { return(provider); } } PerfProvider item = new PerfProvider(providerGuid); s_providerList.Add(item); return(item); } }
protected virtual void Dispose(bool disposing) { lock(this) { PerfProviderCollection.UnregisterCounterSet(m_counterSet); if (m_instanceCreated) { if (m_provider != null) { lock (m_lockObject) { if (m_provider != null) { Interlocked.Decrement(ref m_provider.m_counterSet); if (m_provider.m_counterSet <= 0) { PerfProviderCollection.RemoveProvider(m_providerGuid); } m_provider = null; } } } } } }
internal static PerfProvider QueryProvider(Guid providerGuid) { // Most of the cases should be that the application contains 1 provider that supports several CounterSets; // that is, ContainsKey should succeed except for the first time. lock (s_lockObject) { foreach (PerfProvider ProviderEntry in s_providerList) { if (ProviderEntry._providerGuid == providerGuid) { return(ProviderEntry); } } PerfProvider NewProvider = new PerfProvider(providerGuid); s_providerList.Add(NewProvider); return(NewProvider); } }
public CounterSet(Guid providerGuid, Guid counterSetGuid, CounterSetInstanceType instanceType) { // Check only the mayor version, only support Windows Vista and later. // if (s_platformNotSupported) { throw new System.PlatformNotSupportedException(SR.GetString(SR.Perflib_PlatformNotSupported)); } if (! PerfProviderCollection.ValidateCounterSetInstanceType(instanceType)) { throw new ArgumentException(SR.GetString(SR.Perflib_Argument_InvalidCounterSetInstanceType, instanceType), "instanceType"); } m_providerGuid = providerGuid; m_counterSet = counterSetGuid; m_instType = instanceType; PerfProviderCollection.RegisterCounterSet(m_counterSet); m_provider = PerfProviderCollection.QueryProvider(m_providerGuid); m_lockObject = new Object(); m_stringToId = new Dictionary<String, Int32>(); m_idToCounter = new Dictionary<Int32, CounterType>(); }
public CounterSet(Guid providerGuid, Guid counterSetGuid, CounterSetInstanceType instanceType) { if (s_platformNotSupported) { throw new PlatformNotSupportedException(System.SR.GetString("Perflib_PlatformNotSupported")); } if (!PerfProviderCollection.ValidateCounterSetInstanceType(instanceType)) { throw new ArgumentException(System.SR.GetString("Perflib_Argument_InvalidCounterSetInstanceType", new object[] { instanceType }), "instanceType"); } this.m_providerGuid = providerGuid; this.m_counterSet = counterSetGuid; this.m_instType = instanceType; PerfProviderCollection.RegisterCounterSet(this.m_counterSet); this.m_provider = PerfProviderCollection.QueryProvider(this.m_providerGuid); this.m_lockObject = new object(); this.m_stringToId = new Dictionary<string, int>(); this.m_idToCounter = new Dictionary<int, CounterType>(); }
internal static void RemoveProvider(Guid providerGuid) { lock (s_lockObject) { PerfProvider MatchedProvider = null; foreach (PerfProvider ProviderEntry in s_providerList) { if (ProviderEntry.m_providerGuid == providerGuid) { MatchedProvider = ProviderEntry; } } if (MatchedProvider != null) { MatchedProvider.m_hProvider.Dispose(); s_providerList.Remove(MatchedProvider); } } }
internal static void RemoveProvider(Guid providerGuid) { lock (s_lockObject) { PerfProvider item = null; foreach (PerfProvider provider2 in s_providerList) { if (provider2.m_providerGuid == providerGuid) { item = provider2; } } if (item != null) { item.m_hProvider.Dispose(); s_providerList.Remove(item); } } }
public CounterSet(Guid providerGuid, Guid counterSetGuid, CounterSetInstanceType instanceType) { if (s_platformNotSupported) { throw new PlatformNotSupportedException(System.SR.GetString("Perflib_PlatformNotSupported")); } if (!PerfProviderCollection.ValidateCounterSetInstanceType(instanceType)) { throw new ArgumentException(System.SR.GetString("Perflib_Argument_InvalidCounterSetInstanceType", new object[] { instanceType }), "instanceType"); } this.m_providerGuid = providerGuid; this.m_counterSet = counterSetGuid; this.m_instType = instanceType; PerfProviderCollection.RegisterCounterSet(this.m_counterSet); this.m_provider = PerfProviderCollection.QueryProvider(this.m_providerGuid); this.m_lockObject = new object(); this.m_stringToId = new Dictionary <string, int>(); this.m_idToCounter = new Dictionary <int, CounterType>(); }
public CounterSet(Guid providerGuid, Guid counterSetGuid, CounterSetInstanceType instanceType) { // Check only the mayor version, only support Windows Vista and later. // if (s_platformNotSupported) { throw new System.PlatformNotSupportedException(SR.GetString(SR.Perflib_PlatformNotSupported)); } if (!PerfProviderCollection.ValidateCounterSetInstanceType(instanceType)) { throw new ArgumentException(SR.GetString(SR.Perflib_Argument_InvalidCounterSetInstanceType, instanceType), "instanceType"); } m_providerGuid = providerGuid; m_counterSet = counterSetGuid; m_instType = instanceType; PerfProviderCollection.RegisterCounterSet(m_counterSet); m_provider = PerfProviderCollection.QueryProvider(m_providerGuid); m_lockObject = new Object(); m_stringToId = new Dictionary <String, Int32>(); m_idToCounter = new Dictionary <Int32, CounterType>(); }
protected virtual void Dispose(bool disposing) { lock (this) { PerfProviderCollection.UnregisterCounterSet(this.m_counterSet); if (this.m_instanceCreated && (this.m_provider != null)) { lock (this.m_lockObject) { if (this.m_provider != null) { Interlocked.Decrement(ref this.m_provider.m_counterSet); if (this.m_provider.m_counterSet <= 0) { PerfProviderCollection.RemoveProvider(this.m_providerGuid); } this.m_provider = null; } } } } }