internal ServicePerformanceCountersV2(ServiceHostBase serviceHost) : base(serviceHost)
 {
     if (serviceCounterSet == null)
     {
         lock (syncRoot)
         {
             if (serviceCounterSet == null)
             {
                 CounterSet set = CreateCounterSet();
                 set.AddCounter(0, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0]);
                 set.AddCounter(1, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[1]);
                 set.AddCounter(2, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[2]);
                 set.AddCounter(3, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[3]);
                 set.AddCounter(4, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[4]);
                 set.AddCounter(5, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[5]);
                 set.AddCounter(6, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[6]);
                 set.AddCounter(8, CounterType.AverageBase, ServicePerformanceCountersBase.perfCounterNames[8]);
                 set.AddCounter(7, CounterType.AverageTimer32, ServicePerformanceCountersBase.perfCounterNames[7]);
                 set.AddCounter(9, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[9]);
                 set.AddCounter(10, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[10]);
                 set.AddCounter(11, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[11]);
                 set.AddCounter(12, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[12]);
                 set.AddCounter(13, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[13]);
                 set.AddCounter(14, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[14]);
                 set.AddCounter(15, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[15]);
                 set.AddCounter(0x10, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[0x10]);
                 set.AddCounter(0x11, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0x11]);
                 set.AddCounter(0x12, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[0x12]);
                 set.AddCounter(0x13, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0x13]);
                 set.AddCounter(20, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[20]);
                 set.AddCounter(0x15, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0x15]);
                 set.AddCounter(0x16, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[0x16]);
                 set.AddCounter(0x17, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0x17]);
                 set.AddCounter(0x18, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[0x18]);
                 set.AddCounter(0x19, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0x19]);
                 set.AddCounter(0x1a, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[0x1a]);
                 set.AddCounter(0x1b, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0x1b]);
                 set.AddCounter(0x1c, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[0x1c]);
                 set.AddCounter(0x1d, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0x1d]);
                 set.AddCounter(30, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[30]);
                 set.AddCounter(0x1f, CounterType.RawData32, ServicePerformanceCountersBase.perfCounterNames[0x1f]);
                 set.AddCounter(0x20, CounterType.RateOfCountPerSecond32, ServicePerformanceCountersBase.perfCounterNames[0x20]);
                 set.AddCounter(0x21, CounterType.RawFraction32, ServicePerformanceCountersBase.perfCounterNames[0x21]);
                 set.AddCounter(0x22, CounterType.RawBase32, ServicePerformanceCountersBase.perfCounterNames[0x22]);
                 set.AddCounter(0x23, CounterType.RawFraction32, ServicePerformanceCountersBase.perfCounterNames[0x23]);
                 set.AddCounter(0x24, CounterType.RawBase32, ServicePerformanceCountersBase.perfCounterNames[0x24]);
                 set.AddCounter(0x25, CounterType.RawFraction32, ServicePerformanceCountersBase.perfCounterNames[0x25]);
                 set.AddCounter(0x26, CounterType.RawBase32, ServicePerformanceCountersBase.perfCounterNames[0x26]);
                 serviceCounterSet = set;
             }
         }
     }
     this.serviceCounterSetInstance = CreateCounterSetInstance(this.InstanceName);
     this.counters = new CounterData[0x27];
     for (int i = 0; i < 0x27; i++)
     {
         this.counters[i]       = this.serviceCounterSetInstance.Counters[i];
         this.counters[i].Value = 0L;
     }
 }
        private void CreateCounterSetInstance()
        {
            _CounterSet =
                new CounterSet(
                    base._counterSetRegistrarBase.ProviderId,
                    base._counterSetRegistrarBase.CounterSetId,
                    base._counterSetRegistrarBase.CounterSetInstType);

            // Add the counters to the counter set definition.
            foreach (CounterInfo counterInfo in base._counterSetRegistrarBase.CounterInfoArray)
            {
                if (counterInfo.Name == null)
                {
                    _CounterSet.AddCounter(counterInfo.Id, counterInfo.Type);
                }
                else
                {
                    _CounterSet.AddCounter(counterInfo.Id, counterInfo.Type, counterInfo.Name);
                }
            }

            string instanceName = PSPerfCountersMgr.Instance.GetCounterSetInstanceName();

            // Create an instance of the counter set (contains the counter data).
            _CounterSetInstance = _CounterSet.CreateCounterSetInstance(instanceName);
        }
Пример #3
0
 // Immediately disposes and nulls the CounterSetInstance. This differs from Dispose because Dispose is "lazy" in that
 // it holds weak references to the instances so we don't get corrupted state if the values are updated later. This
 // method is used in situations when we need to delete the instance immediately and know the values won't be updated.
 internal void DeleteInstance()
 {
     if (this.operationCounterSetInstance != null)
     {
         this.operationCounterSetInstance.Dispose();
         this.operationCounterSetInstance = null;
     }
 }
Пример #4
0
 // Immediately disposes and nulls the CounterSetInstance. This differs from Dispose because Dispose is "lazy" in that
 // it holds weak references to the instances so we don't get corrupted state if the values are updated later. This
 // method is used in situations when we need to delete the instance immediately and know the values won't be updated.
 internal void DeleteInstance()
 {
     if (this.endpointCounterSetInstance != null)
     {
         this.endpointCounterSetInstance.Dispose();
         this.endpointCounterSetInstance = null;
     }
 }
 // Immediately disposes and nulls the CounterSetInstance. This differs from Dispose because Dispose is "lazy" in that
 // it holds weak references to the instances so we don't get corrupted state if the values are updated later. This
 // method is used in situations when we need to delete the instance immediately and know the values won't be updated.
 internal void DeleteInstance()
 {
     if (this.serviceCounterSetInstance != null)
     {
         this.serviceCounterSetInstance.Dispose();
         this.serviceCounterSetInstance = null;
     }
 }
Пример #6
0
            /// <summary>
            /// Adds a CounterSetInstance to the cache, from where it will be garbage collected or re-used by another performance counter (whichever occurs first).
            /// </summary>
            internal void Add(string instanceName, CounterSetInstance instance)
            {
                Fx.Assert(instanceName != null, "Invalid argument.");
                Fx.Assert(instance != null, "Invalid argument.");

                lock (this.cache)
                {
                    this.cache[instanceName] = new WeakReference(instance);
                }
            }
 public void PerformanceCounter_PerformanceData_CreateCounterSetInstance_AlreadyExists()
 {
     using (CounterSet typingCounterSet = new CounterSet(_fixture._providerId, _fixture._typingCounterSetId, CounterSetInstanceType.Single))
     {
         typingCounterSet.AddCounter(6, CounterType.SampleBase, "Percent Base");
         using (CounterSetInstance typingCsInstance = typingCounterSet.CreateCounterSetInstance("Typing Instance"))
         {
             AssertExtensions.Throws <ArgumentException>("instanceName", "InstanceName", () => typingCounterSet.CreateCounterSetInstance("Typing Instance"));
         }
     }
 }
Пример #8
0
 internal EndpointPerformanceCountersV2(string service, string contract, string uri) : base(service, contract, uri)
 {
     EnsureCounterSet();
     this.endpointCounterSetInstance = CreateCounterSetInstance(this.InstanceName);
     this.counters = new CounterData[0x13];
     for (int i = 0; i < 0x13; i++)
     {
         this.counters[i]       = this.endpointCounterSetInstance.Counters[i];
         this.counters[i].Value = 0L;
     }
 }
 internal OperationPerformanceCountersV2(string service, string contract, string operationName, string uri) : base(service, contract, operationName, uri)
 {
     EnsureCounterSet();
     this.operationCounterSetInstance = CreateCounterSetInstance(this.InstanceName);
     this.counters = new CounterData[15];
     for (int i = 0; i < 15; i++)
     {
         this.counters[i]       = this.operationCounterSetInstance.Counters[i];
         this.counters[i].Value = 0L;
     }
 }
 public void PerformanceCounter_PerformanceData_InvalidCounterName_Indexer(string counterName)
 {
     using (CounterSet typingCounterSet = new CounterSet(_fixture._providerId, _fixture._typingCounterSetId, CounterSetInstanceType.Single))
     {
         typingCounterSet.AddCounter(6, CounterType.SampleBase, "Percent Base");
         using (CounterSetInstance typingCsInstance = typingCounterSet.CreateCounterSetInstance("Typing Instance"))
         {
             AssertExtensions.Throws <ArgumentNullException>("counterName", "CounterName", () => typingCsInstance.Counters[counterName]);
         }
     }
 }
