系统性能计数器的实例名称是否已本地化?
Windows 中的性能计数器名称是本地化的,因此例如计数器 \Processor(_Total)\% Processor Time
在其他语言版本的 Windows 中被称为其他名称。这意味着为了找到正确的名称,必须首先找到计数器的索引,然后使用 PdhLookupPerfNameByIndex 函数获取本地化名称(使用 PdhAddEnglishCounter 如果应支持 Windows XP 则已退出)。
这对于上面计数器路径的性能对象 (Processor
) 和计数器 (% Processor Time
) 部分来说都是有好处的,但是实例名称 (_Total) 又如何呢? )?我在注册表中找不到该字符串,因此我认为它是由提供该信息的任何系统组件提供的。
系统提供的性能计数器的实例名称在不同语言版本的 Windows 中是否保证相同?
如果不是,我如何确定哪个实例对应于 _Total
实例?
Performance counter names in Windows are localized, so for instance the counter \Processor(_Total)\% Processor Time
is called something else in other language versions of Windows. This means that in order to find the correct name one must first find the index of the counter and then use the PdhLookupPerfNameByIndex function to get the localized name (using PdhAddEnglishCounter is out if Windows XP should be supported).
This is all good for the performance object (Processor
) and counter (% Processor Time
) parts of the counter path above, but what about the instance name (_Total
)? I cannot find this string in the registry, so I suppose that it is provided by whatever system component that provides the information.
Is the instance name for system provided performance counters guaranteed to be the same across different language versions of Windows?
If not, how can I determine which instance corresponds to the _Total
instance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此支持知识库,只有对象和计数器具有友好名称:
因此,这使我相信给定计数器的实例名称是动态获取的(例如进程的 ProcessId)或静态获取的(例如硬编码的)。当然,没有什么可以阻止某人在英语版本中硬编码“_Total”,在德语版本中硬编码其他内容,尽管似乎常见的做法是将语言内容限制在注册表中,并通过以下方式处理对象和计数器按动态或静态名称索引和实例。我认为微软一直使用“_Total”,正如我在一些外语安装中看到的那样。
According to this support KB, only the objects and counters have friendly names:
So this leads me to believe that instance names for a given counter are obtained either dynamically (e.g. ProcessId for a process) or statically (e.g. hard-coded). Of course there is nothing stopping somebody from hard-coding "_Total" in an English build and something else in a German build, though it seems the common practice is to keep the language stuff confined to the registry and deal with the objects and counters by index and the instances by dynamic or static names. I think Microsoft consistently uses "_Total" as I've seen it on a few foreign language installs.
卢克是对的。为了获取 Processor(_Total)\% Processor Time 的本地化版本,我们必须获取路径“Processor”和“%Processor Time”的每个组件的本地化名称,其中“(_Total)”为常量。索引可能因操作系统版本而异,因此您必须在每次运行时发现它们。 win32pyutil 模块包含加载英语到索引映射但保留它的方法,并且由于它并不小,如果您只需要它一次,那么这可能会浪费内存。我们使用以下内容:
构建计数器名称:
产生所需的值。例如,意大利语中的“\Processore(_Total)\% Tempo Processore”。
Luke is correct. In order to get the localized version of Processor(_Total)\% Processor Time, we have to get the localized names of each of the components of the path "Processor" and "%Processor Time" with the '(_Total)' being constant. The indexes can vary across OS versions, so you have to discover them on each run. The win32pyutil module contains methods that will load the english-to-index map but retains it, and since it's not small if you only need it once then that can be a memory waster. We use the following:
To construct the counter name:
which yields the desired value. e.g., "\Processore(_Total)\% Tempo Processore" in Italian.