private string[] GetCounters(string category, ref bool categoryExists) { categoryExists = false; System.Diagnostics.CategoryEntry entry = (System.Diagnostics.CategoryEntry) this.CategoryTable[category]; if (entry == null) { return(null); } categoryExists = true; int index = 0; string[] sourceArray = new string[entry.CounterIndexes.Length]; for (int i = 0; i < sourceArray.Length; i++) { int num3 = entry.CounterIndexes[i]; string str = (string)this.NameTable[num3]; if ((str != null) && (str != string.Empty)) { sourceArray[index] = str; index++; } } if (index < sourceArray.Length) { string[] destinationArray = new string[index]; Array.Copy(sourceArray, destinationArray, index); sourceArray = destinationArray; } return(sourceArray); }
private string GetCategoryHelp(string category) { System.Diagnostics.CategoryEntry entry = (System.Diagnostics.CategoryEntry) this.CategoryTable[category]; if (entry == null) { return(null); } return((string)this.HelpTable[entry.HelpIndex]); }
private CategorySample GetCategorySample(string category) { System.Diagnostics.CategoryEntry entry = (System.Diagnostics.CategoryEntry) this.CategoryTable[category]; if (entry == null) { return(null); } byte[] performanceData = this.GetPerformanceData(entry.NameIndex.ToString(CultureInfo.InvariantCulture)); if (performanceData == null) { throw new InvalidOperationException(SR.GetString("CantReadCategory", new object[] { category })); } return(new CategorySample(performanceData, entry, this)); }
private bool CounterExists(string category, string counter, ref bool categoryExists) { categoryExists = false; if (this.CategoryTable.ContainsKey(category)) { categoryExists = true; System.Diagnostics.CategoryEntry entry = (System.Diagnostics.CategoryEntry) this.CategoryTable[category]; for (int i = 0; i < entry.CounterIndexes.Length; i++) { int num2 = entry.CounterIndexes[i]; string strA = (string)this.NameTable[num2]; if (strA == null) { strA = string.Empty; } if (string.Compare(strA, counter, StringComparison.OrdinalIgnoreCase) == 0) { return(true); } } } return(false); }
private string GetCounterHelp(string category, string counter, ref bool categoryExists) { categoryExists = false; System.Diagnostics.CategoryEntry entry = (System.Diagnostics.CategoryEntry) this.CategoryTable[category]; if (entry == null) { return(null); } categoryExists = true; int num = -1; for (int i = 0; i < entry.CounterIndexes.Length; i++) { int num3 = entry.CounterIndexes[i]; string strA = (string)this.NameTable[num3]; if (strA == null) { strA = string.Empty; } if (string.Compare(strA, counter, StringComparison.OrdinalIgnoreCase) == 0) { num = entry.HelpIndexes[i]; break; } } if (num == -1) { throw new InvalidOperationException(SR.GetString("MissingCounter", new object[] { counter })); } string str2 = (string)this.HelpTable[num]; if (str2 == null) { return(string.Empty); } return(str2); }
internal unsafe CategorySample(byte[] data, System.Diagnostics.CategoryEntry entry, PerformanceCounterLib library) { this.entry = entry; this.library = library; int nameIndex = entry.NameIndex; Microsoft.Win32.NativeMethods.PERF_DATA_BLOCK structure = new Microsoft.Win32.NativeMethods.PERF_DATA_BLOCK(); fixed (byte* numRef = data) { IntPtr ptr = new IntPtr((void*) numRef); Marshal.PtrToStructure(ptr, structure); this.SystemFrequency = structure.PerfFreq; this.TimeStamp = structure.PerfTime; this.TimeStamp100nSec = structure.PerfTime100nSec; ptr = (IntPtr) (((long) ptr) + structure.HeaderLength); int numObjectTypes = structure.NumObjectTypes; if (numObjectTypes == 0) { this.CounterTable = new Hashtable(); this.InstanceNameTable = new Hashtable(StringComparer.OrdinalIgnoreCase); return; } Microsoft.Win32.NativeMethods.PERF_OBJECT_TYPE perf_object_type = null; bool flag = false; for (int i = 0; i < numObjectTypes; i++) { perf_object_type = new Microsoft.Win32.NativeMethods.PERF_OBJECT_TYPE(); Marshal.PtrToStructure(ptr, perf_object_type); if (perf_object_type.ObjectNameTitleIndex == nameIndex) { flag = true; break; } ptr = (IntPtr) (((long) ptr) + perf_object_type.TotalByteLength); } if (!flag) { throw new InvalidOperationException(SR.GetString("CantReadCategoryIndex", new object[] { nameIndex.ToString(CultureInfo.CurrentCulture) })); } this.CounterFrequency = perf_object_type.PerfFreq; this.CounterTimeStamp = perf_object_type.PerfTime; int numCounters = perf_object_type.NumCounters; int numInstances = perf_object_type.NumInstances; if (numInstances == -1) { this.IsMultiInstance = false; } else { this.IsMultiInstance = true; } ptr = (IntPtr) (((long) ptr) + perf_object_type.HeaderLength); CounterDefinitionSample[] sampleArray = new CounterDefinitionSample[numCounters]; this.CounterTable = new Hashtable(numCounters); for (int j = 0; j < sampleArray.Length; j++) { Microsoft.Win32.NativeMethods.PERF_COUNTER_DEFINITION perf_counter_definition = new Microsoft.Win32.NativeMethods.PERF_COUNTER_DEFINITION(); Marshal.PtrToStructure(ptr, perf_counter_definition); sampleArray[j] = new CounterDefinitionSample(perf_counter_definition, this, numInstances); ptr = (IntPtr) (((long) ptr) + perf_counter_definition.ByteLength); int counterType = sampleArray[j].CounterType; if (!PerformanceCounterLib.IsBaseCounter(counterType)) { if (counterType != 0x40000200) { this.CounterTable[sampleArray[j].NameIndex] = sampleArray[j]; } } else if (j > 0) { sampleArray[j - 1].BaseCounterDefinitionSample = sampleArray[j]; } } if (!this.IsMultiInstance) { this.InstanceNameTable = new Hashtable(1, StringComparer.OrdinalIgnoreCase); this.InstanceNameTable["systemdiagnosticsperfcounterlibsingleinstance"] = 0; for (int k = 0; k < sampleArray.Length; k++) { sampleArray[k].SetInstanceValue(0, ptr); } } else { string[] instanceNamesFromIndex = null; this.InstanceNameTable = new Hashtable(numInstances, StringComparer.OrdinalIgnoreCase); for (int m = 0; m < numInstances; m++) { string str; Microsoft.Win32.NativeMethods.PERF_INSTANCE_DEFINITION perf_instance_definition = new Microsoft.Win32.NativeMethods.PERF_INSTANCE_DEFINITION(); Marshal.PtrToStructure(ptr, perf_instance_definition); if ((perf_instance_definition.ParentObjectTitleIndex > 0) && (instanceNamesFromIndex == null)) { instanceNamesFromIndex = this.GetInstanceNamesFromIndex(perf_instance_definition.ParentObjectTitleIndex); } if (((instanceNamesFromIndex != null) && (perf_instance_definition.ParentObjectInstance >= 0)) && (perf_instance_definition.ParentObjectInstance < (instanceNamesFromIndex.Length - 1))) { str = instanceNamesFromIndex[perf_instance_definition.ParentObjectInstance] + "/" + Marshal.PtrToStringUni((IntPtr) (((long) ptr) + perf_instance_definition.NameOffset)); } else { str = Marshal.PtrToStringUni((IntPtr) (((long) ptr) + perf_instance_definition.NameOffset)); } string key = str; int num10 = 1; while (true) { if (!this.InstanceNameTable.ContainsKey(key)) { this.InstanceNameTable[key] = m; break; } key = str + "#" + num10.ToString(CultureInfo.InvariantCulture); num10++; } ptr = (IntPtr) (((long) ptr) + perf_instance_definition.ByteLength); for (int n = 0; n < sampleArray.Length; n++) { sampleArray[n].SetInstanceValue(m, ptr); } ptr = (IntPtr) (((long) ptr) + Marshal.ReadInt32(ptr)); } } } }
internal unsafe CategorySample(byte[] data, System.Diagnostics.CategoryEntry entry, PerformanceCounterLib library) { this.entry = entry; this.library = library; int nameIndex = entry.NameIndex; Microsoft.Win32.NativeMethods.PERF_DATA_BLOCK structure = new Microsoft.Win32.NativeMethods.PERF_DATA_BLOCK(); fixed(byte *numRef = data) { IntPtr ptr = new IntPtr((void *)numRef); Marshal.PtrToStructure(ptr, structure); this.SystemFrequency = structure.PerfFreq; this.TimeStamp = structure.PerfTime; this.TimeStamp100nSec = structure.PerfTime100nSec; ptr = (IntPtr)(((long)ptr) + structure.HeaderLength); int numObjectTypes = structure.NumObjectTypes; if (numObjectTypes == 0) { this.CounterTable = new Hashtable(); this.InstanceNameTable = new Hashtable(StringComparer.OrdinalIgnoreCase); return; } Microsoft.Win32.NativeMethods.PERF_OBJECT_TYPE perf_object_type = null; bool flag = false; for (int i = 0; i < numObjectTypes; i++) { perf_object_type = new Microsoft.Win32.NativeMethods.PERF_OBJECT_TYPE(); Marshal.PtrToStructure(ptr, perf_object_type); if (perf_object_type.ObjectNameTitleIndex == nameIndex) { flag = true; break; } ptr = (IntPtr)(((long)ptr) + perf_object_type.TotalByteLength); } if (!flag) { throw new InvalidOperationException(SR.GetString("CantReadCategoryIndex", new object[] { nameIndex.ToString(CultureInfo.CurrentCulture) })); } this.CounterFrequency = perf_object_type.PerfFreq; this.CounterTimeStamp = perf_object_type.PerfTime; int numCounters = perf_object_type.NumCounters; int numInstances = perf_object_type.NumInstances; if (numInstances == -1) { this.IsMultiInstance = false; } else { this.IsMultiInstance = true; } ptr = (IntPtr)(((long)ptr) + perf_object_type.HeaderLength); CounterDefinitionSample[] sampleArray = new CounterDefinitionSample[numCounters]; this.CounterTable = new Hashtable(numCounters); for (int j = 0; j < sampleArray.Length; j++) { Microsoft.Win32.NativeMethods.PERF_COUNTER_DEFINITION perf_counter_definition = new Microsoft.Win32.NativeMethods.PERF_COUNTER_DEFINITION(); Marshal.PtrToStructure(ptr, perf_counter_definition); sampleArray[j] = new CounterDefinitionSample(perf_counter_definition, this, numInstances); ptr = (IntPtr)(((long)ptr) + perf_counter_definition.ByteLength); int counterType = sampleArray[j].CounterType; if (!PerformanceCounterLib.IsBaseCounter(counterType)) { if (counterType != 0x40000200) { this.CounterTable[sampleArray[j].NameIndex] = sampleArray[j]; } } else if (j > 0) { sampleArray[j - 1].BaseCounterDefinitionSample = sampleArray[j]; } } if (!this.IsMultiInstance) { this.InstanceNameTable = new Hashtable(1, StringComparer.OrdinalIgnoreCase); this.InstanceNameTable["systemdiagnosticsperfcounterlibsingleinstance"] = 0; for (int k = 0; k < sampleArray.Length; k++) { sampleArray[k].SetInstanceValue(0, ptr); } } else { string[] instanceNamesFromIndex = null; this.InstanceNameTable = new Hashtable(numInstances, StringComparer.OrdinalIgnoreCase); for (int m = 0; m < numInstances; m++) { string str; Microsoft.Win32.NativeMethods.PERF_INSTANCE_DEFINITION perf_instance_definition = new Microsoft.Win32.NativeMethods.PERF_INSTANCE_DEFINITION(); Marshal.PtrToStructure(ptr, perf_instance_definition); if ((perf_instance_definition.ParentObjectTitleIndex > 0) && (instanceNamesFromIndex == null)) { instanceNamesFromIndex = this.GetInstanceNamesFromIndex(perf_instance_definition.ParentObjectTitleIndex); } if (((instanceNamesFromIndex != null) && (perf_instance_definition.ParentObjectInstance >= 0)) && (perf_instance_definition.ParentObjectInstance < (instanceNamesFromIndex.Length - 1))) { str = instanceNamesFromIndex[perf_instance_definition.ParentObjectInstance] + "/" + Marshal.PtrToStringUni((IntPtr)(((long)ptr) + perf_instance_definition.NameOffset)); } else { str = Marshal.PtrToStringUni((IntPtr)(((long)ptr) + perf_instance_definition.NameOffset)); } string key = str; int num10 = 1; while (true) { if (!this.InstanceNameTable.ContainsKey(key)) { this.InstanceNameTable[key] = m; break; } key = str + "#" + num10.ToString(CultureInfo.InvariantCulture); num10++; } ptr = (IntPtr)(((long)ptr) + perf_instance_definition.ByteLength); for (int n = 0; n < sampleArray.Length; n++) { sampleArray[n].SetInstanceValue(m, ptr); } ptr = (IntPtr)(((long)ptr) + Marshal.ReadInt32(ptr)); } } } }