ds34 Posted October 21, 2008 Share Posted October 21, 2008 (edited) 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 October 21, 2008 by ds34 Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 21, 2008 Share Posted October 21, 2008 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. Link to comment Share on other sites More sharing options...
martin Posted October 21, 2008 Share Posted October 21, 2008 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) endfuncEasiest 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. Link to comment Share on other sites More sharing options...
ds34 Posted October 22, 2008 Author Share Posted October 22, 2008 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... Link to comment Share on other sites More sharing options...
martin Posted October 22, 2008 Share Posted October 22, 2008 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. Link to comment Share on other sites More sharing options...
ds34 Posted October 22, 2008 Author Share Posted October 22, 2008 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,". Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 22, 2008 Share Posted October 22, 2008 I wonder if a stack trace would be a helpful thing to add to the AutoIt system. Link to comment Share on other sites More sharing options...
xwing1978 Posted March 3, 2009 Share Posted March 3, 2009 I agree, a built in stack trace would be helpful. Link to comment Share on other sites More sharing options...
exodius Posted March 3, 2009 Share Posted March 3, 2009 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? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now