Android Question Is Sub Routine tracing possible?

Discussion in 'Android Questions' started by Robert Valentino, Mar 24, 2015.

Similar threads

B4A Tutorial Uncaught Exceptions
B4A Question SSL Websocket client
B4A Tutorial MJPEG / CCTV Server
B4A Question Changing Locale of Android
B4A Library [Class] Flexible Table
  1. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Is there a way in Debug mode to turn on routine tracing?

    I know I can go put Log messages in the beginning and ALL the exit points of me routines (what a pain this would be)

    It would be nice if there was someway to turn this type of feature on so I could easily see the execution path so maybe I can tighten things up.

    BobVal
     
    Brian Robinson and Troberg like this.
  2. Troberg

    Troberg Well-Known Member Licensed User

    Yes, that's something I've longed for in just about every dev environment I've worked in. A log, somewhat like this:

    2015-03-25 07:42:02.142 Main.SelectFile_Click()
    2015-03-25 07:42:02.144 Main.ShowFileSelector(Startdir="/")
    2015-03-25 07:42:15.764 Main.SaveSettings()

    Edit: Once in place, this would also be a large step towards a code profiler.
     
    Last edited: Mar 25, 2015
  3. Brian Robinson

    Brian Robinson Active Member Licensed User

  4. Troberg

    Troberg Well-Known Member Licensed User

    A stack trace is also useful, but in a different way. Routine tracing is helpful to see stuff like order of events, what is actually called, timing, if program flow is as expected and performance profiling. Stack trace is not useful in these cases.

    Stack Trace, however, is very useful when you break on an error and wonder "OK, how did I get here???".
     
  5. Brian Robinson

    Brian Robinson Active Member Licensed User

    Ahh yes... sorry - didn't really read it well enough did I.

    Yes, both editions would be great...

    If you add as a wish, I will like.
     
  6. Reviewnow

    Reviewnow Active Member Licensed User

  7. JordiCP

    JordiCP Well-Known Member Licensed User

    A not-perfect but possible approach would be (did something similar some time ago but not for these purposes. There may be errors, this is not the exact code but just the idea)

    Replace any direct Sub call by xCallSub(module,procedureName)

    where xCallSub is
    Code:
    Sub xCallSub(Component as Object, procedurename as stringas Object
      
    Dim O as Object
    #if TRACING
       log("START:"...) 'DateTiime, procedure name,...
    #end if
       O=
    CallSub(Component, procedurename)
    #if TRACING
       log("EXIT"&.....) 'Datetime, .....
    #end if
      
    return O
    end sub
    And define TRACING depending on your build configuration (or, if you don't want this overhead, replace any "xCallSub" string in the project for "CallSub" again)

    You can also do it for CallSub2, CallSub3, CallSubDelayed...as needed

    Also, for events, they should be defined in the following way

    Code:
    Sub myButton_Click
      xCallSubDelayed(Me,
    "myButtonClickHandler")
    end sub

    Sub myButtonClickHandler
      
    ' process the event here
    end Sub

    Hope this helps
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice