Znuffie Posted March 16, 2015 Share Posted March 16, 2015 Hello, I'm currently having a small issue with my script. I'm automating the export of some files with a 3rd party application which lacks a decent way to script around. The app works just fine, but after the 2nd or 3rd run, whole OS (I'm running this on Windows 7 inside VMWare) is slow as hell! I tried adding sleep()'s all around just to give it time to catch up, but to no avail. Can someone shed some light as to why this is happening? (My code to "allow the VM to catch up" doesn't really fix anything, even after that long pause, the VM is still slow as hell) My code: expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> #include <MsgBoxConstants.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $program = "C:\Program Files\Smart Player\Smart Player.exe" Opt("MouseCoordMode", 0) Opt("WinTitleMatchMode", 4) Opt("SendKeyDelay", 25) Opt("TrayIconHide", 1) $count = 0 Func GetFile() $file = RecursiveFileSearch("Z:\Surv\_swap", "\.(dav)", ".", 1, True) If $file[0] > 0 Then ConsoleWrite("There are " & $file[0] & " files left" & @CRLF) Return $file[1] Else Return False EndIf EndFunc ;==>GetFile Func _log($string) $time = _Date_Time_GetSystemTime() $time = _Date_Time_SystemTimeToDateTimeStr($time) ConsoleWrite("[" & $time & "] " & $string & @CRLF) Sleep(15) EndFunc ;==>_log Func ConvertFile($file) _log("Do: " & $file); If ProcessExists("Smart Player.exe") Then _log("Exit Program") ProcessClose("Smart Player.exe") EndIf _log("Run Program") Run($program & " " & $file) _log("Waiting for activation...") WinWaitActive("Smart Player") Sleep(500) _log("Closing preview...") ; close preview MouseMove(629, 83, 0) MouseClick("left", 629, 83, 1, 0) Sleep(50) MouseMove(627, 110, 50) Sleep(250) MouseClick("left", 627, 110, 1, 0) ;ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:119]", "left", 1, 296, 11) _log("Clicking export...") ; click to export ;MouseMove(336,36) Sleep(75) MouseClick("left", 336, 36, 1, 0) _log("Checkmark on the file") ; check file ;MouseMove(644, 157) Sleep(75) MouseClick("left", 644, 157, 1, 0) ; stopping preview ;MouseMove(184, 475) Sleep(150) ;MouseClick("left", 184, 475, 1, 0) ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:32]") Sleep(1000) _log("Clicking on Format") ; click on format ;MouseMove(788, 442, 0) Sleep(500) ;MouseClick("left", 788, 442, 1, 0) ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:11]") _log("Selecting AVI") ; Select AVI MouseMove(770, 538, 0) Sleep(250) MouseClick("left", 770, 538, 1, 0) Sleep(250) _log("Exporting now...") ; Click EXPORT MouseMove(487, 544, 0) Sleep(250) MouseClick("left", 487, 544, 1, 10) ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:27]") ; get directory $dir = GetDir($file) _log("Typing Directory: " & $dir) ; type directory Sleep(2500) WinWaitActive("Find Directory") Send($dir & "{ENTER}") Sleep(15000) _log("Checking if there are JPG files in here") $findjpg = RecursiveFileSearch($dir, "\.(jpg)", ".", 1, False) If $findjpg[0] > 0 Then _log("Found JPG files... we failed :-(") ProcessClose("Smart Player.exe") FileChangeDir($dir) FileDelete("*.jpg") Sleep(1000) Return True EndIf _log("Waiting to finish export...") ; now waiting to finish export... WinWaitActive("[W:301; H:136]") _log("Clicking OK") ; clicking "OK" ;MouseMove(159, 111) Sleep(75) MouseClick("left", 159, 111, 1, 0) _log("Exit Program") ProcessClose("Smart Player.exe") Sleep(500) ;DONE $newfile = StringReplace($file, ".dav", ".done") _log("Moving file to: " & $newfile) FileMove($file, $newfile) _log("--- --- --- DONE --- --- --") EndFunc ;==>ConvertFile While True ConvertFile(GetFile()) Sleep(1000) $count = $count + 1 If $count >= 5 Then ConsoleWrite(@CRLF & "Allowing VM to catch up..." & @CRLF) Sleep(20000) $count = 0 EndIf WEnd Func GetDir($sFilePath) Local $aFolders = StringSplit($sFilePath, "\") Local $iArrayFoldersSize = UBound($aFolders) Local $FileDir = "" If (Not IsString($sFilePath)) Then Return SetError(1, 0, -1) EndIf $aFolders = StringSplit($sFilePath, "\") $iArrayFoldersSize = UBound($aFolders) For $i = 1 To ($iArrayFoldersSize - 2) $FileDir &= $aFolders[$i] & "\" Next Return $FileDir EndFunc ;==>GetDir #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.10.0 Author: WeaponX Updated: 2/21/08 Script Function: Recursive file search 2/21/08 - Added pattern for folder matching, flag for return type 1/24/08 - Recursion is now optional Parameters: RFSstartdir: Path to starting folder RFSFilepattern: RegEx pattern to match "\.(mp3)" - Find all mp3 files - case sensitive (by default) "(?i)\.(mp3)" - Find all mp3 files - case insensitive "(?-i)\.(mp3|txt)" - Find all mp3 and txt files - case sensitive RFSFolderpattern: "(Music|Movies)" - Only match folders named Music or Movies - case sensitive (by default) "(?i)(Music|Movies)" - Only match folders named Music or Movies - case insensitive "(?!(Music|Movies)\:)\b.+" - Match folders NOT named Music or Movies - case sensitive (by default) RFSFlag: Specifies what is returned in the array 0 - Files and folders 1 - Files only 2 - Folders only RFSrecurse: TRUE = Recursive, FALSE = Non-recursive RFSdepth: Internal use only #ce ---------------------------------------------------------------------------- Func RecursiveFileSearch($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = True, $RFSdepth = 0) ;Ensure starting folder has a trailing slash If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\" If $RFSdepth = 0 Then ;Get count of all files in subfolders for initial array definition $RFSfilecount = DirGetSize($RFSstartDir, 1) ;File count + folder count (will be resized when the function returns) Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1] EndIf $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*") If @error Then Return ;Search through all files and folders in directory While 1 $RFSnext = FileFindNextFile($RFSsearch) If @error Then ExitLoop ;If folder and recurse flag is set and regex matches If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then If $RFSrecurse And StringRegExp($RFSnext, $RFSFolderpattern, 0) Then RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1) If $RFSFlag <> 1 Then ;Append folder name to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext $RFSarray[0] += 1 EndIf EndIf ElseIf StringRegExp($RFSnext, $RFSFilepattern, 0) And $RFSFlag <> 2 Then ;Append file name to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext $RFSarray[0] += 1 EndIf WEnd FileClose($RFSsearch) If $RFSdepth = 0 Then ReDim $RFSarray[$RFSarray[0] + 1] Return $RFSarray EndIf EndFunc ;==>RecursiveFileSearch Link to comment Share on other sites More sharing options...
Geir1983 Posted March 16, 2015 Share Posted March 16, 2015 You have a loop without sleep (line 229), maybe this is your problem? expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> #include <MsgBoxConstants.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $program = "C:\Program Files\Smart Player\Smart Player.exe" Opt("MouseCoordMode", 0) Opt("WinTitleMatchMode", 4) Opt("SendKeyDelay", 25) Opt("TrayIconHide", 1) $count = 0 Func GetFile() $file = RecursiveFileSearch("Z:\Surv\_swap", "\.(dav)", ".", 1, True) If $file[0] > 0 Then ConsoleWrite("There are " & $file[0] & " files left" & @CRLF) Return $file[1] Else Return False EndIf EndFunc ;==>GetFile Func _log($string) $time = _Date_Time_GetSystemTime() $time = _Date_Time_SystemTimeToDateTimeStr($time) ConsoleWrite("[" & $time & "] " & $string & @CRLF) Sleep(15) EndFunc ;==>_log Func ConvertFile($file) _log("Do: " & $file); If ProcessExists("Smart Player.exe") Then _log("Exit Program") ProcessClose("Smart Player.exe") EndIf _log("Run Program") Run($program & " " & $file) _log("Waiting for activation...") WinWaitActive("Smart Player") Sleep(500) _log("Closing preview...") ; close preview MouseMove(629, 83, 0) MouseClick("left", 629, 83, 1, 0) Sleep(50) MouseMove(627, 110, 50) Sleep(250) MouseClick("left", 627, 110, 1, 0) ;ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:119]", "left", 1, 296, 11) _log("Clicking export...") ; click to export ;MouseMove(336,36) Sleep(75) MouseClick("left", 336, 36, 1, 0) _log("Checkmark on the file") ; check file ;MouseMove(644, 157) Sleep(75) MouseClick("left", 644, 157, 1, 0) ; stopping preview ;MouseMove(184, 475) Sleep(150) ;MouseClick("left", 184, 475, 1, 0) ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:32]") Sleep(1000) _log("Clicking on Format") ; click on format ;MouseMove(788, 442, 0) Sleep(500) ;MouseClick("left", 788, 442, 1, 0) ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:11]") _log("Selecting AVI") ; Select AVI MouseMove(770, 538, 0) Sleep(250) MouseClick("left", 770, 538, 1, 0) Sleep(250) _log("Exporting now...") ; Click EXPORT MouseMove(487, 544, 0) Sleep(250) MouseClick("left", 487, 544, 1, 10) ControlClick("Smart Player", "", "[CLASS:QWidget; INSTANCE:27]") ; get directory $dir = GetDir($file) _log("Typing Directory: " & $dir) ; type directory Sleep(2500) WinWaitActive("Find Directory") Send($dir & "{ENTER}") Sleep(15000) _log("Checking if there are JPG files in here") $findjpg = RecursiveFileSearch($dir, "\.(jpg)", ".", 1, False) If $findjpg[0] > 0 Then _log("Found JPG files... we failed :-(") ProcessClose("Smart Player.exe") FileChangeDir($dir) FileDelete("*.jpg") Sleep(1000) Return True EndIf _log("Waiting to finish export...") ; now waiting to finish export... WinWaitActive("[W:301; H:136]") _log("Clicking OK") ; clicking "OK" ;MouseMove(159, 111) Sleep(75) MouseClick("left", 159, 111, 1, 0) _log("Exit Program") ProcessClose("Smart Player.exe") Sleep(500) ;DONE $newfile = StringReplace($file, ".dav", ".done") _log("Moving file to: " & $newfile) FileMove($file, $newfile) _log("--- --- --- DONE --- --- --") EndFunc ;==>ConvertFile While True ConvertFile(GetFile()) Sleep(1000) $count = $count + 1 If $count >= 5 Then ConsoleWrite(@CRLF & "Allowing VM to catch up..." & @CRLF) Sleep(20000) $count = 0 EndIf WEnd Func GetDir($sFilePath) Local $aFolders = StringSplit($sFilePath, "\") Local $iArrayFoldersSize = UBound($aFolders) Local $FileDir = "" If (Not IsString($sFilePath)) Then Return SetError(1, 0, -1) EndIf $aFolders = StringSplit($sFilePath, "\") $iArrayFoldersSize = UBound($aFolders) For $i = 1 To ($iArrayFoldersSize - 2) $FileDir &= $aFolders[$i] & "\" Next Return $FileDir EndFunc ;==>GetDir #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.10.0 Author: WeaponX Updated: 2/21/08 Script Function: Recursive file search 2/21/08 - Added pattern for folder matching, flag for return type 1/24/08 - Recursion is now optional Parameters: RFSstartdir: Path to starting folder RFSFilepattern: RegEx pattern to match "\.(mp3)" - Find all mp3 files - case sensitive (by default) "(?i)\.(mp3)" - Find all mp3 files - case insensitive "(?-i)\.(mp3|txt)" - Find all mp3 and txt files - case sensitive RFSFolderpattern: "(Music|Movies)" - Only match folders named Music or Movies - case sensitive (by default) "(?i)(Music|Movies)" - Only match folders named Music or Movies - case insensitive "(?!(Music|Movies)\:)\b.+" - Match folders NOT named Music or Movies - case sensitive (by default) RFSFlag: Specifies what is returned in the array 0 - Files and folders 1 - Files only 2 - Folders only RFSrecurse: TRUE = Recursive, FALSE = Non-recursive RFSdepth: Internal use only #ce ---------------------------------------------------------------------------- Func RecursiveFileSearch($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = True, $RFSdepth = 0) ;Ensure starting folder has a trailing slash If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\" If $RFSdepth = 0 Then ;Get count of all files in subfolders for initial array definition $RFSfilecount = DirGetSize($RFSstartDir, 1) ;File count + folder count (will be resized when the function returns) Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1] EndIf $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*") If @error Then Return ;Search through all files and folders in directory While 1 Sleep(10) $RFSnext = FileFindNextFile($RFSsearch) If @error Then ExitLoop ;If folder and recurse flag is set and regex matches If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then If $RFSrecurse And StringRegExp($RFSnext, $RFSFolderpattern, 0) Then RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1) If $RFSFlag <> 1 Then ;Append folder name to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext $RFSarray[0] += 1 EndIf EndIf ElseIf StringRegExp($RFSnext, $RFSFilepattern, 0) And $RFSFlag <> 2 Then ;Append file name to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext $RFSarray[0] += 1 EndIf WEnd FileClose($RFSsearch) If $RFSdepth = 0 Then ReDim $RFSarray[$RFSarray[0] + 1] Return $RFSarray EndIf EndFunc ;==>RecursiveFileSearch Link to comment Share on other sites More sharing options...
Znuffie Posted March 16, 2015 Author Share Posted March 16, 2015 I don't think that's the issue. I mean, I don't have an issue in that loop. The delay/slow performance is when the script automates the UI of the 3rd party program. Link to comment Share on other sites More sharing options...
Geir1983 Posted March 16, 2015 Share Posted March 16, 2015 Did you try it? Its part of your main loop and its called recursively.. Link to comment Share on other sites More sharing options...
mpower Posted March 16, 2015 Share Posted March 16, 2015 The whole code seems inefficient in the way it is structured. Please provide a small working reproducer that anyone can run. It's hard to debug when I cannot really run the script. Link to comment Share on other sites More sharing options...
jguinch Posted March 16, 2015 Share Posted March 16, 2015 RecursiveFileSearch use some slow Redim and does not free the $RFSarray Try to use _FileListToArrayRec instead. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Znuffie Posted March 16, 2015 Author Share Posted March 16, 2015 Did you try it? Its part of your main loop and its called recursively.. Yes I did try it. It has no effect on the actual automation on the UI actions. That's where it lags. The whole code seems inefficient in the way it is structured. Please provide a small working reproducer that anyone can run. It's hard to debug when I cannot really run the script. I would if I had any idea exactly what causes it to slow down after the first try. The 3rd party app is written in QT. It seems that after the first run, the "File Save" dialogue takes a lot of time (>3seconds) to render. And I'm not sure WHY, as I'm restarting the app... Link to comment Share on other sites More sharing options...
Geir1983 Posted March 17, 2015 Share Posted March 17, 2015 So do you restart the 3rd party app or do you restart your autoit script to make the problem disappear? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now