public long AddRelogCountersPreservingPaths(PerformanceCounterSampleSet sampleSet) { long num = 0; foreach (PerformanceCounterSample sample in sampleSet.CounterSamples) { PDH_COUNTER_PATH_ELEMENTS pCounterPathElements = new PDH_COUNTER_PATH_ELEMENTS(); num = this.ParsePath(sample.Path, ref pCounterPathElements); if (num == 0) { IntPtr ptr; num = PdhAddRelogCounter(this.m_hQuery, sample.Path, (long)sample.CounterType, sample.DefaultScale, sample.TimeBase, out ptr); if (num == 0) { CounterHandleNInstance instance = new CounterHandleNInstance { hCounter = ptr }; if (pCounterPathElements.InstanceName != null) { instance.InstanceName = pCounterPathElements.InstanceName.ToLower(CultureInfo.InvariantCulture); } if (!this.m_ReloggerPathToHandleAndInstanceMap.ContainsKey(sample.Path.ToLower(CultureInfo.InvariantCulture))) { this.m_ReloggerPathToHandleAndInstanceMap.Add(sample.Path.ToLower(CultureInfo.InvariantCulture), instance); } } } } if (this.m_ReloggerPathToHandleAndInstanceMap.Keys.Count <= 0) { return(num); } return(0); }
private void WriteSampleSetObject(PerformanceCounterSampleSet set) { foreach (PerformanceCounterSample sample in set.CounterSamples) { if (sample.Status != 0) { Exception exception = new Exception(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("CounterSampleDataInvalid"), new object[0])); base.WriteError(new ErrorRecord(exception, "CounterApiError", ErrorCategory.InvalidResult, null)); break; } } base.WriteObject(set); }
// // WriteSampleSetObject() helper. // In addition to writing the PerformanceCounterSampleSet object, // it writes a single error if one of the samples has an invalid (non-zero) status. // The only exception is the first set, where we allow for the formatted value to be 0 - // this is expected for CSV and TSV files. private void WriteSampleSetObject(PerformanceCounterSampleSet set, bool firstSet) { if (!firstSet) { foreach (PerformanceCounterSample sample in set.CounterSamples) { if (sample.Status != 0) { string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterSampleDataInvalid")); Exception exc = new Exception(msg); WriteError(new ErrorRecord(exc, "CounterApiError", ErrorCategory.InvalidResult, null)); break; } } } WriteObject(set); }
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 long AddRelogCounters(PerformanceCounterSampleSet sampleSet) { long num = 0; Dictionary <string, List <PerformanceCounterSample> > dictionary = new Dictionary <string, List <PerformanceCounterSample> >(); foreach (PerformanceCounterSample sample in sampleSet.CounterSamples) { PDH_COUNTER_PATH_ELEMENTS pCounterPathElements = new PDH_COUNTER_PATH_ELEMENTS(); num = this.ParsePath(sample.Path, ref pCounterPathElements); if (num == 0) { List <PerformanceCounterSample> list; string str = pCounterPathElements.MachineName.ToLower(CultureInfo.InvariantCulture); string str2 = pCounterPathElements.ObjectName.ToLower(CultureInfo.InvariantCulture); string str3 = pCounterPathElements.CounterName.ToLower(CultureInfo.InvariantCulture); string key = @"\\" + str + @"\" + str2 + @"\" + str3; if (dictionary.TryGetValue(key, out list)) { dictionary[key].Add(sample); } else { List <PerformanceCounterSample> list2 = new List <PerformanceCounterSample> { sample }; dictionary.Add(key, list2); } } } foreach (string str5 in dictionary.Keys) { IntPtr ptr; string path = dictionary[str5][0].Path; if (dictionary[str5].Count > 1) { num = this.MakeAllInstancePath(dictionary[str5][0].Path, out path); if (num != 0) { continue; } } num = PdhAddRelogCounter(this.m_hQuery, path, (long)dictionary[str5][0].CounterType, dictionary[str5][0].DefaultScale, dictionary[str5][0].TimeBase, out ptr); if (num == 0) { foreach (PerformanceCounterSample sample2 in dictionary[str5]) { PDH_COUNTER_PATH_ELEMENTS pdh_counter_path_elements2 = new PDH_COUNTER_PATH_ELEMENTS(); num = this.ParsePath(sample2.Path, ref pdh_counter_path_elements2); if (num == 0) { CounterHandleNInstance instance = new CounterHandleNInstance { hCounter = ptr }; if (pdh_counter_path_elements2.InstanceName != null) { instance.InstanceName = pdh_counter_path_elements2.InstanceName.ToLower(CultureInfo.InvariantCulture); } if (!this.m_ReloggerPathToHandleAndInstanceMap.ContainsKey(sample2.Path.ToLower(CultureInfo.InvariantCulture))) { this.m_ReloggerPathToHandleAndInstanceMap.Add(sample2.Path.ToLower(CultureInfo.InvariantCulture), instance); } } } } } if (this.m_ReloggerPathToHandleAndInstanceMap.Keys.Count <= 0) { return(num); } return(0); }