Android Question Is Sub Routine tracing possible?

Robert Valentino

Well-Known Member
Licensed User
Longtime 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
 

Troberg

Well-Known Member
Licensed User
Longtime 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:
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime 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???".
 
Upvote 0

Brian Robinson

Active Member
Licensed User
Longtime 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.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime 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
B4X:
Sub xCallSub(Component as Object, procedurename as string) as 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

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

Sub myButtonClickHandler
  ' process the event here
end Sub


Hope this helps
 
Upvote 0
Top