Jump to content
Sign in to follow this  
Xandl

Variable Inspector, at runtime

Recommended Posts

Xandl

Hello,

as I have no IDE for AutoIT, and setting MsgBoxes for debug is a lot of work, I was thinking about a variable inspector.

I'll attach my first try, its an script to be includet in your source.

Look at the description in the Inspector.au3 source file.

There is also a test script for the inspector, called Test_Inspector.au3.

To test the test_script

1. put Inspector.au3 into your include directory.

2. put Test_Inspector.au3 into your "normal" script dir.

3. start Test_Inspector.au3 and play with it.

4. you will see all declared global variables, their type and value.

To test in your own script:

1. put Inspector.au3 into your include directory.

2. add these lines to your script:

#include <Inspector.au3>
$rc=init_Inspector("^{F1}")

3. start your script and press Ctrl-F1.

4. you will see all declared global variables, their type and value.

I am not sure if the script is useful enough, as it only shows global vars, but its a nice addition for me, so maybe one of you can use it, too ...

ciao

Xandl

Inspector.au3

Test_Inspector.au3

Share this post


Link to post
Share on other sites
MHz

Interesting script, but very slow?

MsgBoxes for debug is a lot of work

Get Scite4Autoit3 and try Debug to Console. Alt+D on any variables to setup points that will show runtime results of what the variables are doing. This program is the closet thing to an IDE, as you can have with Autoit.

:idiot:

Share this post


Link to post
Share on other sites
Xandl

Interesting script, but very slow?

Is it? I would like to know on which script you tried it. It pops up in under one second here, on a 2,4 Ghz CPU, inspecting a testscript with a bunch of variables and arrays, but only few code. Hm, but it can be optimized tougth, I am not skipping comments(argl!), and maybe functions at the moment, so useless lines of code are checked.

If you tried the Test_Inspector script, have a look at the code, it pops up messages every 10 seconds. Between that, just press Ctrl-F1.

... I am using SciTE already, but I didn't know about the Alt-D option, thanks for the hint =:)

This sure helps, but is far away from my dreams.

(an island in the sun :-)))

ciao

Xandl

Share this post


Link to post
Share on other sites
Xandl

OK, I did test it with a 1600 lines of code script, yes its slow and eats up the CPU, I would like to know why. I changed the script to skip comments and more, but still read functions. Not sure if its save to completely skip them. Its faster now, but not too great.

edit: added attachment, dont know how to change the original one, even found in my bord settings.

PS: I have to admit: SciTE and Alt-D are very useful .)

ciao

Xandl

Inspector.au3

Edited by Xandl

Share this post


Link to post
Share on other sites
MHz

The idea of inspector sounds good.

If you have the latest Scite, then you could try Adding Trace lines, and see how the lines of code are running in realtime. You maybe able to see it spending too much time in a particular area?

Share this post


Link to post
Share on other sites
Xandl

If you have the latest Scite, then you could try Adding Trace lines, and see how the lines of code are running in realtime. You maybe able to see it spending too much time in a particular area?

First, I changed the file read method, reading the file into a line in one slurp (not sure how big the file can be, how much takes a string var?), instead of reading and parsing line for line. This was a unremarkable speed gain. I dont think that I do dummy loops, so there is no time lost.

I see it a lot in checking for existance of a variable in the array(for unicness). This could be much faster if stored in a hash (perl like). But I am not shure if this is the slow part, as the trace function shows no timer values. Using timerdiff, I checked out the bigger loops, maybe time goes by when using StringStripWS and StringSplit a lot?

Only thing I know for sure is, that the part sorting out unic $words from lines and putting into the final array, eats the most time 100:1 to 300:1 (3000 msec to 13-30 msec - IIRC), compared to the variable evaluate part of the script. Well, its OK for me, as I dont have that big scripts, and the tool is useful.

But it would be interesting to know where the time goes off and speed it up :)

That said, it would be nice if someone more experienced could have a look at the script and tell me where to speed it up.

ciao

Xandl

PS: is it possible to add a function like trace to SciTE, I would like to add the timerdiff function, for the nice, fast removal :)

edit: OOPS, I found AutoIt3.lua allready ...

Edited by Xandl

Share this post


Link to post
Share on other sites
MHz

PS: is it possible to add a function like trace to SciTE, I would like to add the timerdiff function, for the nice, fast removal :idiot:

edit: OOPS, I found AutoIt3.lua allready ...

<{POST_SNAPBACK}>

Yes, Scite uses lua extensions. You can create a custom functions in lua to do extra options.

Add TraceLines should be in Tools, in Scite menu.

Share this post


Link to post
Share on other sites
Xandl

Add TraceLines should be in Tools, in Scite menu.

