Sign in to follow this  
Followers 0
esfalk

Monitoring Cpu Usage?

12 posts in this topic

Scripters -

I am familiar with the MemGetStats function; is there something similiar that returns CPU load, or percent usage (similiar to the Windows Task Manager). I am hoping to pause my script while a program loads large, 3D models before continuing. I don't think that MemGetStats is going to work because after loading the models, they remain in the memory for accessing easily.

Thanks,

Eric

Share this post


Link to post
Share on other sites



You could always read the status bar of the Task Manager with StatusBarGetText...

Share this post


Link to post
Share on other sites

Thanks Valik... so you mean, load up Windows Task Manager, go to Performance tab, and read the status bar text? That would work, I suppose, but that seems a bit round-a-bout; is there a more direct reference to CPU Usage?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Think this is what he is referencing to:

Minimize your taskmanager to the systemtray and then run this script

while 1
   $rc = StatusBarGetText("Windows Task Manager","",2)
   msgbox(0,'cpu usage',$rc)
wend
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Think this is what he is referencing to:

Minimize your taskmanager to the systemtray and then run this script

while 1
   $rc = StatusBarGetText("Windows Task Manager","",2)
   msgbox(0,'cpu usage',$rc)
wend
What he said.

Share this post


Link to post
Share on other sites

What Run ( * ) command would I run to turn on the Task Manager? :whistle:

Thanks

Share this post


Link to post
Share on other sites

just run taskmgr.exe:

run("taskmgr.exe","",@SW_HIDE)
Sleep(1000)
while 1
  $rc = StatusBarGetText("Windows Task Manager","",2)
  msgbox(0,'cpu usage',$rc)
wend

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

:whistle:

Thanks, I knew someone would know that off the top of their head.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Yea I like Jdeb's aproach but with a constant look:

run("taskmgr.exe","",@SW_HIDE)
Sleep(1000)
while 1
 $rc = StatusBarGetText("Windows Task Manager","",2)
 Tooltip($rc,0,0)
sleep(10)
wend

I might write this into a adlib function :whistle:

edit.. did it:

AdlibEnable ("cpuuse",10) 
Run("taskmgr.exe","",@SW_HIDE)
Sleep(1000)

while 1
sleep(10); or whatever the script
Wend

Func cpuuse()
$rc = StatusBarGetText("Windows Task Manager","",2)
Tooltip($rc,0,0)
EndFunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I threw this together as a function I'm calling to check if my computer's busy. Essentially, it checks Task Manger to keep pc usage under 10%, the mouse cursor for 'wait', and then waits for an expected $window to be activated.

Run ( "taskmgr.exe", "", @SW_HIDE )

; Script that calls _Busy ( )

; Checks for a busy computer
Func _Busy ( $window )
    $checka = 1
    $checkb = 1
    While $checka or $checkb <> 0
        $checka = 0
        $checkb = 0
        $pc = 100
        While $pc > 10
            Sleep ( 100 )
            $pc = StatusBarGetText("Windows Task Manager","",2)
            StringTrimRight ( $pc, 1 )
            If $pc > 10 Then
                $checka = 1
            EndIf
        Wend
        While MouseGetCursor ( ) = 15
            Sleep ( 100 )
            $checkb = 1
        Wend
        WinWaitActive ( $window )
    Wend
EndFunc

Now, is there a way to change my _Busy( $window ) to _Busy ( $window, [$wait] ); essentially with an optional passing of $wait as a timeout on the WinWaitActive?

Edited by esfalk

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

couple of remarks for you:

- only start taskmsg if not running yet:

if not ProcessExists("taskmgr.exe" ) then run("taskmgr.exe","",@SW_HIDE)

- your while is coded strange but does work: While $checka or $checkb <> 0

this test for $checha = 1 or $checkb <> 0

what about: While $checka or $checkb

- this statement doesn't do anything: StringTrimRight ( $pc, 1 )

replace it with:

$pc = StringTrimRight( $pc, 1) ; remove the %

$pc = StringRight ( $pc, 3 ) ; get the possible 3 digits

$pc = int(StringReplace($pc,":","")) ; remove the colon and convert to int.

- your function will only check the CPU and mouse once and then will go into waiting mode for the window. in other words the first While doesn't do anything.

A User function cannot have optional parameters, but you could just define the $wait period before you call _Busy...

Here is an alternate version:

Func _Busy( $WINDOW )
   Do
      Do
         Sleep( 100 )
         $PC = StatusbarGetText("Windows Task Manager","",2)
         $PC = StringTrimRight( $PC, 1)      ; remove the %
         $PC = StringRight( $PC, 3 )            ; get the possible 3 digits
         $PC = Int(StringReplace($PC,":","")); remove colon and convert to int.
      Until  $PC < 10
      Do
         Sleep( 100 )
      Until  MouseGetCursor( ) <> 15
   Until WinActive($WINDOW)
EndFunc  ;==>_Busy
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks JdeB; you're quite the debugger. :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0