Exemplo n.º 1
0
 public PerformanceSample(PerformanceSample other)
 {
     _counterInfo  = other._counterInfo;
     _instanceName = other._instanceName;
     _timestamp    = other._timestamp;
     _value        = other._value;
 }
Exemplo n.º 2
0
 public PerformanceSample(PerformanceSample other)
 {
     _counterInfo = other._counterInfo;
     _instanceName = other._instanceName;
     _timestamp = other._timestamp;
     _value = other._value;
 }
Exemplo n.º 3
0
        private void CounterAdded(PerformanceSample counter)
        {
            _chart.BeginInit();

            AddPoint(counter.Value, counter.CounterName);

            _chart.Invalidate();
            _chart.EndInit();
        }
Exemplo n.º 4
0
        internal void ProduceCounterSamples(PerfCounterInfo counterInfo, DateTime timestamp)
        {
            uint bufferSize = 0;
            uint bufferCount;

            PdhStatus status = PdhNativeMethods.PdhGetFormattedCounterArray(
                counterInfo.Handle,
                PdhFormat.PDH_FMT_DOUBLE,
                ref bufferSize,
                out bufferCount,
                IntPtr.Zero);

            PdhUtils.CheckStatus(status, PdhStatus.PDH_MORE_DATA);

            var buffer = new byte[bufferSize];

            unsafe
            {
                fixed(byte *pb = buffer)
                {
                    status = PdhNativeMethods.PdhGetFormattedCounterArray(
                        counterInfo.Handle,
                        PdhFormat.PDH_FMT_DOUBLE,
                        ref bufferSize,
                        out bufferCount,
                        (IntPtr)pb);
                    if (status == PdhStatus.PDH_INVALID_DATA ||
                        status == PdhStatus.PDH_NO_DATA ||
                        status == PdhStatus.PDH_CALC_NEGATIVE_VALUE ||
                        status == PdhStatus.PDH_CALC_NEGATIVE_DENOMINATOR ||
                        status == PdhStatus.PDH_CALC_NEGATIVE_TIMEBASE)
                    {
                        var sample = new PerformanceSample(counterInfo, counterInfo.Instance, timestamp, double.NaN);
                        _observer.OnNext(sample);
                        return;
                    }

                    PdhUtils.CheckStatus(status, PdhStatus.PDH_CSTATUS_VALID_DATA);

                    var items = (PDH_FMT_COUNTERVALUE_ITEM *)pb;

                    for (int i = 0; i < bufferCount; i++)
                    {
                        PDH_FMT_COUNTERVALUE_ITEM *item = items + i;
                        var instanceName = new string((char *)item->szName);
                        var sample       = new PerformanceSample(counterInfo, instanceName, timestamp, item->FmtValue.doubleValue);

                        _observer.OnNext(sample);
                    }
                }
            }
        }
Exemplo n.º 5
0
        internal void ProduceCounterSamples(PerfCounterInfo counterInfo, DateTime timestamp)
        {
            uint bufferSize = 0;
            uint bufferCount;

            PdhStatus status = PdhNativeMethods.PdhGetFormattedCounterArray(
                counterInfo.Handle,
                PdhFormat.PDH_FMT_DOUBLE,
                ref bufferSize,
                out bufferCount,
                IntPtr.Zero);
            PdhUtils.CheckStatus(status, PdhStatus.PDH_MORE_DATA);

            var buffer = new byte[bufferSize];
            unsafe
            {
                fixed (byte* pb = buffer)
                {
                    status = PdhNativeMethods.PdhGetFormattedCounterArray(
                        counterInfo.Handle,
                        PdhFormat.PDH_FMT_DOUBLE,
                        ref bufferSize,
                        out bufferCount,
                        (IntPtr) pb);
                    if (status == PdhStatus.PDH_INVALID_DATA
                        || status == PdhStatus.PDH_CALC_NEGATIVE_VALUE
                        || status == PdhStatus.PDH_CALC_NEGATIVE_DENOMINATOR
                        || status == PdhStatus.PDH_CALC_NEGATIVE_TIMEBASE)
                    {
                        var sample = new PerformanceSample(counterInfo, counterInfo.Instance, timestamp, double.NaN);
                        _observer.OnNext(sample);
                        return;
                    }

                    PdhUtils.CheckStatus(status, PdhStatus.PDH_CSTATUS_VALID_DATA);

                    var items = (PDH_FMT_COUNTERVALUE_ITEM*) pb;
                    for (int i = 0; i < bufferCount; i++)
                    {
                        PDH_FMT_COUNTERVALUE_ITEM* item = items + i;
                        var instanceName = new string((char*)item->szName);
                        var sample = new PerformanceSample(counterInfo, instanceName, timestamp, item->FmtValue.doubleValue);

                        _observer.OnNext(sample);
                    }
                }
            }
        }