Tool for see the call of procedures

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5500
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Tool for see the call of procedures

Post 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
ImageThe happiness is a road...
Not a destination
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: Tool for see the call of procedures

Post by Axolotl »

Have you tried Debugger | Callstack ?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5500
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Tool for see the call of procedures

Post 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)
ImageThe happiness is a road...
Not a destination
pjay
Enthusiast
Enthusiast
Posts: 277
Joined: Thu Mar 30, 2006 11:14 am

Re: Tool for see the call of procedures

Post 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()

boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Tool for see the call of procedures

Post 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.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5500
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Tool for see the call of procedures

Post 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)
ImageThe happiness is a road...
Not a destination
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Tool for see the call of procedures

Post 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
Last edited by boddhi on Sat Aug 03, 2024 9:42 am, edited 2 times in total.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: Tool for see the call of procedures

Post 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)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5500
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Tool for see the call of procedures

Post by Kwai chang caine »

Thanks a lot at you two, i take a look to your tips :wink:
ImageThe happiness is a road...
Not a destination
Post Reply