Welcome!

By registering with us, you'll be able to discuss, share and exchange private messages with other members of our community.

SignUp Now!

Processor and User Time

Aug
1,837
64
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:
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
 
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

Corrected in OP.

Thankyou Vince.

Joe
 
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?
 
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?

When I am not running the BOINC Manager on my system, I get similar results;
Code:
Processor # ProcessorTime UserTime
          0             0        0
          1            23        0
          2             0        0
          3             0        0
          4             0        0
          5            11        0
          6            17        0
          7             0        5

Joe
 
Back
Top