Ejemplo n.º 1
0
        public void AddCounter(Int32 counterId, CounterType counterType)
        {
            if (m_provider == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_NoActiveProvider, m_providerGuid));
            }
            if (!PerfProviderCollection.ValidateCounterType(counterType))
            {
                throw new ArgumentException(SR.GetString(SR.Perflib_Argument_InvalidCounterType, counterType), "counterType");
            }
            if (m_instanceCreated)
            {
                throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_AddCounterAfterInstance, m_counterSet));
            }

            lock (m_lockObject) {
                if (m_instanceCreated)
                {
                    throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_AddCounterAfterInstance, m_counterSet));
                }
                if (m_idToCounter.ContainsKey(counterId))
                {
                    throw new ArgumentException(SR.GetString(SR.Perflib_Argument_CounterAlreadyExists, counterId, m_counterSet), "CounterId");
                }

                m_idToCounter.Add(counterId, counterType);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add non-displayable new counter to CounterSet; that is, perfmon would not display the counter.
        /// </summary>
        /// <param name="counterId">CounterId uniquely identifies the counter within CounterSet</param>
        /// <param name="counterType">One of defined CounterType values</param>
        public void AddCounter(int counterId, CounterType counterType)
        {
            if (_provider == null)
            {
                throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_NoActiveProvider, _providerGuid));
            }
            if (!PerfProviderCollection.ValidateCounterType(counterType))
            {
                throw new ArgumentException(SR.Format(SR.Perflib_Argument_InvalidCounterType, counterType), nameof(counterType));
            }
            if (_instanceCreated)
            {
                throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_AddCounterAfterInstance, _counterSet));
            }

            lock (_lockObject)
            {
                if (_instanceCreated)
                {
                    throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_AddCounterAfterInstance, _counterSet));
                }
                if (_idToCounter.ContainsKey(counterId))
                {
                    throw new ArgumentException(SR.Format(SR.Perflib_Argument_CounterAlreadyExists, counterId, _counterSet), nameof(counterId));
                }

                _idToCounter.Add(counterId, counterType);
            }
        }
Ejemplo n.º 3
0
 public void AddCounter(int counterId, CounterType counterType)
 {
     if (this.m_provider == null)
     {
         throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_NoActiveProvider", new object[] { this.m_providerGuid }));
     }
     if (!PerfProviderCollection.ValidateCounterType(counterType))
     {
         throw new ArgumentException(System.SR.GetString("Perflib_Argument_InvalidCounterType", new object[] { counterType }), "counterType");
     }
     if (this.m_instanceCreated)
     {
         throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_AddCounterAfterInstance", new object[] { this.m_counterSet }));
     }
     lock (this.m_lockObject)
     {
         if (this.m_instanceCreated)
         {
             throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_AddCounterAfterInstance", new object[] { this.m_counterSet }));
         }
         if (this.m_idToCounter.ContainsKey(counterId))
         {
             throw new ArgumentException(System.SR.GetString("Perflib_Argument_CounterAlreadyExists", new object[] { counterId, this.m_counterSet }), "CounterId");
         }
         this.m_idToCounter.Add(counterId, counterType);
     }
 }
Ejemplo n.º 4
0
        /// <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>();
        }
Ejemplo n.º 5
0
 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>();
 }
Ejemplo n.º 6
0
        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>();
        }
Ejemplo n.º 7
0
 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;
                 }
             }
         }
     }
 }