コード例 #1
0
 /// <summary>
 /// Simulate performance counter calculation using 3 samples
 /// </summary>
 /// <param name="perfCounter"></param>
 private static void CalculatePerfCounter(PerfCounter perfCounter)
 {
     perfCounter.Initialize();
     System.Threading.Thread.Sleep(1000);
     perfCounter.NextValue();
     System.Threading.Thread.Sleep(1000);
     perfCounter.NextValue();
     System.Threading.Thread.Sleep(1000);
     perfCounter.NextValue();
     perfCounter.Calculate();
 }
コード例 #2
0
        public void PerfCounter_CalculateAverageResult_AverageResult()
        {
            var   perfCounter = new PerfCounter("Memory", "Available MBytes", "none", "AvailableMBytes", "MB", "10%", "5%", "0", "automemory");
            float result      = 0;

            perfCounter.Initialize();
            System.Threading.Thread.Sleep(1000);
            result += perfCounter.NextValue();
            System.Threading.Thread.Sleep(1000);
            result += perfCounter.NextValue();
            System.Threading.Thread.Sleep(1000);
            result += perfCounter.NextValue();
            perfCounter.Calculate();
            Assert.AreEqual(perfCounter.GetResult(), result / 3);
        }
コード例 #3
0
            public void GetNextPlot()
            {
                int iNewVal = 0;

                switch (CounterType)
                {
                case CounterTypes.CPU:
                    iNewVal = (int)PerfCounter.NextValue();
                    break;

                case CounterTypes.RAM:
                    int iUsed = iTotalRam - (int)PerfCounter.NextValue();
                    iNewVal = (int)((float)iUsed / (float)iTotalRam * (float)100);                             // Convert to percentage.
                    break;
                }

                // Add new value to the short buffer.
                for (int i = 0; i < _ShortBuffer.Length - 1; i++)
                {
                    _ShortBuffer[i] = _ShortBuffer[i + 1];
                }
                _ShortBuffer[_ShortBuffer.Length - 1] = iNewVal;

                // Add new value to the long buffer.
                for (int i = 0; i < _LongBuffer.Length - 1; i++)
                {
                    _LongBuffer[i] = _LongBuffer[i + 1];
                }
                _LongBuffer[_LongBuffer.Length - 1] = iNewVal;

                // Calculate the mean over the short buffer.
                ShortAverage = (int)_ShortBuffer.Average();

                // Calculate the mean over the long buffer.
                LongAverage = (int)_LongBuffer.Average();
            }
コード例 #4
0
        public void PerfCounter_NextValueWithoutInitializingCounter_ThrowsAnException()
        {
            var perfCounter = new PerfCounter("Processor", "% Processor Time", "_Total", "ProcessorTime", "%", "5", "10", "0", "100");

            perfCounter.NextValue();
        }