Windows command for CPU utilization % for particular service [closed]

与世无争的帅哥 提交于 2019-12-07 00:19:39

问题


Is there any way to get CPU utilization for particular service from a script on Windows? I know wmic cpu get LoadPercentage will give CPU utilization for the entire system, but is it possible to get it for a particular program like winword.exe?


回答1:


Yes, it's possible.

This wmic command prints the CPU usage for all processes. Then you can pipe it to findstr to filter for a particular process (using the flag /c:<process name>).

wmic path Win32_PerfFormattedData_PerfProc_Process get Name,PercentProcessorTime

Do help findstr and help find from the command line to see more ways you can filter the list.

For example:

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



回答2:


to do this, the most simple is using MS performance toolkit, it can hire the ETW to track the a lot of metrics include CPU usage. after install performance toolkit (now is in Windows SDK).

execute the following commands:

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

unlike WMI, Xperf is a more complex toolkit and can provide more detail in the CPU usage, not only the process, but also the function call consume, CPU state change, and so on. (that is why we import Windows symbols at the first step).

another good point is Xperf hiring ETW, and ETW is little impact to CPU.



来源:https://stackoverflow.com/questions/14215756/windows-command-for-cpu-utilization-for-particular-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!