Jump to content

My Script seems to use too much processor while idle


Recommended Posts

Hi All,

This script works well, but seems to be working too hard when there is nothing to process.

I run it on several laptops/PCs and the lowest spec machine is a 1.5ghz 1gb ram and Win 7.

The processor seems to be working way too hard as none of the watched processes are even running.

My question is ...

How do I lower the processor requirements, but keep functionality of this script?

I think it might be because i'm using processexist as the checker.

#NoTrayIcon
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=C:\WindowCheck.exe
#AutoIt3Wrapper_Run_Tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
While 1
    If ProcessExists("excel.exe") Then _excel()
    If ProcessExists("allinone.exe") Then _allinone()
    If ProcessExists("outlook.exe") Then _outlook()
    If ProcessExists("ConvertXtoDvd.exe") Then _ConvertXtoDvd()
    Sleep(1000)
WEnd

Func _excel()
    If WinExists("Microsoft Office Excel - Compatibility Checker") Then ;**** Microsoft Office Excel - Compatibility Checker
        Sleep(1500)
        WinActivate("Microsoft Office Excel - Compatibility Checker", "")
        Send("+{TAB 2}{SPACE}")
        Sleep(500)
        Send("{TAB 2}{SPACE}")
    EndIf

    If WinExists("Microsoft Office Excel", "A formula or sheet you") Then ;**** Excel VAT formula
        Sleep(1500)
        WinActivate("Microsoft Office Excel", "A formula or sheet you")
        ControlSend("Microsoft Office Excel", "A formula or sheet you", "[CLASS:Button; INSTANCE:1]", "{SPACE}")
    EndIf

    If WinExists("Microsoft Office Excel", "Do you want Excel to recalculate") Then ;**** Excel to recalculate
        Sleep(1500)
        WinActivate("Microsoft Office Excel", "Do you want Excel to recalculate")
        Send("n")
        Sleep(500)
    EndIf

    If WinExists("Microsoft Office Excel", "Data may exist in the sheet") Then ;**** Excel delete sheet
        Sleep(1500)
        WinActivate("Microsoft Office Excel", "Data may exist in the sheet")
        ControlSend("Microsoft Office Excel", "Data may exist in the sheet", "[CLASS:Button; INSTANCE:1]", "{SPACE}")
    EndIf

    If WinExists("Microsoft Office Excel", "with references to unsaved documents") Then ;**** Excel delete sheet
        Sleep(1500)
        WinActivate("Microsoft Office Excel", "with references to unsaved documents")
        ControlSend("Microsoft Office Excel", "with references to unsaved documents", "[CLASS:Button; INSTANCE:1]", "{SPACE}")
    EndIf

EndFunc   ;==>_excel

Func _allinone()
    If WinExists("Burn Data CD/DVD 5.2", "Enable BURN-Protection") Then WinSetTitle("Burn Data CD/DVD 5.2", "Enable BURN-Protection", "My New Burn Data CD/DVD 5")

    If WinExists("Burn Data CD/DVD 5.2", "The total file size has exceeded 4380 MB") Then ;**** Pepsky Data Burning next disk
        Sleep(1500)
        WinActivate("Burn Data CD/DVD 5.2", "The total file size has exceeded 4380 MB")
        Send("{ENTER}")
        Sleep(1500)
        WinWait("Select the files or folder to be burned")
        Send("{TAB 3}{ENTER}")
    EndIf

    If WinExists("Burn Data CD/DVD 5.2", "Do you want to burn?") Then ;**** Pepsky Data Burning start burn
        Sleep(1500)
        WinActivate("Burn Data CD/DVD 5.2", "Do you want to burn?")
        Send("y")
        Sleep(500)
    EndIf

    If WinExists("Burn Data CD/DVD 5.2", "Delete all of the added files and folders") Then ;**** Pepsky Data Burning Delete all of the added files and folders?
        Sleep(1500)
        WinActivate("Burn Data CD/DVD 5.2", "Delete all of the added files and folders")
        ControlSend("Burn Data CD/DVD 5.2", "Delete all of the added files and folders", "[CLASS:Button; INSTANCE:1]", "{SPACE}")
    EndIf

    If WinExists("Burn Data CD/DVD 5.2", "Burning completed successfully") Then ;**** Pepsky Data Burning complete
        Sleep(1500)
        WinActivate("Burn Data CD/DVD 5.2", "Burning completed successfully")
        ControlSend("Burn Data CD/DVD 5.2", "Burning completed successfully", "[CLASS:Button; INSTANCE:1]", "{SPACE}")
        FileCopy("B:\Scripts\To Use\Completed.au3", "B:\Scripts\AcerLaptop\")
    EndIf

    If WinExists("Information", "Burning image completed") Then ;**** Pepsky Image Burning complete
        Sleep(1500)
        WinActivate("Information", "Burning image completed")
        ControlSend("Information", "Burning image completed", "[CLASS:Button; INSTANCE:1]", "{SPACE}")
        FileCopy("B:\Scripts\To Use\Completed.au3", "B:\Scripts\AcerLaptop\")
    EndIf

    If WinExists("Information", "Burn process completed successfully") Then ;**** Pepsky DVD Folder Burning complete
        Sleep(1500)
        WinActivate("Information", "Burn process completed successfully")
        ControlSend("Information", "Burn process completed successfully", "[CLASS:Button; INSTANCE:1]", "{SPACE}")
        FileCopy("B:\Scripts\To Use\Completed.au3", "B:\Scripts\AcerLaptop\")
    EndIf

    If WinExists("Burn Data CD/DVD 5.2", "Burning completed, verifying failed.") Then ;**** Burning completed, verifying failed.
        Sleep(1500)
        WinActivate("Burn Data CD/DVD 5.2", "Burning completed, verifying failed.")
        ControlSend("Burn Data CD/DVD 5.2", "Burning completed, verifying failed.", "", "!")
        FileCopy("B:\Scripts\To Use\Completed.au3", "B:\Scripts\AcerLaptop\")
    EndIf

EndFunc   ;==>_allinone

Func _outlook()
    WinWait("Microsoft Office Outlook", "A program is trying to send an e-mail message on your behalf", 20)
    For $iNum = 1 To 5
        If WinExists("Microsoft Office Outlook", "A program is trying to send an e-mail message on your behalf") Then
            While 1
                WinActivate("Microsoft Office Outlook")
                Sleep(500)
                If ControlCommand("Microsoft Office Outlook", "A program is trying to send an e-mail message on your behalf", "Button4", "IsEnabled") Then
                    Sleep(500)
                    ControlFocus("Microsoft Office Outlook", "A program is trying to send an e-mail message on your behalf", "[CLASS:Button; INSTANCE:4]")
                    Send("{SPACE}")
                    ExitLoop 2
                EndIf
                Sleep(250)
            WEnd
        EndIf
        Sleep(1000)
    Next
EndFunc   ;==>_outlook

Func _ConvertXtoDvd()
    If WinExists("ConvertXtoDVD", "Operation complete") Then ;**** ConvertXtoDVD Operation Complete
        Sleep(1500)
        WinActivate("ConvertXtoDVD", "Operation complete")
        ControlSend("ConvertXtoDVD", "Operation complete", "[CLASS:Button; INSTANCE:1]", "{SPACE}")
        FileCopy("B:\Scripts\To Use\Completed.au3", "B:\Scripts\AcerLaptop\")
    EndIf

EndFunc   ;==>_ConvertXtoDvd
Link to comment
Share on other sites

On my PC it sits at 0% and goes up to 1% a few times a minute for short moments.

I have a faster PC. (E8500 @ 3.16 GHz), but I would still expect it to atleast stay at, or above 2%. Ofcoarse not all 1.5 GHz processors are alike.

Reducing the main sleep to 100ms pushed the script 2 percent higher. (2% with jumps to 3%) which is more then in had expected.

Putting a sleep(25) between each processexists (replacing the original sleep) resulted in the script jumping between 0 and 3-4% cpu usage.

I am getting better results using ProcessList() and searching the resulting array for the processes you're looking for.

Link to comment
Share on other sites

I just tested it and I don't see it hogging the CPU either. Memory values of about 8 to 9.5 MB of RAM and 6 to 7 of VM. Pretty standard for any executable made with AutoIt. Zero to 1% of CPU on my duel core machine.

However there is a method to set the priority (as you can in the task manager) of your process. ProcessSetPriority ("myprocess.exe", 0) will lower the process to Low(Idle), even the application itself. The range is 0 to 5 (5 is Realtime) so be careful!

Link to comment
Share on other sites

I wouldn't call it cpu hogging, but it is a little heavier than I expected.

This script shows that it's about 4 times slower than winexists for instance (for me at least)

Local $timer = TimerInit()
For $i = 0 To 999
    ProcessExists("randomnonexistingprocess")
Next
ConsoleWrite("1000*ProcessExists = " & Round(TimerDiff($timer),0) & "ms." & @CRLF)

$timer = TimerInit()
For $i = 0 To 999
    WinExists("randomnonexistingwindow")
Next
ConsoleWrite("1000*WinExists = " & Round(TimerDiff($timer),0) & "ms." & @CRLF)

@OP: Winexists would be a viable alternative to processexists for your particular script.

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...