Jump to content
Sign in to follow this  
ds34

Function called by whom?

Recommended Posts

ds34

I have a procedure (to generate debug output) that is called about 10000 times in the script...

Since meanwhile the output is way too much I would like to limit the amount of messages printed WITHOUT needing to touch each call triggering the function but restricting it inside of the function.

So it would be really usefull, if a function could by itself determine, which function was calling it...

Is there something built in - would save my day ;-)

thanks,

Daniel

My script looks like

global $env_Debug="on"

 func Debugtrace($string="")
 if $env_Debug="on" then write to logfile (timestamp&some_environment_condition&string)
 endfunc

and everywhere else in the script it called

Debugtrace("blabla")

So I would like to change to something like below, then it is only acting when called by functiona but not when called from functionc

global $env_Debug="functiona_functionb_function10002

 func Debugtrace($string="")
 $called_from=??????
 if stringinstr($env_Debug,$called_from) then write to logfile (timestamp&some_environment_condition&string)
 endfunc
Edited by ds34

Share this post


Link to post
Share on other sites
Richard Robertson

That would require some sort of function stack access. Either the devs would have to provide this or you would have to write something yourself, such as declare a stack(obviously more coding involved) and push the current function every time a function is called. Then you would have to pop the function when it ends.

Share this post


Link to post
Share on other sites
martin

I have a procedure (to generate debug output) that is called about 10000 times in the script...

Since meanwhile the output is way too much I would like to limit the amount of messages printed WITHOUT needing to touch each call triggering the function but restricting it inside of the function.

So it would be really usefull, if a function could by itself determine, which function was calling it...

Is there something built in - would save my day ;-)

thanks,

Daniel

My script looks like

global $env_Debug="on"

 func Debugtrace($string="")
 if $env_Debug="on" then write to logfile (timestamp&some_environment_condition&string)
 endfunc

and everywhere else in the script it called

Debugtrace("blabla")

So I would like to change to something like below, then it is only acting when called by functiona but not when called from functionc

global $env_Debug="functiona_functionb_function10002

 func Debugtrace($string="")
 $called_from=??????
 if stringinstr($env_Debug,$called_from) then write to logfile (timestamp&some_environment_condition&string)
 endfunc
Easiest way is to just have an extra parameter in your function., or have a global value that is set at the first line in each function.

Global $funcname = ''

.
.
Func FnOne()
$funcname = "FnOne"
..
.
.
DebugTrace("something")
Endfunc

Or

Func FnOne()
;blah
;blah
DebugTrace("something","FnOne")
etc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
ds34

Thanks for thinking about this,

I also thought about declaring a global variable, to be sets upon every function entry.

This would require as well that the function itself, resets the variable before exiting to the previosly set vale (in case func a calls func b wich calls func c)...

In principle doable with a setting it directly after the "func" and reset before the "endfunc" statements, but I will need to set it es well before each and every Return or Exit statement - much work as well.

Since the project is too big already I consider this still too much effort...

Share this post


Link to post
Share on other sites
martin

Thanks for thinking about this,

I also thought about declaring a global variable, to be sets upon every function entry.

This would require as well that the function itself, resets the variable before exiting to the previosly set vale (in case func a calls func b wich calls func c)...

In principle doable with a setting it directly after the "func" and reset before the "endfunc" statements, but I will need to set it es well before each and every Return or Exit statement - much work as well.

Since the project is too big already I consider this still too much effort...

Yes you're right , a global variable would not be a good idea. So you would need to add a local variable to each function and pass that to the debug function.

The effort required is minimal. One line in your debug function. Then a script of about 10 lines I would guess to read your script and add the line "Local $inFunction = "thisFunction" after each function header. That way each function has it's own variable which is its own name.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
ds34

Yes you're right , a global variable would not be a good idea. So you would need to add a local variable to each function and pass that to the debug function.

The effort required is minimal. One line in your debug function. Then a script of about 10 lines I would guess to read your script and add the line "Local $inFunction = "thisFunction" after each function header. That way each function has it's own variable which is its own name.

Thanks, that's the key, a local variable with the same name in each function (set directly after the function header) and a "find all and replace" of each DebugTrace function call: "DebugTrace(" to "DebugTrace($inFunction,".

Share this post


Link to post
Share on other sites
Richard Robertson

I wonder if a stack trace would be a helpful thing to add to the AutoIt system.

Share this post


Link to post
Share on other sites
xwing1978

I agree, a built in stack trace would be helpful.

Share this post


Link to post
Share on other sites
exodius

So would using the "Trace: Add Func Trace Lines" option in SciTE and then running your script in SciTE not illuminate what the last function to call your debug function was?

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  

×