Yes, but time information is missing. To have a new menue entry in SciTE, to see timed values in trace, you may:

1. Append this slightly adopted function to the end of file .\AutiIt3\SciTE\AutoIt3.lua:

function Au3Trace_timer()
   editor:BeginUndoAction()
   FirstLine = 0
    LastLine = editor:LineFromPosition(editor.Length)
    CurrentLine = 0
    editor:GotoLine(0)
    PrevLineCont = 0
    while (CurrentLine <= LastLine) do 
      local LineCode = editor:GetLine(editor:LineFromPosition(editor.CurrentPos))
      -- fill LineCode with "" when nul to avoid function errors
      if LineCode == nul then 
        LineCode = ""
      end
      -- Skip the debug consolewrite lines
      place = string.find(LineCode, "ConsoleWrite%('@@" ) 
      if place then
        LineCode = ""
      end
      -- Skip the line contains test for @error else it could break logic
      place = string.find(LineCode, "@[Ee][Rr][Rr][Oo][Rr]" ) 
      if place then
        LineCode = ""
      end
      -- Remove CRLF
      LineCode = string.gsub(LineCode,"\r\n","")    
      -- Only go WordRight when its not already on a Keyword and LineCode not Empty
      if editor.StyleAt[editor.CurrentPos] ~= SCE_AU3_KEYWORD and LineCode ~= "" then
         editor:WordRight()
      end
        ls = editor.StyleAt[editor.CurrentPos]
        if LineCode ~= "" and ls ~= SCE_AU3_COMMENTBLOCK and ls ~= SCE_AU3_COMMENT and ls ~= SCE_AU3_STRING and ls ~= SCE_AU3_PREPROCESSOR and ls ~= SCE_AU3_SPECIAL then
            editor:LineEnd()
            editor:CharLeft()
            -- check for continuation lines since that would create a syntax error
            if editor.CharAt[editor.CurrentPos] == 95 and editor.StyleAt[editor.CurrentPos] ~= SCE_AU3_COMMENT then
               CurLineCont = 1
            else
               CurLineCont = 0
            end
            if LineCode ~= "" and PrevLineCont == 0 then
                LineCode =  string.gsub(LineCode,"'","''")
                cl = editor:LineFromPosition(editor.CurrentPos) +2
                editor:Home()
                editor:AddText("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tConsoleWrite('@@ (" .. cl .. ") : ***Trace_timer '& x_time() &' msec :" .. LineCode .. "'  & @lf);### Debug Console\r\n" )
--              editor:AddText("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tConsoleWrite('@@ dur: ' & x_time() & ' msec' & @lf) ;### Debug Console\r\n" )
                editor:LineDown()
                editor:Home()
            else
                -- If continuation line then just move down
                editor:LineDown()
                editor:Home()
            end
            PrevLineCont = CurLineCont
            CurrentLine = CurrentLine + 1
        else
            -- just move down on comment and empty lines
            editor:Home()
            editor:LineDown()
            CurrentLine = CurrentLine + 1
        end
    end
   editor:EndUndoAction()
end

2. Insert this for the SciTE menue entry into file .\AutiIt3\SciTE\au3.properties (its one line down from "command.save.before.18.*.au3=2", so you may search for it:

# Add ConsoleWrite Trace_timer lines
command.name.19.*.au3=Debug: Add Trace_timer Lines
command.subsystem.19.*.au3=3
command.19.*.au3=Au3Trace_timer
command.shortcut.19.*.au3=
command.save.before.19.*.au3=2

3. This is a simple timer, please put it into your include directory as .\AutiIt3\include\x_tim.au3:

#include-once

Dim $x_tim_s, $x_tim_d
Global $x_tim_wst = 0.0
$x_tim_s = TimerInit()

Func x_time()
    $x_tim_d = TimerDiff($x_tim_s) - $x_tim_wst
    $x_tim_s = TimerInit()
    Return StringFormat("%.6f",$x_tim_d)
EndFunc

Func x_time_cali()
    Local $x_tim_sc = TimerInit()
    Local $dmy = 0
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    $dmy = x_time()
    Local $x_tim_dc = TimerDiff($x_tim_sc)
    $x_tim_wst = $x_tim_dc / 100;
    If $x_tim_wst < 0 Then Return 0
    Return $x_tim_wst
EndFunc

4. Last, not least, put this init into the start of your script:

#include <x_tim.au3>
ConsoleWrite('latency calibrator: ' & x_time_cali() & ' msec' & @LF)

5. uff :)

Then open SciTE, you will find a new menu entry "Tools\Debug: Add Trace_timer Lines". Just use it, start your script, and see the modified trace including timed values.

ciao

Xandl

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.