问题描述
在Windows中,性能计数器具有不同的名称,具体取决于操作系统的语言.例如,在英语Windows版本上,存在性能计数器\Processor(_Total)\% Processor Time
.在德语Windows版本中,同一计数器称为\Prozessor(_Total)\Prozessorzeit (%)
.
Under Windows, performance counters have different names, depending on the operating system language. For example, on an English Windows version, there is the performance counter \Processor(_Total)\% Processor Time
. The same counter is called \Prozessor(_Total)\Prozessorzeit (%)
on a German Windows version.
是否有任何方法可以以与语言无关的方式(使用C ++或C#)来检索性能计数器值?还是有一种替代方法可以在没有性能计数器的情况下获得整个计算机的处理器负载?
Is there any way to retrieve the performance counter value in a language-independent way (using C++ or C#)? Or is there an alternative to get the processor load of the whole computer without performance counters?
推荐答案
每个PerfMon计数器都有一个唯一的(每台机器)整数ID来标识PerfMon计数器(但是,对于标准计数器,此ID可以保证保留)一样).
Each PerfMon counter is given a unique (per machine) integer ID to identify the PerfMon counter (however in the case of the standard counters this id is guaranteed to stay the same).
将PerfMon计数器ID链接到其美国英语名称和其本地化名称的信息存储在注册表中的以下注册表项中:
The information linking PerfMon counters id's to both their US English name and their Localized name is stored in the registry in the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib
使用注册表获取PerfMon计数器名称(您可以将其作为标准计数器的常量嵌入到应用程序中)后,可以使用 PdhLookupPerfNameByIndex 函数可查找给定计数器ID的本地化名称.
Once you have used the registry to obtain the PerfMon counter name (which you can embed in your app as a constant for standard counters) you can use the PdhLookupPerfNameByIndex function to look up the localized name for the given counter ID.
有关更多详细信息,请参见以本地化语言(Microsoft KB)正确使用PDH API .
See Using PDH APIs correctly in a localized language (Microsoft KB) for more details.
您可能还会找到通过winreg(StackOverflow)查找perfmon计数器ID 有点相关.
You might also find Finding perfmon counter id via winreg (StackOverflow) somewhat relevant.
这篇关于以与语言无关的方式检索性能计数器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!