Page 1 of 1

Tool for see the call of procedures

Posted: Thu Aug 01, 2024 3:45 pm
by Kwai chang caine
Hello at all

Exist it a tool in PB, who show the list of procedures called and the order where she are called ?

Have a good day

Re: Tool for see the call of procedures

Posted: Thu Aug 01, 2024 4:08 pm
by Axolotl
Have you tried Debugger | Callstack ?

Re: Tool for see the call of procedures

Posted: Thu Aug 01, 2024 8:38 pm
by Kwai chang caine
Hello Axolotl :D

Yes, i have try the tool CallStacks but not really understand :oops:
Image


That only show some lines :|

Me... i search instead something who write this style of lines :
KCC imaginary CallStack wrote:
Start => one()
One() => Two()
Two() => Tree()
for this code

Code: Select all

Procedure Three()
 Debug "Hello"
EndProcedure

Procedure Two()
 Three()
EndProcedure

Procedure one()
 
 Two()
 
EndProcedure

one()

Repeat : Delay(1) :Until GetAsyncKeyState_(#VK_ESCAPE)

Re: Tool for see the call of procedures

Posted: Thu Aug 01, 2024 9:44 pm
by pjay
You could try something like this...

Code: Select all

;/ simple procedure profiling - PJ

#ProcProfile = #True
Global NewMap P_CallCount.i()
Global NewList P_Sequence.s()

Macro ProcProfileBegin
  CompilerIf #ProcProfile = #True
    P_CallCount(#PB_Compiler_Procedure) + 1
    AddElement(P_Sequence()) : P_Sequence() = #PB_Compiler_Procedure
  CompilerEndIf
EndMacro

Procedure Three() : ProcProfileBegin
 ;Debug "Hello"
EndProcedure

Procedure Two() : ProcProfileBegin
 Three()
EndProcedure

Procedure One() : ProcProfileBegin
 Two()
EndProcedure

One()

OpenConsole()
; output results:
ForEach P_Sequence()
  PrintN( "Procedure Call #"+Str(ListIndex(P_Sequence())+1)+": "+P_Sequence()+"()")
Next
PrintN("")
ForEach P_CallCount()
  PrintN("Called "+MapKey(P_CallCount())+"() "+P_CallCount()+" time(s).")
Next
PrintN("") : PrintN("Finished")
Input()


Re: Tool for see the call of procedures

Posted: Thu Aug 01, 2024 10:42 pm
by boddhi
Salut KCC,

I usually put after each Procedure X() a:

Code: Select all

Debug #PB_Compiler_Procedure+"(Here, with possibly detail of parameter values)",99 ; 99 to show/hide them with DebugLevel
So, I can see the flow of procedure calls in debugging window.

Re: Tool for see the call of procedures

Posted: Fri Aug 02, 2024 3:36 pm
by Kwai chang caine
Hello at you two :D

Thanks a lot for your two tips 8)
Apparently we are forced to modify the original code for put the "Flags" :|
Even if with the IDE "Replace" function that can be more easier, if the code is very big with several includefile, that can be a little bit fastidious :|
I'm surprising, because i thought FRED had planned this kind of useful tool in his splendid program :shock:

Especially since I believe that the precompiler is responsible for tracing the entire path that the program will take before each compilation, if I am not mistaken, which is exactly what I am trying to know. :wink:

Again thanks for your answers, i wish you a good day at you two 8)

Re: Tool for see the call of procedures

Posted: Sat Aug 03, 2024 2:58 am
by boddhi
Salut KCC,

If needed, a very old dirty code to add "Debug #PB_Compiler_Debug" in codes.
It is intended for use as a PB-tool IDE and certainly needs to be improved.

Code: Select all

EnableExplicit

Define.s FichierSource,FichierCible,Chaine,ChaineDebug="Debug #PB_Compiler_Procedure"
Define.b Proc
If CountProgramParameters()<>2
  End
EndIf
FichierSource=ProgramParameter()
FichierCible=ProgramParameter()
If ReadFile(0,FichierSource,#PB_File_SharedRead)=0
  End
EndIf
If CreateFile(1,FichierCible)=0
  End
EndIf
While Not Eof(0)
  Chaine=ReadString(0)
  While Right(Chaine,1)=Chr(32) Or Right(Chaine,1)=Chr(9)
    Chaine=Left(Chaine,Len(Chaine)-1)
  Wend
  If (LCase(Left(Trim(ReplaceString(Chaine,Chr(9),"")),9))="procedure" Or LCase(Left(Trim(ReplaceString(Chaine,Chr(9),"")),12))="proceduredll" Or LCase(Left(Trim(ReplaceString(Chaine,Chr(9),"")),17))="runtime procedure") And LCase(Left(Trim(ReplaceString(Chaine,Chr(9),"")),15))<>"procedurereturn"
    Proc=#True
  Else
    If Proc And LCase(Left(Trim(ReplaceString(Chaine,Chr(9),"")),28))<>LCase(ChaineDebug)
      Chaine=Chr(9)+ChaineDebug+"+"+Chr(34)+"()"+Chr(34)+Chr(10)+Chaine
    EndIf
    Proc=#False
  EndIf
  WriteStringN(1,Chaine)
Wend
CloseFile(0)
CloseFile(1)
 
EDIT : As you probably noticed, I wanted to write #PB_Compiler_Procedure instead of #PB_Compiler_Debug. :oops: :mrgreen:
EDIT 2: Sorry, I forgot to give the tool's config:
Image

Re: Tool for see the call of procedures

Posted: Sat Aug 03, 2024 6:35 am
by AZJIO

Code: Select all

Global order
Macro order(i)
	order+1
EndMacro

Procedure Three()
	order(i)
	Debug Str(order) + " => Three()"
	Debug "Hello"
EndProcedure

Procedure Two()
	order(i)
	Debug Str(order) + " => Two()"
	Three()
EndProcedure

Procedure one()
	order(i)
	Debug Str(order) + " => one()"
	Two()
	
EndProcedure

one()

Repeat : Delay(1) :Until GetAsyncKeyState_(#VK_ESCAPE)
Leave the macro empty when the information is no longer needed

If you need to insert this into someone else's code, then use a regular expression
Find:

Code: Select all

(?mi)^(\h*(?:Procedure[CDL$]{0,5}?(?:\h*\.[abcdfilqsuw])?\h+\K)[A-Za-z_]\w*\h*\(.+)\r?$
Replace:

Code: Select all

\1\r\n\torder(i)

Re: Tool for see the call of procedures

Posted: Mon Aug 05, 2024 12:45 pm
by Kwai chang caine
Thanks a lot at you two, i take a look to your tips :wink: