Jump to content

Recommended Posts

Posted (edited)

Built using AutoIt Beta 3.3.1.7

Is your AutoIt script not running as fast as you would like, but you don't know where to start trying to make it run faster. If the answer is yes then this application may help you

AU3Profiler instruments a script to provided comprehensive timing information on how much time is spent executing code in each function or user identified section of code. For those of you who are not familiar with profilers they are a very useful tool when you have got you your application to to a state where functionally it works but is perhaps not working as fast as you would like. A profiler identifies those functions of blocks of code that your application spends the most time executing. Thus enabling you to target your efforts to improve the speed where it is likely to have the most impact. For example you will get a 10 times benifit to your application by improving the speed of a function that is called 1000 times by 10ms than by improving the speed of a function by 1000ms that is only called once.

AU3Profiler instruments functions automatically but if you would like timings for blocks of code smaller than a function you need to add special comments to you code'

Example:

;ProfileBlockStart("Outer loop")  <==== This comment will start a timing block
   For $i = 0 To 50
        ;ProfileBlockStart("Inner loop")  <==== This comment will start a nested timing block
        For $j = 0 To 100
       $Result += $i * $j
     Next
        ;ProfileBlockStop() <==== This coment will end the "Inner loop" timing block
        Sleep(10)
   Next
   ;ProfileBlockStop() <==== This comment will end the "Outer loop" timing block

Note: Before using AU3 profiler you should check that your script runs and is error free.

Your original AU3 script file will not be altered by AU3Profiler.  

Posted Image

Added New Version AU3Profiler 3.4.3963.0

Now includes ability to add command line options for the script being profiled

Profiler.zip

AU3 Profiler Test applications.zip

'Profiler Test App_3_3_0_0.au3' is compatible with the Autoit Production version 3.3.0.0 

'Profiler Test App_3_3_1_6.au3' is compatible with the Autoit Beta version 3.3.1.6 and above 

AU3Profiler Help File

AU3Profiler Source Code

Source Code (I need to spend some time commenting this and tidying it up)

EDIT: Uploaded new versions of al files

 

Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted (edited)

This is very useful, good work Bowmore, ;) and it looks like a lot of effort has gone into it so far.

To save me wading through the enormous help file, and your code, can you tell me what the negative values mean?

Tried again and no negative values!

I haven't studied your script but I know from when I wrote a debugger (now defunct) which had to do some similar things, that catching all the horrible constructions that were likely to be written in a script could sometimes be a pain in the backside.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted

I tried to run your script, which looks great btw, but it looks like the forum is butchering the code:

C:\Downloads\Profiler\Profiler.au3(778,160) : ERROR: syntax error (illegal character)
    $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(If .*? Then)[ \t]*(\bReturn\b.*?){:content:}quot;, " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(781,196) : ERROR: syntax error (illegal character)
    $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(\bReturn\b.*?){:content:}quot;, $sProfileBlockStop & $sProfileFunctionstop & @CRLF & " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(803,158) : ERROR: syntax error (illegal character)
    $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(If .*? Then)[ \t]*(\bExit\+.*?){:content:}quot;, " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(806,217) : ERROR: syntax error (illegal character)
    $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(\bExit\b.*?){:content:}quot;, $sProfileBlockStop & $sProfileFunctionstop & @CRLF & $sProfReport & @CRLF & " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(883,162) : ERROR: syntax error (illegal character)
    $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(If .*? Then)[ \t]*(\bReturn\b.*?){:content:}quot;, " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(886,177) : ERROR: syntax error (illegal character)
    $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(\bReturn\b.*?){:content:}quot;, $sProfileFunctionstop & @CRLF & " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3 - 6 error(s), 0 warning(s)

I don't think that "{:content:}quot;" is supposed to be there.

- The Kandie Man ;-)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Posted

This is very useful, good work Bowmore, ;) and it looks like a lot of effort has gone into it so far.

To save me wading through the enormous help file, and your code, can you tell me what the negative values mean?

Tried again and no negative values!

I haven't studied your script but I know from when I wrote a debugger (now defunct) which had to do some similar things, that catching all the horrible constructions that were likely to be written in a script could sometimes be a pain in the backside.

Thanks for the comments guys

I have noticed that the displayed results do on very rare occasions get corrupted giving spurious values. There should never be any negative values. I'll have a look and see if I can recreate the problem. The main problem with code constructs I had to deal with were the single line return/exit statements e.g. If $a <>  $b Then Return SetError(1,0,1) but RegEx sorted that by converting it to multi line If Then EndIf  statements.

The error column is there to flag up any instance of where the user has managed to think of a way of exiting a function that I haven't allowed for, but I'm sure there will be situation that I have miss when more people try it.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted

I tried to run your script, which looks great btw, but it looks like the forum is butchering the code:

C:\Downloads\Profiler\Profiler.au3(778,160) : ERROR: syntax error (illegal character)
     $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(If .*? Then)[ \t]*(\bReturn\b.*?){:content:}quot;, " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(781,196) : ERROR: syntax error (illegal character)
     $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(\bReturn\b.*?){:content:}quot;, $sProfileBlockStop & $sProfileFunctionstop & @CRLF & " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(803,158) : ERROR: syntax error (illegal character)
     $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(If .*? Then)[ \t]*(\bExit\+.*?){:content:}quot;, " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(806,217) : ERROR: syntax error (illegal character)
     $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(\bExit\b.*?){:content:}quot;, $sProfileBlockStop & $sProfileFunctionstop & @CRLF & $sProfReport & @CRLF & " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(883,162) : ERROR: syntax error (illegal character)
     $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(If .*? Then)[ \t]*(\bReturn\b.*?){:content:}quot;, " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3(886,177) : ERROR: syntax error (illegal character)
     $aScriptSourceCode[$iCodeLine] = StringRegExpReplace($aScriptSourceCode[$iCodeLine], "(?i)^([ \t]*)(\bReturn\b.*?){:content:}quot;, $sProfileFunctionstop & @CRLF & " \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Downloads\Profiler\Profiler.au3 - 6 error(s), 0 warning(s)

I don't think that "{:content:}quot;" is supposed to be there.

- The Kandie Man ;-)

