Beispiel #1
0
        private PerformanceCounterSample GetFormattedCounterSample(IntPtr counterHandle, string name, CounterInfo info, PDH_RAW_COUNTER rawCounter)
        {
            IntPtr   counterType = new IntPtr(0);
            long     fileTime    = (((long)rawCounter.TimeStamp.dwHighDateTime) << 0x20) + rawCounter.TimeStamp.dwLowDateTime;
            DateTime timeStamp2  = new DateTime(DateTime.FromFileTimeUtc(fileTime).Ticks, DateTimeKind.Local);
            PDH_FMT_COUNTERVALUE_DOUBLE doubleFormattedCounter;
            uint returnCode = Apis.PdhGetFormattedCounterValue(counterHandle, PdhFormat.PDH_FMT_NOCAP100 + PdhFormat.PDH_FMT_DOUBLE, out counterType, out doubleFormattedCounter);

            //vista and above, any non-valid result is returned like this
            if ((!_isPreVista && (returnCode != PdhResults.PDH_CSTATUS_VALID_DATA)) ||
                //below vista, return data for no_data and invalid_data, otherwise throw
                (_isPreVista && (returnCode == PdhResults.PDH_INVALID_DATA || returnCode == PdhResults.PDH_NO_DATA)))
            {
                return(new PerformanceCounterSample(name, this._consumerPathToHandleAndInstanceMap[name].InstanceName,
                                                    0.0, (ulong)rawCounter.FirstValue, (ulong)rawCounter.SecondValue, rawCounter.MultiCount,
                                                    //TODO: not sure if its useful to stuff a bad returnCode in for status, as VerifySamples will throw when status isn't 0... not sure that's useful
                                                    //TODO: original code just uses pdh_raw_counter.CStatus when _isPreVista
                                                    (PerformanceCounterType)info.Type, info.DefaultScale, info.TimeBase, timeStamp2, (ulong)fileTime, (doubleFormattedCounter.CStatus == 0) ? returnCode : rawCounter.CStatus));
            }
            else if (_isPreVista && (returnCode != PdhResults.PDH_CSTATUS_VALID_DATA))
            {
                throw BuildException(returnCode);
            }

            return(new PerformanceCounterSample(name, this._consumerPathToHandleAndInstanceMap[name].InstanceName,
                                                doubleFormattedCounter.doubleValue, (ulong)rawCounter.FirstValue, (ulong)rawCounter.SecondValue, rawCounter.MultiCount,
                                                (PerformanceCounterType)counterType.ToInt32(), info.DefaultScale, info.TimeBase, timeStamp2, (ulong)fileTime, doubleFormattedCounter.CStatus));
        }
Beispiel #2
0
 public static extern uint PdhGetRawCounterValue(IntPtr hCounter, out IntPtr lpdwType, out PDH_RAW_COUNTER pValue);
Beispiel #3
0
        private PerformanceCounterSample GetFormattedCounterSample(IntPtr counterHandle, string name, CounterInfo info, PDH_RAW_COUNTER rawCounter)
        {
            IntPtr counterType = new IntPtr(0);
            long fileTime = (((long)rawCounter.TimeStamp.dwHighDateTime) << 0x20) + rawCounter.TimeStamp.dwLowDateTime;
            DateTime timeStamp2 = new DateTime(DateTime.FromFileTimeUtc(fileTime).Ticks, DateTimeKind.Local);
            PDH_FMT_COUNTERVALUE_DOUBLE doubleFormattedCounter;
            uint returnCode = Apis.PdhGetFormattedCounterValue(counterHandle, PdhFormat.PDH_FMT_NOCAP100 + PdhFormat.PDH_FMT_DOUBLE, out counterType, out doubleFormattedCounter);

            //vista and above, any non-valid result is returned like this
            if ((!_isPreVista && (returnCode != PdhResults.PDH_CSTATUS_VALID_DATA)) ||
                //below vista, return data for no_data and invalid_data, otherwise throw
                (_isPreVista && (returnCode == PdhResults.PDH_INVALID_DATA || returnCode == PdhResults.PDH_NO_DATA)))
            {
                return new PerformanceCounterSample(name, this._consumerPathToHandleAndInstanceMap[name].InstanceName,
                    0.0, (ulong)rawCounter.FirstValue, (ulong)rawCounter.SecondValue, rawCounter.MultiCount,
                    //TODO: not sure if its useful to stuff a bad returnCode in for status, as VerifySamples will throw when status isn't 0... not sure that's useful
                    //TODO: original code just uses pdh_raw_counter.CStatus when _isPreVista
                    (PerformanceCounterType)info.Type, info.DefaultScale, info.TimeBase, timeStamp2, (ulong)fileTime, (doubleFormattedCounter.CStatus == 0) ? returnCode : rawCounter.CStatus);
            }
            else if (_isPreVista && (returnCode != PdhResults.PDH_CSTATUS_VALID_DATA))
            {
                throw BuildException(returnCode);
            }

            return new PerformanceCounterSample(name, this._consumerPathToHandleAndInstanceMap[name].InstanceName,
                doubleFormattedCounter.doubleValue, (ulong)rawCounter.FirstValue, (ulong)rawCounter.SecondValue, rawCounter.MultiCount,
                (PerformanceCounterType)counterType.ToInt32(), info.DefaultScale, info.TimeBase, timeStamp2, (ulong)fileTime, doubleFormattedCounter.CStatus);
        }
Beispiel #4
0
 public static extern uint PdhGetRawCounterValue(IntPtr hCounter, out IntPtr lpdwType, out PDH_RAW_COUNTER pValue);