开发者

Is it possible to know the cpu utilization from a script [closed]

开发者 https://www.devze.com 2022-12-22 06:07 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answe开发者_运维问答red.

Closed 7 years ago.

Improve this question

Is there any command or possible way to know the cpu utilization in windows operating system for use on the command line or in a batch script?


To determine the usage in general, you can use mcstellar and warren's answer. You also have the option of:

List all processes:

typeperf "\Process(*)\% Processor Time" -sc 1

List all processes, take 5 samples at 10 second intervals:

typeperf "\Process(*)\% Processor Time" -si 10 -sc 5

If you want a specific process, Rtvscan for example:

typeperf "\Process(Rtvscan)\% Processor Time" -si 10 -sc 5

I found it extremely useful to just monitor all process activity over a period of time. I could then dump it to a csv file and filter in a spreadsheet to remotely diagnose issues.

The following gives me 5 minutes (at 10 second intervals) of all processes. The data includes not just % Processor Time, but IO, memory, paging, etc.

typeperf -qx "\Process" > config.txt typeperf -cf config.txt -o perf.csv -f CSV -y -si 10 -sc 60


To monitor at 1 second intervals use:

typeperf "\processor(_total)\% processor time"

For only the current usage, use:

typeperf -sc 1 "\processor(_total)\% processor time"


here's a little vbscript that shows cpu utilization for each process

strComputer ="."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process",,48)
For Each obj in colProcess
If obj.Name <> "Idle"  And obj.Name <> "_Total" Then 
        WScript.echo obj.Name & "," & obj.PercentProcessorTime
End If
Next

save as showcpu.vbs and run it on the command line as

c:\test> cscript //nologo showcpu.vbs 


From the command line? Have a look at PsList in the PsTools suite.

0

精彩评论

暂无评论...
验证码 换一张
取 消