Jump to content

Can we measure CPU Utilization?


Recommended Posts

I'd like to make something that works like this:

while(1)

{ if (CPU utilization < 40%) emit a mouse click;

sleep 5 minutes;

}

Do the pieces needed for that exist? (I haven't found them in the docs, and am not sufficiently expert in winternals to know what all the system dlls etc do). Is there a function, external app, dll call or something that would let me measure CPU util like that, to use it to control a script's execution?

Thanks!

Link to comment
Share on other sites

Hi,

Very simple :)

Start taskmgr.exe from your script and hide it.

use the following code to get the cpu usage.

While 1
    
    $Cpu = StatusbarGetText('Windows Taakbeheer','',2)
    ToolTip($Cpu,0,0)
    Sleep(10)
    
WEnd

Andre

Edit : Replace Windows Taakbeheer with your language of course :D

Edited by Andre
What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel!
Link to comment
Share on other sites

you could write a Dll with SystemGetTimes

NOTE: NOT SystemGetTime...

maybe ill give it a shot, although many think i really need a lot fo learning to do with C++ so, it may not be safe if i made it.. ill wait :)

but in andres example you could just do like

if $cpu = 40 then blahblah

i think..

FootbaG
Link to comment
Share on other sites

Something using a dll call would surely be more elegant, but leeching off task manager would be a quick and dirty way to get basic function going. I'm looking to make my pc do a pile of work while I'm away from it, but starting multiple instances of the task make it crash. Way too much virtual memory to run in parallel. That crashes the machine.

Emit a mouse click will do, if I stack up a bunch of windows exactly over each other and place the mouse cursor over the "go" button. I bet I could do better by searching windows for a given title string too. More elaborations.

But once it's all done, this could be kinda neat. :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...