首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何查看/调试System.Diagnostics计数器?

如何查看/调试System.Diagnostics计数器?
EN

Stack Overflow用户
提问于 2013-01-21 22:22:44
回答 1查看 99关注 0票数 0

有没有办法查看应用程序已经注册的所有性能计数器?

EN

回答 1

Stack Overflow用户

发布于 2013-01-21 22:33:59

是的,您可以从PerformanceCounterCategory类中检查GetCounter()方法。您将获取一个PerformanceCounter[]和关于每个计数器的一些信息。

代码语言:javascript
复制
PerformanceCounterCategory pcc = new PerformanceCounterCategory();

// Retrieves the list of performance object instances that are associated with this category.
foreach (string instanceName in pcc.GetInstanceNames()) 
    // Retrieves a list of the counters in a performance counter category that contains exactly one instance.
    foreach (PerformanceCounter counter in pcc.GetCounters())
    {
        // now you have the counter object that represents a PerformanceCounter to get some information about the performance counter

        Console.WriteLine("Category: " + counter.Category);
        Console.WriteLine("Instance Name: " + counter.InstanceName);    
        Console.WriteLine("Machine Name: " + counter.MachineName);

        Console.WriteLine("Counter Name: " + counter.CounterName);

        Console.WriteLine("Next Value: " + counter.NextValue());
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14440660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档