Jump to content
Sign in to follow this  
Ferryman

Dllcall loop with delay

Recommended Posts

Ferryman

I would like to display the actual CPU frequency in my app.

To determine the CPU frequency I use an external Dll to read the CPU TSC register.

The update rate of 1 second would be more than enough, however I cannot figure out how to "loop" the dllcall without locking the other functionality of the GUI (the GUI is unresponsive if the call is looped).

$DLL=DllOpen("xxx.dll")
$TSCInit = DllCall($DLL, "dword", "Rdtsc", "dword*", "", "dword*", "")
Sleep(200)
$TSCTerm = DllCall($DLL, "dword", "Rdtsc", "dword*", "", "dword*", "")
$TSCInitHi = Hex($TSCInit[2], 8)
$TSCInitLo = Hex($TSCInit[1], 8)
$TSCTermHi = Hex($TSCTerm[2], 8)
$TSCTermLo = Hex($TSCTerm[1], 8)
$TSCInitHiLo = $TSCInitHi&$TSCInitLo
$TSCInitHiLo = Dec($TSCInitHiLo)
$TSCTermHiLo = $TSCTermHi&$TSCTermLo
$TSCTermHiLo = Dec($TSCTermHiLo)
$TSC = $TSCTermHiLo - $TSCInitHiLo
$TSC = $TSC * 5
$TSC = $TSC / 1000000
$TSC = Round($TSC, 2)

This loop requires a fixed delay (to determine how much the TSC increases).

Also since I want to use as little resources as possible, I would like to set the "polling rate" to 1 second.

Is there any way to loop this call without "freezing" to other functionality of the GUI?

Thanks

Share this post


Link to post
Share on other sites
kylomas

Ferryman,

You might try using an adlib to run your monitoring function.

kylomas

edit: just for grins...not calling an external prog but demonstrates the principle

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#Include <WinAPIEx.au3>

#AutoIt3Wrapper_Add_Constants=n

local $gui010   =   guicreate('')
local $aSize    =   wingetclientsize($gui010)
local $lbl010   =   guictrlcreatelabel('',10,$aSize[0]-50,$aSize[1]-20,30,bitor($ss_sunken,$ss_centerimage,$ss_center))
local $btn010   =   guictrlcreatebutton('Press Me While The ADLIB is Running To Test Responsivness',10,$aSize[0]-150,$aSize[1]-20,30)
                    guisetstate()

                    adlibregister("_process_time",1000)

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $btn010
            ConsoleWrite('Yep, responsive...' & @LF)
    EndSwitch
WEnd

func _process_time()

    $aPTime = _WinAPI_GetProcessTimes(@AutoItPID)
    guictrlsetdata($lbl010,'Sample at ' & @min & ':' & @sec &  '    Kernel Time = ' & $aPTime[1] & '           User Mode Time = ' & $aPTime[2])

endfunc
Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

×