Processor and User Time

On my Windows 7 64-bit system, I can use resource monitor to see the CPU usage for each of the eight cores on my system;
1544709801151.png

However, I would like to see this info via the command line.

Here is a .BTM that allows me to do that;
Code:
@setlocal
@echo off
COMMENT
  Tested on;

  TCC  24.00.24 x64   Windows 7 [Version 6.1.7601]
  TCC Build 24   Windows 7 Build 7601  Service Pack 1

  The first time this .BTM is run, it would seem to be hung, but subsequent runs are immediate.
ENDCOMMENT

:: A couple of functions to get what I want;
::
function ProcessorTime=`%@wmi[root\CIMV2,"select PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor where name = '%1'"]`
function UserTime=`%@wmi[root\CIMV2,"select PercentUserTime from Win32_PerfFormattedData_PerfOS_Processor where name = '%1'"]`
::
:: TCC can tell me how may processors I have;
::
set Processors=%@wininfo[3]
:: Zero-base the Processors
::
set Processors=%@dec[%Processors]
::
:: Show the ProcessorTime and UserTime as a percentage for each Processor
::
echo Processor # ProcessorTime UserTime
do Processor=0 to %Processors
  echo %@format[11,%Processor] %@format[13,%@ProcessorTime[%Processor]] %@format[8,%@UserTime[%Processor]]
enddo
endlocal
Sample run;
Code:
Processor # ProcessorTime UserTime
          0            87       93
          1            37       24
          2            62       62
          3           100       99
          4            87       81
          5            56       74
          6            87       62
          7            69       80
Joe
 
Last edited:
May 20, 2008
9,856
69
Syracuse, NY, USA
You went out of your way to set %Processors but then you re-used "Processors" as the DO variable and hard-coded the 7. Didn't you, later, mean to say
Code:
do Processor=0 to %Processors
  echo %@format[11,%Processor] %@format[13,%@ProcessorTime[%Processor]] %@format[8,%@UserTime[%Processor]]
enddo
 
Apr 2, 2011
1,248
2
52
North Carolina, USA
Code:
[C:\TCMD]CPUsage.btm
Processor # ProcessorTime UserTime
          0             0       18
          1             0        0
          2             0        0
          3             0        0

[C:\TCMD]
Does not look right - does it?