C# 原始值还是下一个值

C# 原始值还是下一个值,c#,asp.net,performancecounter,instrumentation,C#,Asp.net,Performancecounter,Instrumentation,我有一个非常简单的问题,我想我以前已经回答过了,但我就是找不到任何准确和简单的参考资料来说明我在寻找什么 我有一个控制台实用程序应用程序,它根据输入参数获取每个web应用程序或每个windows服务的性能计数器列表 我的简单问题是:应该使用NextValue读取哪些计数器,使用RawValue读取哪些计数器 因为我的实用程序需要快速运行(不到2秒),所以我希望高效地读取每个计数器。例如,我知道进程/%处理器时间必须通过NextValue读取,而进程/工作集可以通过RawValue读取 我试图让我

我有一个非常简单的问题,我想我以前已经回答过了,但我就是找不到任何准确和简单的参考资料来说明我在寻找什么

我有一个控制台实用程序应用程序,它根据输入参数获取每个web应用程序或每个windows服务的性能计数器列表

我的简单问题是:应该使用NextValue读取哪些计数器,使用RawValue读取哪些计数器

因为我的实用程序需要快速运行(不到2秒),所以我希望高效地读取每个计数器。例如,我知道进程/%处理器时间必须通过NextValue读取,而进程/工作集可以通过RawValue读取

我试图让我的应用程序根据PerfCounterType(NumberItems32、CounterXXX等)来决定,这是可行的,但我只需要关于如何读取每个类型的确切的简单直接信息

我早期的结论似乎是,为了提高准确性,所有的数据都必须通过下一个值读取,但根据经验,有些数据可以通过下一个值读取,因此最好是通过第二个值读取数据,并避免需要的1秒睡眠

这是计数器的潜在列表,我获得了类型:

# Bytes in all Heaps = NumberOfItems32
# Gen 0 Collections = NumberOfItems32
# Gen 1 Collections = NumberOfItems32
# Gen 2 Collections = NumberOfItems32
# Induced GC = NumberOfItems32
# of current logical Threads = NumberOfItems32
# of current physical Threads = NumberOfItems32
# of Exceps Thrown / sec = RateOfCountsPerSecond32
# of Exceps Thrown = NumberOfItems32
# of marshalling = NumberOfItems32
# of Sink Blocks in use = NumberOfItems32
% Processor Time = Timer100Ns
% Time in GC = RawFraction
Bytes Received = NumberOfItems64
Bytes Sent = NumberOfItems64
Cache % Process Memory Limit Used = RawFraction
Cache % Process Memory Limit Used = RawFraction
Cache Total Entries = NumberOfItems32
Cache Total Entries = NumberOfItems32
Cache Total Entries = NumberOfItems32
Channels = NumberOfItems32
Connections Established = NumberOfItems32
Context Proxies = NumberOfItems32
Current Queue Length = NumberOfItems32
Errors Unhandled During Execution = NumberOfItems32
Errors Unhandled During Execution = NumberOfItems32
Errors Unhandled During Execution = NumberOfItems32
Finalization Survivors = NumberOfItems32
Forms Authentication Failure = NumberOfItems32
Forms Authentication Failure = NumberOfItems32
Forms Authentication Success = NumberOfItems32
Forms Authentication Success = NumberOfItems32
Gen 0 heap size = NumberOfItems32
Gen 1 heap size = NumberOfItems32
Gen 2 heap size = NumberOfItems32
Handle Count = NumberOfItems32
Large Object Heap size = NumberOfItems32
Remote Calls/sec = RateOfCountsPerSecond32
Request Wait Time = NumberOfItems32
Request Wait Time = NumberOfItems32
Requests Executing = NumberOfItems32
Requests Executing = NumberOfItems32
Requests Executing = NumberOfItems32
Requests In Application Queue = NumberOfItems32
Requests In Application Queue = NumberOfItems32
Requests In Application Queue = NumberOfItems32
Requests Succeeded = NumberOfItems32
Requests Succeeded = NumberOfItems32
Requests Succeeded = NumberOfItems32
Requests Timed Out = NumberOfItems32
Requests Timed Out = NumberOfItems32
Requests Timed Out = NumberOfItems32
Requests/Sec = RateOfCountsPerSecond32
Requests/Sec = RateOfCountsPerSecond32
Requests/Sec = RateOfCountsPerSecond32
Sessions Active = NumberOfItems32
Sessions Active = NumberOfItems32
Sessions Active = NumberOfItems32
Thread Count = NumberOfItems32
Total Remote Calls = NumberOfItems32
Working Set - Private = NumberOfItems64

我最初的想法是,无论您编写什么.NET代码来处理原始值,都会比Microsoft编写的代码慢,而Microsoft编写的代码将经过高度优化以获得最佳性能。显示了处理器时间计数器数据的原始计数器收集之间的2秒等待,因此无论是原始还是烘焙,等待似乎仍然是必要的。对,如果必须花费1秒,我不能反对,但至少要尽可能做到性能最好——我要说的是,您为处理原始值而编写的任何.NET代码在性能方面都不会比处理原始值的Windows代码更好。此外,如果您为它设置了一种机制来决定要获取哪种类型的计数器,那么开销会更大。然后,如果我有计数器与读取模式之间的映射,至少我可以对其进行硬编码以减少开销。