Thanks for bringing that to my attention I think I've managed to fix it. The '{:content:}quot;' should be '$"' without the single quotes.

 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted (edited)

I'm disappointed.

  • The help button doesn't work (tries to start some file that doesn't exist)
  • The help file that is FileInstall'd is incomplete
  • The included test file crashes, with both 3.3.0.0 and 3.3.1.1
  • Also why are you starting AutoIt with "/SO"? That isn't right.

Edit: Also you should add a input (or something) for command line parameters, I shouldn't have to edit my scripts to profile them...

Edit2: And you're starting the beta with "/BETA"... ;)

Edited by AdmiralAlkex
Posted (edited)

I also found out the help file doesn't open. Looking through the code, I found that the help file should be installed as AU3Profiler Help.rtf because the name of the executable file is AU3Profiler, not Profiler.

But other than that quick fix, I don't see anything terribly wrong with the script. It can obviously be tidied up, but the program works great for a first release.

Edited by dantay9
Posted

Nicely done very useful tool.

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Posted

I'm disappointed.

  • The help button doesn't work (tries to start some file that doesn't exist)
  • The help file that is FileInstall'd is incomplete
  • The included test file crashes, with both 3.3.0.0 and 3.3.1.1
  • Also why are you starting AutoIt with "/SO"? That isn't right.

Edit: Also you should add a input (or something) for command line parameters, I shouldn't have to edit my scripts to profile them...

Edit2: And you're starting the beta with "/BETA"...  ;)

New version uploaded 0.0.0.7 (see first post)

Source code and other files also replaced.

Thanks for letting me know about these bugs.

  • I've changed the name of the help document so that it now open from the help button. I normally have fileinstall rename the file so I don't overwrite it when testing but I messed up this time.
  • Fixed - Correct file now included in exe.
  • The original test file included was built using 3.3.1.6. I've removed the test file from the exe and uploaded 2 versions, one compatible with 3.3.0.0 and the other with beta 3.3.1.6 and above.
  • "/SO" and "/BETA" parameters used with Autoit3.exe, removed. The perils of cutting and pasting code.
It is only necessary to make any any edits to your script to profile them if you want any more detailed timings than function level. I plan to create a function for Scite to enable the user to select a line or group of lines and have the special comment tags inserted automatically.

The ability to run from a command line is on my list of things to do. 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted

No you missunderstood, I want to run your profiler on one of my scripts that is ONLY supposed to be used with a couple of command line parameters. But you have no place for setting them so I have to hardcode some settings in my script ;)

Posted

No you missunderstood, I want to run your profiler on one of my scripts that is ONLY supposed to be used with a couple of command line parameters. But you have no place for setting them so I have to hardcode some settings in my script :evil:

Oh! I get it now.  ;) I need to add an edit box for the user to enter any command line parameters for their script. 

Thanks

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Posted

Yes.

I have found that one my test script, the profiler somehow causes one of the variables to fail upon the second or third profile (and all subsequent ones).

I don't know how - I've looked at the script_Profiler.au3 code, and it all looks fine. And if I blow away that profiler script and make a new one, everything runs fine again - until the second or third go again.

It's a bit curious.

Posted

Nice idea and work!

I can give you this feedback on error handling:

I have a script that reads folder names from E:\, and when I run it on a computer that wants E: to be a memory card, I get the error shown in the attached picture.

(There is no disk in the unit. Insert a disk in unit \Device\Harddisk1\DR1)

Trying with the empty DVD reader/writer, or a non-existent letter, causes no problem, just the card reader.

Also, whenever I check the UDF box, I get "Subscript used with non-Array variable". Maybe I'm using that wrong? I have an #include <> and a function call. Do I need the full function declaration?

post-42277-12615242509115_thumb.png

  • 10 months later...
Posted

New Version Added

I've just added an updated version that allows you to add commandline parameters for the script you are profileing.

See first post for link. to AU3Profiler  version 3.4.3963.0

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

  • 2 years later...
Posted

Hey Bowmore!

This posting is more documentary than a real question. I like your script very much and many thanks for it! I found out, that there is a special "feature" ;-) with the replacement of 'Exit' lines with the last _ap_profileStop and _ap_ProfileReport routines, if you add a variable to return the main exit code.

Stay away from variables with "return" in the name!! $returncode isn't a great choice, as that makes AU3Profiler think, it's a "return" line and not an "exit" line. But "Exit" lines are treated that way, that the main profiling stops and the report will be shown.

Don't: "Exit $returncode"

Do: "Exit $retcode"

Just for the record...

Regards,

Holger

Posted

Thanks for the comments Holger. Ahh those little extra features that come to light when someone else runs your code.  :> I'll have a look when I get a bit of spare time. It will probably get a complete rewrite and properly documented as people at work keep asking for some small changes. I've a lot more experience with AutoIt now than when I originally started this project.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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
  • Recently Browsing   0 members

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