22

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?

indiv
  • 17,306
  • 6
  • 61
  • 82
Bharath
  • 665
  • 5
  • 12
  • 20
  • Related: [Get CPU Usage from Windows Command Prompt](http://stackoverflow.com/questions/9097067/get-cpu-usage-from-windows-command-prompt) – Alex K. Jan 09 '15 at 11:23

4 Answers4

33

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

Kimberly
  • 431
  • 4
  • 3
  • 3
    What happen if a new process is launched during your 5 minutes period? Will its activity be logged? – Alessandro Jacopson May 02 '11 at 07:35
  • 2
    On my system the command typeperf -qx "\Process" > config.txt does not work well because it adds to config.txt also the string "Exiting please wait... The command completed successfully." in the middle of the counters. It works well if I replace the redirection with the -o typeperf option. – Alessandro Jacopson May 02 '11 at 13:43
  • with "typeperf -q" you can get all list of QUERY parameters. – Boris Ivanov Oct 20 '14 at 15:24
15

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"
warren
  • 32,620
  • 21
  • 85
  • 124
mcstellar
  • 393
  • 1
  • 7
5

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

AffineMesh
  • 1,025
  • 8
  • 14
  • 2
    `pslist` only shows CPU time and elapsed time, which requires extra calculation to get a utilization number, and is not a "real time" number but process lifetime number. For a quick "who's using my CPU" this isn't so useful, though it could be good for other uses. – Nathan Kidd Nov 07 '14 at 15:35
5

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 
ghostdog74
  • 327,991
  • 56
  • 259
  • 343