Пример #1
0
 public bool Equals(CounterSample other)
 {
     return
         (rawValue == other.rawValue &&
          baseValue == other.counterFrequency &&
          counterFrequency == other.counterFrequency &&
          systemFrequency == other.systemFrequency &&
          timeStamp == other.timeStamp &&
          timeStamp100nSec == other.timeStamp100nSec &&
          counterTimeStamp == other.counterTimeStamp &&
          counterType == other.counterType);
 }
Пример #2
0
        // may throw InvalidOperationException, Win32Exception
        public CounterSample NextSample()
        {
            CounterSample sample;

            if (changed)
            {
                UpdateInfo();
            }
            GetSample(impl, false, out sample);
            valid_old  = true;
            old_sample = sample;
            return(sample);
        }
Пример #3
0
        public static float ComputeCounterValue(CounterSample newSample)
        {
            switch (newSample.CounterType)
            {
            case PerformanceCounterType.RawFraction:
            case PerformanceCounterType.NumberOfItems32:
            case PerformanceCounterType.NumberOfItemsHEX32:
            case PerformanceCounterType.NumberOfItems64:
            case PerformanceCounterType.NumberOfItemsHEX64:
                return((float)newSample.RawValue);

            default:
                return(0);
            }
        }
Пример #4
0
        // may throw InvalidOperationException, Win32Exception
        public float NextValue()
        {
            CounterSample sample;

            if (changed)
            {
                UpdateInfo();
            }
            GetSample(impl, false, out sample);
            float val;

            if (valid_old)
            {
                val = CounterSampleCalculator.ComputeCounterValue(old_sample, sample);
            }
            else
            {
                val = CounterSampleCalculator.ComputeCounterValue(sample);
            }
            valid_old  = true;
            old_sample = sample;
            return(val);
        }
Пример #5
0
        public static float ComputeCounterValue(CounterSample oldSample,
                                                CounterSample newSample)
        {
            if (newSample.CounterType != oldSample.CounterType)
            {
                throw new Exception("The counter samples must be of the same type");
            }
            switch (newSample.CounterType)
            {
            case PerformanceCounterType.RawFraction:
            case PerformanceCounterType.NumberOfItems32:
            case PerformanceCounterType.NumberOfItemsHEX32:
            case PerformanceCounterType.NumberOfItems64:
            case PerformanceCounterType.NumberOfItemsHEX64:
                return((float)newSample.RawValue);

            case PerformanceCounterType.AverageCount64:
                return((float)(newSample.RawValue - oldSample.RawValue) / (float)(newSample.BaseValue - oldSample.BaseValue));

            case PerformanceCounterType.AverageTimer32:
                return((((float)(newSample.RawValue - oldSample.RawValue)) / newSample.SystemFrequency) / (float)(newSample.BaseValue - oldSample.BaseValue));

            case PerformanceCounterType.CounterDelta32:
            case PerformanceCounterType.CounterDelta64:
                return((float)(newSample.RawValue - oldSample.RawValue));

            case PerformanceCounterType.CounterMultiTimer:
                return(((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp) * 100.0f / newSample.BaseValue);

            case PerformanceCounterType.CounterMultiTimer100Ns:
                return(((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec) * 100.0f / newSample.BaseValue);

            case PerformanceCounterType.CounterMultiTimerInverse:
                return((newSample.BaseValue - ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp)) * 100.0f);

            case PerformanceCounterType.CounterMultiTimer100NsInverse:
                return((newSample.BaseValue - ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec)) * 100.0f);

            case PerformanceCounterType.CounterTimer:
            case PerformanceCounterType.CountPerTimeInterval32:
            case PerformanceCounterType.CountPerTimeInterval64:
                return(((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp));

            case PerformanceCounterType.CounterTimerInverse:
                return((1.0f - ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec)) * 100.0f);

            case PerformanceCounterType.ElapsedTime:
                // FIXME
                return(0);

            case PerformanceCounterType.Timer100Ns:
                return(((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp) * 100.0f);

            case PerformanceCounterType.Timer100NsInverse:
                return((1f - ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp)) * 100.0f);

            case PerformanceCounterType.RateOfCountsPerSecond32:
            case PerformanceCounterType.RateOfCountsPerSecond64:
                return(((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp) * 10000000);

            default:
                Console.WriteLine("Counter type {0} not handled", newSample.CounterType);
                return(0);
            }
        }
Пример #6
0
 static extern bool GetSample(IntPtr impl, bool only_value, out CounterSample sample);
Пример #7
0
 public static float Calculate(CounterSample counterSample,
                               CounterSample nextCounterSample)
 {
     return(CounterSampleCalculator.ComputeCounterValue(counterSample, nextCounterSample));
 }