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

C# 如何查看/调试System.Diagnostics计数器?,c#,C#,有没有办法查看应用程序已注册的所有性能计数器 是的,您可以从PerformanceCounterCategory类中检查该方法。您将为每个计数器获取一个和一些有关的信息 PerformanceCounterCategory pcc = new PerformanceCounterCategory(); // Retrieves the list of performance object instances that are associated with this category. for

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

是的,您可以从
PerformanceCounterCategory
类中检查该方法。您将为每个计数器获取一个和一些有关的信息

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