public static CounterEntry GetCounterEntry(IntPtr handle, int offset) { CounterEntry counterEntry = CounterEntry.InternalGetCounterEntry(handle, offset); counterEntry.InitializeNextCounter(handle); return(counterEntry); }
private unsafe void Initialize(IntPtr handle) { if (this.internalInstanceEntry->FirstCounterOffset != 0) { this.counterEntry = CounterEntry.GetCounterEntry(handle, this.internalInstanceEntry->FirstCounterOffset); } this.name = new string((long)handle / 2L + this.internalInstanceEntry->InstanceNameOffset); }
private string GetAllInstancesLayout(string categoryName) { StringBuilder stringBuilder = new StringBuilder(); try { using (PerformanceCounterMemoryMappedFile performanceCounterMemoryMappedFile = new PerformanceCounterMemoryMappedFile(categoryName, true)) { CategoryEntry categoryEntry = performanceCounterMemoryMappedFile.FindCategory(categoryName); if (categoryEntry != null) { for (InstanceEntry instanceEntry = categoryEntry.FirstInstance; instanceEntry != null; instanceEntry = instanceEntry.Next) { CounterEntry firstCounter = instanceEntry.FirstCounter; if (firstCounter != null) { LifetimeEntry lifetime = firstCounter.Lifetime; if (lifetime != null && lifetime.Type == 1) { stringBuilder.AppendLine(string.Format("A process is holding onto a transport performance counter. processId : {0}, counter : {1}, currentInstance : {2}, categoryName: {3} ", new object[] { lifetime.ProcessId, firstCounter, instanceEntry, categoryName })); } } } } } } catch (Win32Exception ex) { stringBuilder.AppendLine(string.Concat(new object[] { "Win32Exception for category ", categoryName, " : ", ex })); } catch (FileMappingNotFoundException ex2) { stringBuilder.AppendLine(string.Concat(new object[] { "FileMappingNotFoundException for category ", categoryName, " : ", ex2 })); } catch (Exception arg) { stringBuilder.AppendLine("Exception : " + arg); } return(stringBuilder.ToString()); }
private void InitializeNextCounter(IntPtr handle) { CounterEntry counterEntry = this; while (counterEntry.NextCounterOffset != 0) { CounterEntry counterEntry2 = CounterEntry.InternalGetCounterEntry(handle, counterEntry.NextCounterOffset); counterEntry.nextCounterEntry = counterEntry2; counterEntry = counterEntry2; } }
public void RemoveCategory(string categoryName, Action <CounterEntry, LifetimeEntry, InstanceEntry> logRemoveInstanceEvent) { CategoryEntry categoryEntry = this.FindCategory(categoryName); if (categoryEntry != null) { for (InstanceEntry instanceEntry = categoryEntry.FirstInstance; instanceEntry != null; instanceEntry = instanceEntry.Next) { CounterEntry firstCounter = instanceEntry.FirstCounter; if (firstCounter != null) { LifetimeEntry lifetime = firstCounter.Lifetime; if (lifetime != null && lifetime.Type == 1) { instanceEntry.RefCount = 0; logRemoveInstanceEvent(firstCounter, lifetime, instanceEntry); } } } } }