erlang trace tutorial

mats cronqvist mats.cronqvist@REDACTED
Mon Oct 25 15:19:41 CEST 2004

Thomas Lindgren wrote:
> (It is also easy to generalize this to "trace system
> for N seconds" or whatnot.)
> You can do more as well, but I haven't gotten that far
> myself:
> - use match specifications
> - send trace messages to other destinations
> (ports/sockets, ...)

   thought i'd post what i use. background is that i wanted a trace  
facility that was less likely to choke the emulator that dbg is. i also  
had the most excellent constraint of not being allowed to use beam files  
or the compiler(*). Basically, i wanted something that wouldn't flood the  
shell with io, and that exited if things got difficult.
   solution was to spawn a process that ran a trace, collected messages for  
a while, but did not print anything until after the tracing finished. it  
will exit if it ever finds more than 100 messages in it's inbox.


(*) This is why the source code looks so wierd; one can take all the funs  
in rdbg/0, remove extra whitespace and get a oneliner that can be pasted  
into the shell... this has been dubbed the "ugliest line of code ever" by  
the Top Poster (ulf wiger).

   rdbg - restricted debugging utility


   An interface to the trace mechanism, safer (hopefully) than
   dbg. Disallows some of the more dangerous traces and exits if it
   gets flooded by trace messages. It runs in the background,
   collecting trace messages, until it reaches one of it's termination
   criteria (number of messages or maximum time). Prints the resulting
   trace messages like this;
[{Process, Timestamp, Data}...]
   Process is the registered name, if any, or else the initital call  
   Timestamp is {Hour, Minute, Second, Microsecond}

   Proc can be; the atom 'all', a registered name, a pid, or the tuple  
{pid,I1,I2} (which specifies the pid <0.I1.I2>).
   Trc can be; the atom 'send', the atom 'receive', or a list of restricted  
trace patterns (RTP).
   An RTP is a tuple {Module, Function, RMSs, LocalGlobal}
    where LocalGlobal is one of the atoms 'local' or 'global'. 'global'  
means that only fully qualified function
   calls (i.e. M:F()) are traced. Defaults to 'global'.
   RMSs is a list of restricted match specs (RMS). It defaults to [].
   An RMS can be; the atom 'stack', the atom 'return', or a description of  
the argument list. E.g. the list;
   would match is the arity of the called function is 3, the first argument  
is 1 and the third argument is 'x'.


** rdbg, 1 msgs **

** rdbg, 2 msgs **

** rdbg, 2 msgs **

(erl@REDACTED)1> erlang:now().
** rdbg, 2 msgs **
   {{stack,['shell:eval_loop/2 ']},

(erl@REDACTED)1> ets:tab2list(inet_db).
(erl@REDACTED)2> ets:tab2list(ac_tab).
** rdbg, 1 msgs **
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rdbg.erl
URL: <>

More information about the erlang-questions mailing list