Switching Debug Info On and Off

Siri Hansen (EAB) <>
Tue Feb 18 17:05:27 CET 2003


Hello!

I think the solution to your problem is tracing. If you're running OTP
R9, you can use ttb (trace tool builder) in the observer
application. If you're using an earlier version of OTP you can use dbg
in the runtime_tools application.

Below is an example which I have used in a small system. It turns on
call tracing on all exported functions (debug()) or all exported and
internal functions (debugl()) in all modules specified in the list
?ALL_MY_MODULES. All trace ouput is written to the file
mylog.trc. This is a binary file which must be formatted. The ttb
version of the example autmatically formats the file when stop_debug()
is called.

The difference between ttb and dbg is that ttb has more support for
large systems, i.e. tracing of multiple nodes, collection of trace
logs when tracing stops... The logs will also contain process and node
names in addition to the pid if you use ttb. If using dbg you must
start tracing separatly on each node.

The example below uses the default handler when formatting the trace
log. You can use your own handler by adding the handler option to
ttb:tracer or by adding the HandlerSpec argument to dbg:trace_client. 

You can also reduce the amount of trace information by specifying
exactly which functions to trace. See the functions tp/3/4 and tpl/3/4
(exist in both ttb and dbg).

See documentation for observer or runtime_tools for further
details. You will also find more examples in the documentation.

When not running, tracing does not have any performance impact on your
system.

Kind regards
/siri

Example

Using ttb (observer):
---------------------------------
debug() -> debug(global). % global level, i.e. external function calls
debugl() -> debug(local). % local level, i.e. internal function calls
debug(Trace) ->
    ttb:tracer(all,[{file,"mylog.trc"}]), % tracing all nodes
    ttb:p(all,[call,timestamp]),
    MS = [{'_',[],[{return_trace},{message,{caller}}]}],
    tp(Trace,MS),
    ttb:ctp(?MODULE,stop_debug), % don't want tracing of the stop_debug func
    ok.
tp(local,MS) ->
    lists:foreach(fun(M) -> ttb:tpl(M,MS) end, ?ALL_MY_MODULES);
tp(global,MS) ->
    lists:foreach(fun(M) -> ttb:tp(M,MS) end, ?ALL_MY_MODULES).
stop_debug() ->
    ttb:stop([format]).



Using dbg (runtime_tools):
---------------------------------
debug() -> debug(global).
debugl() -> debug(local).
debug(Trace) ->
    dbg:tracer(port,dbg:trace_port(file,"mylog.trc")),
    dbg:p(all,[call,timestamp]),
    MS = [{'_',[],[{return_trace},{message,{caller}}]}],
    tp(Trace,MS),
    dbg:ctp(?MODULE,stop_debug), % don't want tracing of the stop_debug func
    ok.
tp(local,MS) ->
    lists:foreach(fun(M) -> dbg:tpl(M,MS) end, ?ALL_MY_MODULES);
tp(global,MS) ->
    lists:foreach(fun(M) -> dbg:tp(M,MS) end, ?ALL_MY_MODULES).
stop_debug() ->
    dbg:ctp('_'),
    dbg:stop().
format_debug() ->
    dbg:trace_client(file,"mylog.trc").




DANIESC SCHUTTE wrote:
> Greetings all,
> 
> today I would like te enquire about the most elegant way to switch debugging code on and off in an erlang runtime system.  Would this be possible without a complete re-compile of all applications, or would there be an easy solution - without a huge performace impact? Can this be done dynamically?
> 
> Regards
> 
> 
> Danie Schutte
> Phone: +27 - 11 - 203 - 1613
> Mobile: 084-468-3138
> e-Mail: 
> 
> #####################################################################################
> The information contained in this message and or attachments is intended
> only for the person or entity to which it is addressed and may contain
> confidential and/or privileged material.  Any review, retransmission,
> dissemination or other use of, or taking of any action in reliance upon,
> this information by persons or entities other than the intended recipient
> is prohibited. If you received this in error, please contact the sender and
> delete the material from any system and destroy and copies.
> #####################################################################################



More information about the erlang-questions mailing list