Esempio n. 1
0
 public PerformanceSample(PerformanceSample other)
 {
     _counterInfo  = other._counterInfo;
     _instanceName = other._instanceName;
     _timestamp    = other._timestamp;
     _value        = other._value;
 }
Esempio n. 2
0
 public PerformanceSample(PerformanceSample other)
 {
     _counterInfo = other._counterInfo;
     _instanceName = other._instanceName;
     _timestamp = other._timestamp;
     _value = other._value;
 }
Esempio n. 3
0
 internal PerformanceSample(PerfCounterInfo counterInfo, string instanceName, DateTime timestamp, double value)
 {
     _counterInfo  = counterInfo;
     _instanceName = instanceName;
     _timestamp    = timestamp;
     _value        = value;
 }
Esempio n. 4
0
 internal PerformanceSample(PerfCounterInfo counterInfo, string instanceName, DateTime timestamp, double value)
 {
     _counterInfo = counterInfo;
     _instanceName = instanceName;
     _timestamp = timestamp;
     _value = value;
 }
Esempio n. 5
0
        protected void AddCounter(string counterPath, int index)
        {
            PdhCounterHandle counter;
            PdhStatus status = PdhNativeMethods.PdhAddCounter(_query, counterPath, IntPtr.Zero, out counter);
            if (status == PdhStatus.PDH_ENTRY_NOT_IN_LOG_FILE)
                return;

            PdhUtils.CheckStatus(status, PdhStatus.PDH_CSTATUS_VALID_DATA);

            var counterInfo = new PerfCounterInfo(counterPath, counter, index);
            _counters.Add(counterInfo);
        }
Esempio n. 6
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);
                    }
                }
            }
        }
Esempio n. 7
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);
                    }
                }
            }
        }
Esempio n. 8
0
        protected void AddCounter(string counterPath, int index)
        {
            PdhCounterHandle counter;
            PdhStatus        status = PdhNativeMethods.PdhAddCounter(_query, counterPath, IntPtr.Zero, out counter);

            if (status == PdhStatus.PDH_ENTRY_NOT_IN_LOG_FILE || status == PdhStatus.PDH_CSTATUS_NO_INSTANCE)
            {
                return;
            }

            PdhUtils.CheckStatus(status, PdhStatus.PDH_CSTATUS_VALID_DATA);

            var counterInfo = new PerfCounterInfo(counterPath, counter, index);

            _counters.Add(counterInfo);
        }