The main steps for tracing function calls are given in inanimate node:
> dbg:start(). % start dbg > dbg:tracer(). % start a simple tracer process > dbg:tp(Module, Function, Arity, []). % specify MFA you are interested in > dbg:p(all, c). % trace calls (c) of that MFA for all processes. ... trace here > dbg:stop_clear(). % stop tracer and clear effect of tp and p calls.
You can track multiple functions at once. Add functions by calling tp for each function. If you want to track non-exported functions, you need to call tpl . To remove functions, call ctp or ctpl same way. Some common tp calls:
> dbg:tpl(Module, '_', []). % all calls in Module > dbg:tpl(Module, Function, '_', []). % all calls to Module:Function with any arity. > dbg:tpl(Module, Function, Arity, []). % all calls to Module:Function/Arity. > dbg:tpl(M, F, A, [{'_', [], [{return_trace}]}]). % same as before, but also show return value.
The final argument is the conformance specification. You can play with this using dbg:fun2ms .
You can select processes to track with p (). Elements are described in the erlang: trace section. Some challenges:
> dbg:p(all, c). % trace calls to selected functions by all functions > dbg:p(new, c). % trace calls by processes spawned from now on > dbg:p(Pid, c). % trace calls by given process > dbg:p(Pid, [c, m]). % trace calls and messages of a given process
I guess you will never need to call erlang:trace directly, since dbg does almost everything for you.
The golden rule for a live node is to generate only the amount of trace output into the shell, which allows you to enter dbg:stop_clear(). . :)
I often use a tracer that automatically stops after several events. For example:
dbg:tracer(process, {fun (_,100) -> dbg:stop_clear(); (Msg, N) -> io:format("~p~n", [Msg]), N+1 end, 0 }).
If you are looking for debugging on remote sites (or multiple sites), search for pan , eper , inviso or onviso .