Sign in to follow this  
Followers 0
enneract

performance problem

5 posts in this topic

#1 ·  Posted (edited)

Can anyone spot where I have a problem that could introduce a major memory leak or other problem causing severe performance degradation? My system drops to a crawl about 60 seconds after launching the script.

The other problem is that the mouse hook only seems to trigger on the first left click after the script is run, and I don't have a clue about this either.

; ~~ Mouse Hook ~~
;For more info, Visit: http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx

;Include GUI Consts
#include <GUIConstants.au3> ;for $GUI_EVENT_CLOSE
#Include <WinAPI.au3> ;for HIWORD
#NoTrayIcon

;These constants found in the helpfile under Windows Message Codes
Global Const $WM_LBUTTONDOWN = 0x0201

Global Const $timeout = 5 ;seconds

;Consts/structs from msdn
Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
;~ Global Const $WH_MOUSE_LL = 14           ;already declared
;~ Global Const $tagPOINT = "int X;int Y"   ;already declared

;Register callback
$hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)

$timer = 0


Run("C:\Program Files\RocketDock\RocketDock.exe")         ;launch RocketDock  
;ConsoleWrite("Stage 1 ")
While 1                                                   
    If BitAND(WinGetState("RocketDock"),2) Then           ;Wait for window to appear
        Send("!^r")                                       ;close dock   
        ;ConsoleWrite("Stage 3 ")
        ExitLoop
    EndIf
    ;ConsoleWrite("Stage 2 ")
WEnd

While 1
    If BitAND(WinGetState("RocketDock"), 2) Then          ;if visible
        $timer = TimerInit()                              ;start timer
        While BitAND(WinGetState("RocketDock"), 2)        ;while visible
            If TimerDiff($timer) > $timeout * 1000 Then   ;check TimerDiff
                send("!^r")
                ;ConsoleWrite("Stage 6 ")
            EndIf
            ;ConsoleWrite("Stage 5 ")
            Sleep(500)
        WEnd
    EndIf
    ;ConsoleWrite("Stage 4 ")
    Sleep(1000)                                    ;one second pause, this isn't high priority
WEnd
Exit

Func _Mouse_Proc($nCode, $wParam, $lParam) ;function called for mouse events..    
    If $nCode < 0 OR $wParam <> $WM_LBUTTONDOWN Then ;recommended, see http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx
        $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
                "int", $nCode, "ptr", $wParam, "ptr", $lParam) ;recommended
        Return $ret[0]
    EndIf       
    
    ConsoleWrite("Stage 7 ")
    
    If BitAND(WinGetState("RocketDock"), 2) Then
        Sleep(500)
        ConsoleWrite("Stage 8 ")
        Send("!^r")
    EndIf
    
    ;This is recommended instead of Return 0
    $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
            "int", $nCode, "ptr", $wParam, "ptr", $lParam)
    Return $ret[0]
EndFunc   ;==>_Mouse_Proc

Func OnAutoItExit()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
    $hM_Hook[0] = 0
    DllCallbackFree($hKey_Proc)
    $hKey_Proc = 0
EndFunc   ;==>OnAutoItExit
Edited by enneract

Share this post


Link to post
Share on other sites



What exactly is the code supposed to be doing? Is your program actually leaking memory (check taskmgr)?

I'm not sure if you should be using a Sleep inside a DLL Callback function or not. It doesn't seem like a good idea to me.

It monitors for visibility of a dock program called RocketDock, and sends a hotkey to hide it after it has been visible to a certain amount of time, or if a left click occurs.

As for the sleep within the callback function... I can't find any way around it. Without it, the dock often doesn't register the click before the script hides the window.

I seemed to have worked around it by creating the hook when the window becomes visible, and destroying it when the window is hidden, but it does create a slight delay where mouse clicks can't be detected.

Share this post


Link to post
Share on other sites

Okay, now I'm afraid I must ask why as I am baffled as to why you'd want to do such a thing. It has been quite a while since I used RocketDock, but I thought it had auto-hiding.

It's auto-hiding functionality is based on mouse cursor proximity, which is utterly useless for what I am using it as.

Using it as an application launcher for my tablet PC, and if I am using the touch screen, it is nearly impossible to trigger.

If you ask why I don't just use the win7 taskbar - it is for a similar reason, that in portrait mode, it is extremely difficult to hit the UI controls to change the taskbar 'page' using touch.

Share this post


Link to post
Share on other sites

I don't know about your 2nd problem ...

but try Sleep(10) in your first while loop to keep CPU at minimum. It was running at 100% on mine.


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

I don't know about your 2nd problem ...

but try Sleep(10) in your first while loop to keep CPU at minimum. It was running at 100% on mine.

The first while loop should only execute for a few fractions of a second, it just does the initial hiding.

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