相关疑难解决方法(0)

C#:访问".NET CLR内存类别"的PerformanceCounters

我正在尝试使用PerformanceCounter类通过C#访问位于".NET CLR内存类别"中的性能计数器.但是,无法使用我期望的正确类别/计数器名称来实例化类别

new PerformanceCounter(".NET CLR Memory", "# bytes in all heaps", Process.GetCurrentProcess().ProcessName);
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下代码循环遍历类别和计数器

string[] categories = PerformanceCounterCategory.GetCategories().Select(c => c.CategoryName).OrderBy(s => s).ToArray();
string toInspect = string.Join(",\r\n", 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();
Run Code Online (Sandbox Code Playgroud)

但找不到任何似乎匹配的东西.是不可能从CLR中观察这些值,或者我做错了什么.

重要的是,环境是在64位Windows 7机器上运行的.NET 4.0.

.net c# memory performancecounter

9
推荐指数
1
解决办法
5679
查看次数

标签 统计

.net ×1

c# ×1

memory ×1

performancecounter ×1