Пример #11
0
 public PerfCounters(Uri instanceName)
 {
     this.providerGuid           = new Guid("{b0f9d01b-71f3-4d7d-b69e-5d1c5932b74d}");
     this.providerCounterSetGuid = new Guid("{e711142e-c6b7-41a9-ac1a-aa63c936cd55}");
     this.counterSet             = new CounterSet(this.providerGuid, this.providerCounterSetGuid, CounterSetInstanceType.Multiple);
     this.counterSet.AddCounter(1, CounterType.RawData32);
     this.counterSet.AddCounter(2, CounterType.RawData32);
     this.counterSet.AddCounter(3, CounterType.RawData32);
     this.counterSet.AddCounter(4, CounterType.RateOfCountPerSecond32);
     this.counterSet.AddCounter(5, CounterType.RateOfCountPerSecond32);
     this.counterSetInstance = this.CreateInstance(instanceName);
 }
Пример #12
0
        /// <summary>
        /// Helper function to generate the triangle wave and square wave for the counters.
        /// </summary>
        /// <param name="CsInstance"> CounterSetInstance object which needs the value update.</param>
        /// <param name="MinimalValue"> The minimal value for the counters.</param>
        /// <param name="Degree"> Generate the data according to this value.</param>
        static void UpdataGeometricWave(CounterSetInstance CsInstance, UInt32 MinimalValue, UInt32 Degree)
        {
            long   High;
            UInt32 Increase;

            High = ((Degree % 180) > 90) ? ALTITUDE : -ALTITUDE;
            CsInstance.Counters[2].Value = MinimalValue + High; //"Square Wave"

            Increase = (Degree < 180) ? Degree : 360 - Degree;
            Increase = (UInt32)((double)ALTITUDE / 180 * Increase);
            CsInstance.Counters[1].Value = MinimalValue + Increase; //"Triangle Wave"
        }
 public void PerformanceCounter_PerformanceData_Counter_NotFound()
 {
     using (CounterSet typingCounterSet = new CounterSet(_fixture._providerId, _fixture._typingCounterSetId, CounterSetInstanceType.Single))
     {
         typingCounterSet.AddCounter(6, CounterType.SampleBase, "Percent Base");
         using (CounterSetInstance typingCsInstance = typingCounterSet.CreateCounterSetInstance("Typing Instance"))
         {
             Assert.Null(typingCsInstance.Counters["NotFound"]);
             Assert.Null(typingCsInstance.Counters[1]);
         }
     }
 }
Пример #14
0
 internal EndpointPerformanceCountersV2(string service, string contract, string uri)
     : base(service, contract, uri)
 {
     EnsureCounterSet();
     // Create an instance of the counter set (contains the counter data).
     this.endpointCounterSetInstance = CreateCounterSetInstance(this.InstanceName);
     this.counters = new CounterData[(int)PerfCounters.TotalCounters]; // Cache to dodge dictionary lookups in ServiceModelInstance
     for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
     {
         this.counters[i]       = this.endpointCounterSetInstance.Counters[i];
         this.counters[i].Value = 0;
     }
 }
        protected void Application_Start(object sender, EventArgs e)
        {
            // Creating an unique name from the name of the process, which will be assigned to counter instance
            // We need to "sanitize" the process name by removing some characters from the string (ie. back slash).
            // For example "/lm/w3svc/2/root/jsonproxy-3-13119983125367734"
            // Will become "_lm_w3svc_2_root_jsonprox_-3-13119983125367734"
            string instanceName = AppDomain.CurrentDomain.FriendlyName.Replace('/', '_');

            // creating the counter set
            Global.myCounterSet = new CounterSet <MyCounterSource.MyCounterObjectsSet>();
            // creating coutner instances
            Global.myCounterInstances = myCounterSet.CreateInstance(instanceName);
        }
