public void PerformanceCounter_PerformanceData_CreateCounterSetInstance_EmptyCounters()
 {
     using (CounterSet typingCounterSet = new CounterSet(_fixture._providerId, _fixture._typingCounterSetId, CounterSetInstanceType.Single))
     {
         Assert.Throws <InvalidOperationException>(() => typingCounterSet.CreateCounterSetInstance("Typing Instance"));
     }
 }
        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);
        }
 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]);
         }
     }
 }
 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"));
         }
     }
 }
 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]);
         }
     }
 }
Пример #6
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);
            }
        }
Пример #7
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);
        }
Пример #8
0
 static CounterSetInstance CreateCounterSetInstance(string name)
 {
     return(counterSetInstanceCache.Get(name) ?? endpointCounterSet.CreateCounterSetInstance(name));
 }
        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();
        }
 public void PerformanceCounter_PerformanceData_CounterSet_InvalidInstanceName(string instanceName, Type exceptionType)
 {
     using (CounterSet typingCounterSet = new CounterSet(_fixture._providerId, _fixture._typingCounterSetId, CounterSetInstanceType.Single))
     {
         typingCounterSet.AddCounter(6, CounterType.SampleBase, "Percent Base");
         ArgumentException argumentException = (ArgumentException)Assert.Throws(exceptionType, () => typingCounterSet.CreateCounterSetInstance(instanceName));
         Assert.Equal("instanceName", argumentException.ParamName);
     }
 }
 static CounterSetInstance CreateCounterSetInstance(string name)
 {
     return(counterSetInstanceCache.Get(name) ?? operationCounterSet.CreateCounterSetInstance(name));
 }
Пример #12
0
 private static CounterSetInstance CreateCounterSetInstance(string name)
 {
     return(endpointCounterSet.CreateCounterSetInstance(name));
 }
Пример #13
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);
            }
        }
 private static CounterSetInstance CreateCounterSetInstance(string name)
 {
     return(serviceCounterSet.CreateCounterSetInstance(name));
 }
 private static CounterSetInstance CreateCounterSetInstance(string name)
 {
     return(operationCounterSet.CreateCounterSetInstance(name));
 }