Advertisement
Guest User

Untitled

a guest
Aug 9th, 2013
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. new PerformanceCounter(".NET CLR Memory", "# bytes in all heaps", Process.GetCurrentProcess().ProcessName);
  2.  
  3. string[] categories = PerformanceCounterCategory.GetCategories().Select(c => c.CategoryName).OrderBy(s => s).ToArray();
  4. string toInspect = string.Join(",rn", categories);
  5.  
  6. System.Text.StringBuilder interestingToInspect = new System.Text.StringBuilder();
  7. string[] interestingCategories = categories.Where(s => s.StartsWith(".NET") || s.Contains("Memory")).ToArray();
  8. foreach (string interestingCategory in interestingCategories)
  9. {
  10. PerformanceCounterCategory cat = new PerformanceCounterCategory(interestingCategory);
  11. foreach (PerformanceCounter counter in cat.GetCounters())
  12. {
  13. interestingToInspect.AppendLine(interestingCategory + ":" + counter.CounterName);
  14. }
  15. }
  16. toInspect = interestingToInspect.ToString();
  17.  
  18. foreach (var instance in cat.GetInstanceNames())
  19. {
  20. foreach (PerformanceCounter counter in cat.GetCounters(instance))
  21. {
  22. interestingToInspect.AppendLine(interestingCategory + ":" + counter.CounterName);
  23. }
  24. }
  25.  
  26. new PerformanceCounter(".NET CLR Memory", "# bytes in all heaps", Process.GetCurrentProcess().ProcessName, true);
  27.  
  28. public static string GetInstanceNameForProcessId(int pid)
  29. {
  30. var cat = new PerformanceCounterCategory(".NET CLR Memory");
  31. foreach (var instanceName in cat.GetInstanceNames())
  32. {
  33. using (var pcPid = new PerformanceCounter(cat.CategoryName, "Process ID", instanceName))
  34. {
  35. if ((int)pcPid.NextValue() == pid)
  36. {
  37. return instanceName;
  38. }
  39. }
  40. }
  41.  
  42. throw new ArgumentException(
  43. string.Format("No performance counter instance found for process id '{0}'", pid),
  44. "pid");
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement