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()); }
public static PerformanceCounterMemoryMappedFile GetPerformanceCounterSharedMemory(string categoryName) { PerformanceCounterMemoryMappedFile performanceCounterMemoryMappedFile = null; if (!PerformanceCounterMemoryMappedFile.perfCounterSharedMemories.TryGetValue(categoryName, out performanceCounterMemoryMappedFile)) { performanceCounterMemoryMappedFile = new PerformanceCounterMemoryMappedFile(categoryName); PerformanceCounterMemoryMappedFile.perfCounterSharedMemories.Add(categoryName, performanceCounterMemoryMappedFile); } return(performanceCounterMemoryMappedFile); }
public static PerformanceCounterMemoryMappedFile GetDefaultPerformanceCounterSharedMemory() { PerformanceCounterMemoryMappedFile performanceCounterMemoryMappedFile = null; if (!PerformanceCounterMemoryMappedFile.perfCounterSharedMemories.TryGetValue("netfxcustomperfcounters.1.0", out performanceCounterMemoryMappedFile)) { performanceCounterMemoryMappedFile = new PerformanceCounterMemoryMappedFile(); PerformanceCounterMemoryMappedFile.perfCounterSharedMemories.Add("netfxcustomperfcounters.1.0", performanceCounterMemoryMappedFile); } return(performanceCounterMemoryMappedFile); }