Пример #16
0
        public CounterSetInstance CreateInstance(Uri instanceName)
        {
            TraceHelper.Current.DebugMessage(string.Concat("Counter instance Url = ", instanceName.ToString()));
            string             str = instanceName.ToString().Replace("/", "_");
            CounterSetInstance counterSetInstance = this.counterSet.CreateCounterSetInstance(str);

            this.ActiveRequests              = new PerfCounter(counterSetInstance, 1);
            this.ActiveRunspaces             = new PerfCounter(counterSetInstance, 2);
            this.ActiveUsers                 = new PerfCounter(counterSetInstance, 3);
            this.UserQuotaViolationsPerSec   = new PerfCounter(counterSetInstance, 4);
            this.SystemQuotaViolationsPerSec = new PerfCounter(counterSetInstance, 5);
            return(counterSetInstance);
        }
Пример #17
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         if ((disposing && PerformanceCounters.PerformanceCountersEnabled) && (this.endpointCounterSetInstance != null))
         {
             this.endpointCounterSetInstance.Dispose();
             this.endpointCounterSetInstance = null;
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Пример #18
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing && this.workflowServiceHostCounterSetInstance != null)
         {
             this.workflowServiceHostCounterSetInstance.Dispose();
             this.workflowServiceHostCounterSetInstance = null;
             this.isPerformanceCounterEnabled           = false;
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Пример #19
0
 protected virtual void Dispose(bool disposeManagedResources)
 {
     if (disposeManagedResources && !this.disposed)
     {
         if (this.counterSetInstance != null)
         {
             this.counterSetInstance.Dispose();
             this.counterSetInstance = null;
         }
         if (this.counterSet != null)
         {
             this.counterSet.Dispose();
             this.counterSet = null;
         }
         this.disposed = true;
     }
 }
Пример #20
0
        private void CreateCounterSetInstance()
        {
            this._CounterSet = new CounterSet(base._counterSetRegistrarBase.ProviderId, base._counterSetRegistrarBase.CounterSetId, base._counterSetRegistrarBase.CounterSetInstType);
            foreach (CounterInfo info in base._counterSetRegistrarBase.CounterInfoArray)
            {
                if (info.Name == null)
                {
                    this._CounterSet.AddCounter(info.Id, info.Type);
                }
                else
                {
                    this._CounterSet.AddCounter(info.Id, info.Type, info.Name);
                }
            }
            string counterSetInstanceName = PSPerfCountersMgr.Instance.GetCounterSetInstanceName();

            this._CounterSetInstance = this._CounterSet.CreateCounterSetInstance(counterSetInstanceName);
        }
Пример #21
0
        static void Main(string[] args)
        {
            var schemaPath = RegisterCounters();
            PerformanceCounter pc = new PerformanceCounter("Typing", "Words Typed In Interval");
            typingCounterSet = new CounterSet(providerId, typingCounterSetId, CounterSetInstanceType.Single);
            try
            {
                typingCounterSet.AddCounter(1, CounterType.Delta32, "Words Typed In Interval");
                typingCsInstance = typingCounterSet.CreateCounterSetInstance("Typing Instance");
                typingCsInstance.Counters[1].Value = 0;

                System.Diagnostics.Debug.Assert(pc.RawValue == 0);
                typingCsInstance.Counters["Words Typed In Interval"].Increment();
                System.Diagnostics.Debug.Assert(pc.RawValue == 1);
            }
            finally
            {
                typingCounterSet.Dispose();
                UnregisterCounters(schemaPath);
                Directory.Delete(Path.GetDirectoryName(schemaPath), true);
            }
        }
Пример #22
0
        internal void InitializePerformanceCounters()
        {
            this.instanceName = CreateFriendlyInstanceName(this.serviceHost);

            if (PerformanceCounters.PerformanceCountersEnabled)
            {
                EnsureCounterSet();
                // Create an instance of the counter set (contains the counter data).
                this.workflowServiceHostCounterSetInstance = CreateCounterSetInstance(this.InstanceName);

                if (this.workflowServiceHostCounterSetInstance != null)
                {
                    this.counters = new CounterData[(int)PerfCounters.TotalCounters];
                    for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
                    {
                        this.counters[i]       = this.workflowServiceHostCounterSetInstance.Counters[i];
                        this.counters[i].Value = 0;
                    }
                    // Enable perf counter only if CounterSetInstance is created without instance name conflict.
                    this.isPerformanceCounterEnabled = PerformanceCounters.PerformanceCountersEnabled;
                }
            }
            this.initialized = true;
        }
Пример #23
0
        static CounterSetInstance CreateCounterSetInstance(string name)
        {
            CounterSetInstance workflowServiceHostCounterSetInstance = null;

            if (PartialTrustHelpers.AppDomainFullyTrusted)
            {
                try
                {
                    workflowServiceHostCounterSetInstance = workflowServiceHostCounterSet.CreateCounterSetInstance(name);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    // A conflicting instance name already exists and probably the unmanaged resource is not yet disposed.
                    FxTrace.Exception.AsWarning(exception);
                    workflowServiceHostCounterSetInstance = null;
                }
            }

            return(workflowServiceHostCounterSetInstance);
        }
 internal CounterSetInstanceCounterDataSet(CounterSetInstance thisInst)
 {
 }
        public void PerformanceCounter_PerformanceData()
        {
            // We run test in isolated process to avoid interferences on internal performance counter shared state with other tests.
            // These interferences could lead to fail also after retries
            RemoteExecutor.Invoke((string providerId, string typingCounterSetId) =>
            {
                // Create the 'Typing' counter set.
                using (CounterSet typingCounterSet = new CounterSet(Guid.Parse(providerId), Guid.Parse(typingCounterSetId), CounterSetInstanceType.Single))
                {
                    // Add the counters to the counter set definition.
                    typingCounterSet.AddCounter(1, CounterType.RawData32, "Total Words Typed");
                    typingCounterSet.AddCounter(2, CounterType.Delta32, "Words Typed In Interval");
                    typingCounterSet.AddCounter(3, CounterType.RawData32, "Letter A Pressed");
                    typingCounterSet.AddCounter(4, CounterType.RawData32, "Words Containing A");
                    typingCounterSet.AddCounter(5, CounterType.SampleFraction, "Percent of Words Containing A");
                    typingCounterSet.AddCounter(6, CounterType.SampleBase, "Percent Base");
                    typingCounterSet.AddCounter(7, CounterType.SampleBase);

                    // Create an instance of the counter set (contains the counter data).
                    using (CounterSetInstance typingCsInstance = typingCounterSet.CreateCounterSetInstance("Typing Instance"))
                    {
                        typingCsInstance.Counters[1].Value = 0;
                        typingCsInstance.Counters[2].Value = 0;
                        typingCsInstance.Counters[3].Value = 0;
                        typingCsInstance.Counters[4].Value = 0;
                        typingCsInstance.Counters[5].Value = 0;
                        typingCsInstance.Counters[6].Value = 0;

                        // Instance counters readers
                        using (PerformanceCounter totalWordsTyped = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Total Words Typed")),
                               wordsTypedInInterval = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Words Typed In Interval")),
                               aKeyPressed = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Letter A Pressed")),
                               wordsContainingA = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Words Containing A")),
                               percentofWordsContaingA = Helpers.RetryOnAllPlatforms(() => new PerformanceCounter("Typing", "Percent of Words Containing A")))
                        {
                            typingCsInstance.Counters[1].Increment();
                            Assert.Equal(1, typingCsInstance.Counters[1].Value);
                            Assert.Equal(1, typingCsInstance.Counters[1].RawValue);
                            Assert.Equal(1, typingCsInstance.Counters["Total Words Typed"].RawValue);
                            Assert.Equal(1, totalWordsTyped.RawValue);


                            typingCsInstance.Counters[1].Increment();
                            Assert.Equal(2, typingCsInstance.Counters[1].Value);
                            Assert.Equal(2, typingCsInstance.Counters[1].RawValue);
                            Assert.Equal(2, typingCsInstance.Counters["Total Words Typed"].RawValue);
                            Assert.Equal(2, totalWordsTyped.RawValue);

                            typingCsInstance.Counters[2].IncrementBy(3);
                            Assert.Equal(3, typingCsInstance.Counters[2].Value);
                            Assert.Equal(3, typingCsInstance.Counters[2].RawValue);
                            Assert.Equal(3, typingCsInstance.Counters["Words Typed In Interval"].RawValue);
                            Assert.Equal(3, wordsTypedInInterval.RawValue);

                            typingCsInstance.Counters[3].RawValue = 4;
                            Assert.Equal(4, typingCsInstance.Counters[3].Value);
                            Assert.Equal(4, typingCsInstance.Counters[3].RawValue);
                            Assert.Equal(4, typingCsInstance.Counters["Letter A Pressed"].RawValue);
                            Assert.Equal(4, aKeyPressed.RawValue);

                            typingCsInstance.Counters[4].Value = 5;
                            Assert.Equal(5, typingCsInstance.Counters[4].Value);
                            Assert.Equal(5, typingCsInstance.Counters[4].RawValue);
                            Assert.Equal(5, typingCsInstance.Counters["Words Containing A"].RawValue);
                            Assert.Equal(5, wordsContainingA.RawValue);

                            typingCsInstance.Counters[4].Decrement();
                            Assert.Equal(4, typingCsInstance.Counters[4].Value);
                            Assert.Equal(4, typingCsInstance.Counters[4].RawValue);
                            Assert.Equal(4, typingCsInstance.Counters["Words Containing A"].RawValue);
                            Assert.Equal(4, wordsContainingA.RawValue);
                        }
                    }
                }
            }, _fixture._providerId.ToString(), _fixture._typingCounterSetId.ToString()).Dispose();
        }
Пример #26
0
        static void Main(string[] args)
        {
            // Initialize the provider and counters

            Guid providerId = new Guid("{5AE84FD4-BF72-49c4-936E-A7473237C338}");

            Guid       geometricWavesCounterSetId = new Guid("{F7DC6E2D-9A3F-4239-AC8D-28DCE96CCA98}");
            CounterSet geometricWavesCounterSet   = new CounterSet(providerId, geometricWavesCounterSetId, CounterSetInstanceType.MultipleAggregate);

            geometricWavesCounterSet.AddCounter(1, CounterType.RawData32); //"Triangle Wave"
            geometricWavesCounterSet.AddCounter(2, CounterType.RawData32); //"Square Wave"
            CounterSetInstance geomCsInstance1 = geometricWavesCounterSet.CreateCounterSetInstance("Instance_1");
            CounterSetInstance geomCsInstance2 = geometricWavesCounterSet.CreateCounterSetInstance("Instance_2");
            CounterSetInstance geomCsInstance3 = geometricWavesCounterSet.CreateCounterSetInstance("Instance_3");

            Guid       trigWavesCounterSetId = new Guid("{F89A016D-A5D1-4ce2-8489-D5612FDD2C6F}");
            CounterSet trigWavesCounterSet   = new CounterSet(providerId, trigWavesCounterSetId, CounterSetInstanceType.Single);

            trigWavesCounterSet.AddCounter(1, CounterType.RawData32);     //"Sine Wave"
            trigWavesCounterSet.AddCounter(2, CounterType.RawData32);     //"Cosine Wave"
            trigWavesCounterSet.AddCounter(3, CounterType.RawData32);     //"Constant Value"
            trigWavesCounterSet.AddCounter(4, CounterType.RawBase32);     //"Constant Number"
            trigWavesCounterSet.AddCounter(5, CounterType.RawFraction32); //"Raw Fraction"
            CounterSetInstance trigCsInstance = trigWavesCounterSet.CreateCounterSetInstance("_Default");

            // Initialize variables used in counter calculations.
            UInt32 Degree         = 0;
            UInt32 Base           = BASE;
            UInt32 NaturalNumbers = 1;
            double Angle          = 0;
            UInt32 Sine           = 0;
            UInt32 Cosine         = 0;

            // Set the constant counter value.
            trigCsInstance.Counters[4].Value = BASE;

            Console.WriteLine("\tPress any key to quit");
            while (!Console.KeyAvailable)
            {
                // Increment the Degree value to between 0 - 360.
                Degree = (Degree + 10) % 360;

                // Increment the Natural Number counter. Set it to 1 if we reach 100.
                NaturalNumbers = ++NaturalNumbers % 100;

                Angle  = (((double)Degree) * M_PI) / (180.00);
                Sine   = Base + (UInt32)(AMPLITUDE * Math.Sin(Angle));
                Cosine = Base + (UInt32)(AMPLITUDE * Math.Cos(Angle));

                // Set raw counter data for SingleInstanceCounterSet.
                UpdataGeometricWave(geomCsInstance1, 30, Degree);
                UpdataGeometricWave(geomCsInstance2, 50, Degree);
                UpdataGeometricWave(geomCsInstance3, 80, Degree);

                //Update TrigonometricWave counters
                trigCsInstance.Counters[1].Value = Sine;
                trigCsInstance.Counters[2].Value = Cosine;
                trigCsInstance.Counters[3].Value = Base;
                trigCsInstance.Counters[5].Value = NaturalNumbers;

                //Sleep for 1 second before iterating once again to change the counter values.
                Thread.Sleep(TIME_INTERVAL);
            }
        }
Пример #27
0
 public PerfCounter(CounterSetInstance counterSetInstance, int counterId)
 {
     this.counterId          = counterId;
     this.counterSetInstance = counterSetInstance;
 }
Пример #28
0
 internal ServicePerformanceCountersV2(ServiceHostBase serviceHost)
     : base(serviceHost)
 {
     if (serviceCounterSet == null)
     {
         lock (syncRoot)
         {
             if (serviceCounterSet == null)
             {
                 CounterSet localCounterSet = CreateCounterSet();
                 // Add the counters to the counter set definition.
                 localCounterSet.AddCounter((int)PerfCounters.Calls, CounterType.RawData32, perfCounterNames[(int)PerfCounters.Calls]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.CallsPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsOutstanding, CounterType.RawData32, perfCounterNames[(int)PerfCounters.CallsOutstanding]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsFailed, CounterType.RawData32, perfCounterNames[(int)PerfCounters.CallsFailed]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsFailedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.CallsFailedPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsFaulted, CounterType.RawData32, perfCounterNames[(int)PerfCounters.CallsFaulted]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsFaultedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.CallsFaultedPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.CallDurationBase, CounterType.AverageBase, perfCounterNames[(int)PerfCounters.CallDurationBase]);
                 localCounterSet.AddCounter((int)PerfCounters.CallDuration, CounterType.AverageTimer32, perfCounterNames[(int)PerfCounters.CallDuration]);
                 localCounterSet.AddCounter((int)PerfCounters.SecurityValidationAuthenticationFailures, CounterType.RawData32, perfCounterNames[(int)PerfCounters.SecurityValidationAuthenticationFailures]);
                 localCounterSet.AddCounter((int)PerfCounters.SecurityValidationAuthenticationFailuresPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.SecurityValidationAuthenticationFailuresPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsNotAuthorized, CounterType.RawData32, perfCounterNames[(int)PerfCounters.CallsNotAuthorized]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsNotAuthorizedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.CallsNotAuthorizedPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.Instances, CounterType.RawData32, perfCounterNames[(int)PerfCounters.Instances]);
                 localCounterSet.AddCounter((int)PerfCounters.InstancesRate, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.InstancesRate]);
                 localCounterSet.AddCounter((int)PerfCounters.RMSessionsFaulted, CounterType.RawData32, perfCounterNames[(int)PerfCounters.RMSessionsFaulted]);
                 localCounterSet.AddCounter((int)PerfCounters.RMSessionsFaultedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.RMSessionsFaultedPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.RMMessagesDropped, CounterType.RawData32, perfCounterNames[(int)PerfCounters.RMMessagesDropped]);
                 localCounterSet.AddCounter((int)PerfCounters.RMMessagesDroppedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.RMMessagesDroppedPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.TxFlowed, CounterType.RawData32, perfCounterNames[(int)PerfCounters.TxFlowed]);
                 localCounterSet.AddCounter((int)PerfCounters.TxFlowedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.TxFlowedPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.TxCommitted, CounterType.RawData32, perfCounterNames[(int)PerfCounters.TxCommitted]);
                 localCounterSet.AddCounter((int)PerfCounters.TxCommittedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.TxCommittedPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.TxAborted, CounterType.RawData32, perfCounterNames[(int)PerfCounters.TxAborted]);
                 localCounterSet.AddCounter((int)PerfCounters.TxAbortedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.TxAbortedPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.TxInDoubt, CounterType.RawData32, perfCounterNames[(int)PerfCounters.TxInDoubt]);
                 localCounterSet.AddCounter((int)PerfCounters.TxInDoubtPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.TxInDoubtPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.MsmqPoisonMessages, CounterType.RawData32, perfCounterNames[(int)PerfCounters.MsmqPoisonMessages]);
                 localCounterSet.AddCounter((int)PerfCounters.MsmqPoisonMessagesPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.MsmqPoisonMessagesPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.MsmqRejectedMessages, CounterType.RawData32, perfCounterNames[(int)PerfCounters.MsmqRejectedMessages]);
                 localCounterSet.AddCounter((int)PerfCounters.MsmqRejectedMessagesPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.MsmqRejectedMessagesPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.MsmqDroppedMessages, CounterType.RawData32, perfCounterNames[(int)PerfCounters.MsmqDroppedMessages]);
                 localCounterSet.AddCounter((int)PerfCounters.MsmqDroppedMessagesPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.MsmqDroppedMessagesPerSecond]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsPercentMaxCalls, CounterType.RawFraction32, perfCounterNames[(int)PerfCounters.CallsPercentMaxCalls]);
                 localCounterSet.AddCounter((int)PerfCounters.CallsPercentMaxCallsBase, CounterType.RawBase32, perfCounterNames[(int)PerfCounters.CallsPercentMaxCallsBase]);
                 localCounterSet.AddCounter((int)PerfCounters.InstancesPercentMaxInstances, CounterType.RawFraction32, perfCounterNames[(int)PerfCounters.InstancesPercentMaxInstances]);
                 localCounterSet.AddCounter((int)PerfCounters.InstancesPercentMaxInstancesBase, CounterType.RawBase32, perfCounterNames[(int)PerfCounters.InstancesPercentMaxInstancesBase]);
                 localCounterSet.AddCounter((int)PerfCounters.SessionsPercentMaxSessions, CounterType.RawFraction32, perfCounterNames[(int)PerfCounters.SessionsPercentMaxSessions]);
                 localCounterSet.AddCounter((int)PerfCounters.SessionsPercentMaxSessionsBase, CounterType.RawBase32, perfCounterNames[(int)PerfCounters.SessionsPercentMaxSessionsBase]);
                 serviceCounterSet = localCounterSet;
             }
         }
     }
     // Create an instance of the counter set (contains the counter data).
     this.serviceCounterSetInstance = CreateCounterSetInstance(this.InstanceName);
     this.counters = new CounterData[(int)PerfCounters.TotalCounters]; // Cache to dodge dictionary lookups in ServiceModelInstance
     for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
     {
         this.counters[i]       = this.serviceCounterSetInstance.Counters[i];
         this.counters[i].Value = 0;
     }
 }