简体   繁体   English

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

[英]How to see/debug System.Diagnostics Counter?

有什么方法可以查看应用程序已注册了所有Performance Counter吗?

Yes, you can check the GetCounter() method from the PerformanceCounterCategory class. 是的,您可以从PerformanceCounterCategory类中检查GetCounter()方法。 You will take a PerformanceCounter[] and some information about for each counter. 您将获得PerformanceCounter[]以及有关每个计数器的一些信息。

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());
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用System.Diagnostics进行简单的调试和日志记录 - Simple Debug and Logging using System.Diagnostics Silverlight的System.Diagnostics中是否没有Debug.Write()方法? - Is there no Debug.Write() method in Silverlight's System.Diagnostics? 如何使用system.diagnostics将日志添加到Windows事件日志 - How to add logging to Windows Event Log using system.diagnostics 您如何使用 System.Diagnostics 以编程方式设置源开关 - How do you programatically set the source switch with System.Diagnostics 如何使用System.Diagnostics打开(.tif)文件 - How to open (.tif) file using System.Diagnostics 如何让 System.Diagnostics 在 Ubuntu Linux 上的 Blazor 应用程序中工作? - How to get System.Diagnostics to work in a Blazor application on Ubuntu Linux? 如何在xml中为System.Diagnostics侦听器或过滤器指定文件夹? - How to specify a folder for a System.Diagnostics listener or filter in the xml? 使用WMI或System.Diagnostics类的一些非常奇怪的性能计数器 - few very odd Performance counter using WMI or System.Diagnostics class StopWatch(System.Diagnostics)和System.Timers - StopWatch (System.Diagnostics) and System.Timers System.Diagnostics跟踪通配符以获取源名称 - System.Diagnostics Traces wildcard for source name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM