Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new PerformanceCounter(".NET CLR Memory", "# bytes in all heaps", Process.GetCurrentProcess().ProcessName);
- string[] categories = PerformanceCounterCategory.GetCategories().Select(c => c.CategoryName).OrderBy(s => s).ToArray();
- string toInspect = string.Join(",rn", categories);
- System.Text.StringBuilder interestingToInspect = new System.Text.StringBuilder();
- string[] interestingCategories = categories.Where(s => s.StartsWith(".NET") || s.Contains("Memory")).ToArray();
- foreach (string interestingCategory in interestingCategories)
- {
- PerformanceCounterCategory cat = new PerformanceCounterCategory(interestingCategory);
- foreach (PerformanceCounter counter in cat.GetCounters())
- {
- interestingToInspect.AppendLine(interestingCategory + ":" + counter.CounterName);
- }
- }
- toInspect = interestingToInspect.ToString();
- foreach (var instance in cat.GetInstanceNames())
- {
- foreach (PerformanceCounter counter in cat.GetCounters(instance))
- {
- interestingToInspect.AppendLine(interestingCategory + ":" + counter.CounterName);
- }
- }
- new PerformanceCounter(".NET CLR Memory", "# bytes in all heaps", Process.GetCurrentProcess().ProcessName, true);
- public static string GetInstanceNameForProcessId(int pid)
- {
- var cat = new PerformanceCounterCategory(".NET CLR Memory");
- foreach (var instanceName in cat.GetInstanceNames())
- {
- using (var pcPid = new PerformanceCounter(cat.CategoryName, "Process ID", instanceName))
- {
- if ((int)pcPid.NextValue() == pid)
- {
- return instanceName;
- }
- }
- }
- throw new ArgumentException(
- string.Format("No performance counter instance found for process id '{0}'", pid),
- "pid");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement