有没有办法从Windows上的脚本中获取特定服务的CPU利用率?我知道wmic cpu get LoadPercentage
会给出整个系统的CPU使用率,但是有没有可能得到像winword.exe这样的特定程序的CPU使用率呢?
发布于 2013-01-09 02:30:56
此wmic命令打印所有进程的CPU使用率。然后,您可以(使用标志/c:<process name>
)通过管道将其传递给findstr
以过滤特定的进程。
wmic path Win32_PerfFormattedData_PerfProc_Process get Name,PercentProcessorTime
从命令行执行help findstr
和help find
命令,查看可以过滤列表的更多方法。
例如:
C:\> wmic path Win32_PerfFormattedData_PerfProc_Process get Name,PercentProcessorTime | findstr /i /c:chrome
chrome 24
chrome#1 0
chrome#2 0
chrome#3 0
发布于 2013-01-08 21:44:23
要做到这一点,最简单的是使用MS性能工具包,它可以租用ETW来跟踪包括CPU使用率在内的许多指标。安装后性能工具包(现在在Windows SDK中)。
执行以下命令:
1. set _NT_SYMBOL_PATH= srv*C:\symbols*http://msdl.microsoft.com/downloads/symbols
2. open trace via: xperf -on base
3. Excute any program for some times.
4. output the result: xperf –d myprofile.etl
5. launch the graphics UI to analysis : xperfview myprofile.etl
与WMI不同,Xperf是一个更复杂的工具包,可以提供有关CPU使用情况的更多详细信息,不仅包括进程,还包括函数调用消耗、CPU状态更改等。(这就是我们在第一步导入Windows元件的原因)。
另一个好处是Xperf采用了ETW,而且ETW对CPU的影响很小。
https://stackoverflow.com/questions/14215756
复制相似问题