コード例 #1
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);
            }
        }
コード例 #2
0
        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);
        }