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 unsafe void InitializeNextInstance(IntPtr handle) { InstanceEntry instanceEntry = this; while (instanceEntry.internalInstanceEntry->NextInstanceOffset != 0) { InstanceEntry instanceEntry2 = new InstanceEntry(InstanceEntry.GetInternalInstanceEntry(handle, instanceEntry.internalInstanceEntry->NextInstanceOffset), handle); instanceEntry2.offset = instanceEntry.internalInstanceEntry->NextInstanceOffset; instanceEntry.nextInstanceEntry = instanceEntry2; instanceEntry = instanceEntry2; } }
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); } } } } }
public InstanceEntry(IntPtr handle, int offset) : this(InstanceEntry.GetInternalInstanceEntry(handle, offset), handle) { this.offset = offset; this.InitializeNextInstance(handle); }