internal PerformanceCounterSampleSet(DateTime timeStamp, PerformanceCounterSample[] counterSamples, bool firstSet) : this() { this._timeStamp = timeStamp; this._counterSamples = counterSamples; }
public long SetCounterValue(PerformanceCounterSample sample, out bool bUnknownPath) { bUnknownPath = false; string key = sample.Path.ToLower(CultureInfo.InvariantCulture); if (!this.m_ReloggerPathToHandleAndInstanceMap.ContainsKey(key)) { bUnknownPath = true; return 0; } PDH_RAW_COUNTER pdh_raw_counter = new PDH_RAW_COUNTER { FirstValue = (long) sample.RawValue, SecondValue = (long) sample.SecondValue, MultiCount = sample.MultipleCount }; DateTime time2 = new DateTime(sample.Timestamp.Ticks, DateTimeKind.Utc); pdh_raw_counter.TimeStamp.dwHighDateTime = (int) (((ulong) (time2.ToFileTimeUtc() >> 0x20)) & 0xffffffffL); DateTime time4 = new DateTime(sample.Timestamp.Ticks, DateTimeKind.Utc); pdh_raw_counter.TimeStamp.dwLowDateTime = (int) (((ulong) time4.ToFileTimeUtc()) & 0xffffffffL); pdh_raw_counter.CStatus = sample.Status; return PdhSetCounterValue(this.m_ReloggerPathToHandleAndInstanceMap[key].hCounter, ref pdh_raw_counter, this.m_ReloggerPathToHandleAndInstanceMap[key].InstanceName); }
public uint SetCounterValue(PerformanceCounterSample sample, out bool bUnknownPath) { Debug.Assert(_hOutputLog != null && !_hOutputLog.IsInvalid); bUnknownPath = false; string lcPath = sample.Path.ToLower(CultureInfo.InvariantCulture); if (!_reloggerPathToHandleAndInstanceMap.ContainsKey(lcPath)) { bUnknownPath = true; return 0; } PDH_RAW_COUNTER rawStruct = new PDH_RAW_COUNTER(); rawStruct.FirstValue = (long)sample.RawValue; rawStruct.SecondValue = (long)sample.SecondValue; rawStruct.MultiCount = sample.MultipleCount; rawStruct.TimeStamp.dwHighDateTime = (int)((new DateTime(sample.Timestamp.Ticks, DateTimeKind.Utc).ToFileTimeUtc() >> 32) & 0xFFFFFFFFL); rawStruct.TimeStamp.dwLowDateTime = (int)(new DateTime(sample.Timestamp.Ticks, DateTimeKind.Utc).ToFileTimeUtc() & 0xFFFFFFFFL); rawStruct.CStatus = sample.Status; return PdhSetCounterValue(_reloggerPathToHandleAndInstanceMap[lcPath].hCounter, ref rawStruct, /*PPDH_RAW_COUNTER */ _reloggerPathToHandleAndInstanceMap[lcPath].InstanceName); }
public long ReadNextSetPreVista(out PerformanceCounterSampleSet nextSet, bool bSkipReading) { long num = 0; nextSet = null; num = PdhCollectQueryData(this.m_hQuery); if (bSkipReading) { return num; } if ((num != 0) && (num != 0x800007d5L)) { return num; } PerformanceCounterSample[] counterSamples = new PerformanceCounterSample[this.m_ConsumerPathToHandleAndInstanceMap.Count]; long num2 = 0; long num3 = 0; long num4 = 0; DateTime now = DateTime.Now; foreach (string str in this.m_ConsumerPathToHandleAndInstanceMap.Keys) { PDH_RAW_COUNTER pdh_raw_counter; IntPtr lpdwType = new IntPtr(0); long counterType = 0x40030403; long defaultScale = 0; ulong timeBase = 0L; IntPtr hCounter = this.m_ConsumerPathToHandleAndInstanceMap[str].hCounter; this.GetCounterInfoPlus(hCounter, out counterType, out defaultScale, out timeBase); num = PdhGetRawCounterValue(hCounter, out lpdwType, out pdh_raw_counter); switch (num) { case 0xc0000bc6L: case 0x800007d5L: counterSamples[num2++] = new PerformanceCounterSample(str, this.m_ConsumerPathToHandleAndInstanceMap[str].InstanceName, 0.0, 0L, 0L, 0, PerformanceCounterType.RawBase, defaultScale, timeBase, DateTime.Now, (ulong) DateTime.Now.ToFileTime(), pdh_raw_counter.CStatus); num3++; num4 = num; break; default: { PDH_FMT_COUNTERVALUE_DOUBLE pdh_fmt_countervalue_double; if (num != 0) { return num; } long fileTime = (pdh_raw_counter.TimeStamp.dwHighDateTime << 0x20) + ((long) ((ulong) pdh_raw_counter.TimeStamp.dwLowDateTime)); now = new DateTime(DateTime.FromFileTimeUtc(fileTime).Ticks, DateTimeKind.Local); num = PdhGetFormattedCounterValue(hCounter, 0x8200, out lpdwType, out pdh_fmt_countervalue_double); switch (num) { case 0xc0000bc6L: case 0x800007d5L: { counterSamples[num2++] = new PerformanceCounterSample(str, this.m_ConsumerPathToHandleAndInstanceMap[str].InstanceName, 0.0, (ulong) pdh_raw_counter.FirstValue, (ulong) pdh_raw_counter.SecondValue, pdh_raw_counter.MultiCount, (PerformanceCounterType) counterType, defaultScale, timeBase, now, (ulong) fileTime, pdh_fmt_countervalue_double.CStatus); num3++; num4 = num; continue; } } if (num != 0) { return num; } counterSamples[num2++] = new PerformanceCounterSample(str, this.m_ConsumerPathToHandleAndInstanceMap[str].InstanceName, pdh_fmt_countervalue_double.doubleValue, (ulong) pdh_raw_counter.FirstValue, (ulong) pdh_raw_counter.SecondValue, pdh_raw_counter.MultiCount, (PerformanceCounterType) lpdwType.ToInt32(), defaultScale, timeBase, now, (ulong) fileTime, pdh_fmt_countervalue_double.CStatus); break; } } } nextSet = new PerformanceCounterSampleSet(now, counterSamples, this.m_firstReading); this.m_firstReading = false; if (num3 == counterSamples.Length) { return num4; } return 0; }
public uint ReadNextSet(out PerformanceCounterSampleSet nextSet, bool bSkipReading) { Debug.Assert(_hQuery != null && !_hQuery.IsInvalid); if (_isPreVista) { return ReadNextSetPreVista(out nextSet, bSkipReading); } uint res = 0; nextSet = null; Int64 batchTimeStampFT = 0; res = PdhCollectQueryDataWithTime(_hQuery, ref batchTimeStampFT); if (bSkipReading) { return res; } if (res != 0 && res != PdhResults.PDH_NO_DATA) { return res; } // // NOTE: PDH returns the filetime as local time, therefore // we need to call FromFileTimUtc() to avoid .NET applying the timezone adjustment. // However, that would result in the DateTime object having Kind.Utc. // We have to copy it once more to correct that (Kind is a read-only property). // DateTime batchStamp = DateTime.Now; if (res != PdhResults.PDH_NO_DATA) { batchStamp = new DateTime(DateTime.FromFileTimeUtc(batchTimeStampFT).Ticks, DateTimeKind.Local); } PerformanceCounterSample[] samplesArr = new PerformanceCounterSample[_consumerPathToHandleAndInstanceMap.Count]; uint sampleIndex = 0; uint numInvalidDataSamples = 0; uint lastErr = 0; foreach (string path in _consumerPathToHandleAndInstanceMap.Keys) { IntPtr counterTypePtr = new IntPtr(0); UInt32 counterType = (UInt32)PerformanceCounterType.RawBase; UInt32 defaultScale = 0; UInt64 timeBase = 0; IntPtr hCounter = _consumerPathToHandleAndInstanceMap[path].hCounter; Debug.Assert(hCounter != null); res = GetCounterInfoPlus(hCounter, out counterType, out defaultScale, out timeBase); if (res != 0) { //Console.WriteLine ("GetCounterInfoPlus for " + path + " failed with " + res); } PDH_RAW_COUNTER rawValue; res = PdhGetRawCounterValue(hCounter, out counterTypePtr, out rawValue); if (res != 0) { samplesArr[sampleIndex++] = new PerformanceCounterSample(path, _consumerPathToHandleAndInstanceMap[path].InstanceName, 0, (ulong)0, (ulong)0, 0, PerformanceCounterType.RawBase, defaultScale, timeBase, batchStamp, (UInt64)batchStamp.ToFileTime(), (rawValue.CStatus == 0) ? res : rawValue.CStatus); numInvalidDataSamples++; lastErr = res; continue; } long dtFT = (((long)rawValue.TimeStamp.dwHighDateTime) << 32) + (uint)rawValue.TimeStamp.dwLowDateTime; DateTime dt = new DateTime(DateTime.FromFileTimeUtc(dtFT).Ticks, DateTimeKind.Local); PDH_FMT_COUNTERVALUE_DOUBLE fmtValueDouble; res = PdhGetFormattedCounterValue(hCounter, PdhFormat.PDH_FMT_DOUBLE | PdhFormat.PDH_FMT_NOCAP100, out counterTypePtr, out fmtValueDouble); if (res != 0) { samplesArr[sampleIndex++] = new PerformanceCounterSample(path, _consumerPathToHandleAndInstanceMap[path].InstanceName, 0, (ulong)rawValue.FirstValue, (ulong)rawValue.SecondValue, rawValue.MultiCount, (PerformanceCounterType)counterType, defaultScale, timeBase, dt, (UInt64)dtFT, (fmtValueDouble.CStatus == 0) ? res : rawValue.CStatus); numInvalidDataSamples++; lastErr = res; continue; } samplesArr[sampleIndex++] = new PerformanceCounterSample(path, _consumerPathToHandleAndInstanceMap[path].InstanceName, fmtValueDouble.doubleValue, (ulong)rawValue.FirstValue, (ulong)rawValue.SecondValue, rawValue.MultiCount, (PerformanceCounterType)counterTypePtr.ToInt32(), defaultScale, timeBase, dt, (UInt64)dtFT, fmtValueDouble.CStatus); } nextSet = new PerformanceCounterSampleSet(batchStamp, samplesArr, _firstReading); _firstReading = false; if (numInvalidDataSamples == samplesArr.Length) { res = lastErr; } else { // // Reset the error - any errors are saved per sample in PerformanceCounterSample.Status for kvetching later // res = 0; } return res; }