powercfg -energy如何检测请求的计时器分辨率 [英] How does powercfg -energy detect the requested timer resolution

查看:222
本文介绍了powercfg -energy如何检测请求的计时器分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"powercfg -energy"命令如何检测当时正在运行的每个程序的请求计时器分辨率?

How does "powercfg -energy" command detect the requested timer resolution of each individual program running at the time?

我想一种方法是将每个正在运行的进程注入到该进程中,并在这些分辨率内循环地为每个提高的分辨率(值1-15)调用 timeEndPeriod ,并检查 timeEndPeriod 调用当前解决方案会返回 TIMERR_NOCANDO ,并且 TIMERR_NOERROR (请注意:这些返回值并不相应地为 false true ).如果返回 TIMERR_NOERROR ,则表明程序正在使用该频率,然后再次调用 timeBeginPeriod .但是这种方法似乎很麻烦.而且,由于它修改了进程的状态,并且还假定powercfg能够注入到所有进程中,因此有点麻烦.

I imagine one way would be injecting into each of running processes and inside that process calling timeEndPeriod for each increased resolution (values 1-15) in a loop over these resolutions and checking whether the timeEndPeriod call for a current resolution returns TIMERR_NOCANDO or TIMERR_NOERROR (note: these return values are NOT correspondingly false and true). And if it returns TIMERR_NOERROR then concluding that the program is using that frequency, and then calling again timeBeginPeriod. But this method seems cumbersome. Moreover, it is a bit intrusive since it modifies the state of the process, and also assumes that powercfg is able to inject into all processes.

是否存在一些已记录或未记录的系统API,这些API可以为外部流程请求该信息?至少我想知道它是如何工作的,即使该API仍然是秘密...

Is there instead some documented or undocumented system API that enables requesting that information for foreign processes? At least I would like to know how it works, even if that API remains a secret...

一个相关的(但不是主要的)问题是,如果我对单个应用程序的请求不感兴趣,如何获得系统中当前有效的最大计时器分辨率(最小间隔)?我想也许 GetSystemTimeAdjustment()的lpTimeIncrement 可以帮助实现这一点,但我不太确定.请确认我或提出其他方法.

A related (but not the main) question is, how to get the maximum timer resolution (minimum interval) that is currently in effect in the system in case I am not interested in the requests of individual applications? I imagine that maybe GetSystemTimeAdjustment()'s lpTimeIncrement helps with that, but I am not too sure. Please confirm me or propose an alternate method.

推荐答案

您可以使用NtQueryTimerResolution()的未记录API.

You may use the undocumented API of NtQueryTimerResolution().

NTSTATUS NtQueryTimerResolution(OUT PULONGMinimumResolution, 
                                OUT LONGMaximumResolution, 
                                OUT PULONGActualResolution);

有关如何使用它的示例,请参见这篇文章.但是它只会提供任何进程配置的 ActualResolution .它不提供有关哪个进程配置了哪个多媒体计时器分辨率的信息.

See this post for an example on how to use it. But it will only give the ActualResolution as configured by any process. It does not give the information which process has configured which multimedia timer resolution.

您不想更改每个进程的mutimedia设置,以找出哪个进程需要哪个分辨率.仅需要获取有关哪个进程已请求 ActualResolution 的信息.

You wouldn't want to change each processes mutimedia setting to find out which process has aquired which resolution. It would only be needed to obtain information on which process has requested ActualResolution.

注意:powercfg/energy仅在Windows 7/Windows Server 2008 R2及更高版本中可用.

Note: powercfg /energy is only available from Windows 7 / Windows Server 2008 R2 upwards.

这篇关于powercfg -energy如何检测请求的计时器分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