Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The basic steps of tracing for function calls are on a non-live node:</p> <pre><code>&gt; dbg:start(). % start dbg &gt; dbg:tracer(). % start a simple tracer process &gt; dbg:tp(Module, Function, Arity, []). % specify MFA you are interested in &gt; dbg:p(all, c). % trace calls (c) of that MFA for all processes. ... trace here &gt; dbg:stop_clear(). % stop tracer and clear effect of tp and p calls. </code></pre> <p>You can trace for multiple functions at the same time. Add functions by calling <code>tp</code> for each function. If you want to trace for non-exported functions, you need to call <code>tpl</code>. To remove functions, call <code>ctp</code> or <code>ctpl</code> in a similar manner. Some general tp calls are:</p> <pre><code>&gt; dbg:tpl(Module, '_', []). % all calls in Module &gt; dbg:tpl(Module, Function, '_', []). % all calls to Module:Function with any arity. &gt; dbg:tpl(Module, Function, Arity, []). % all calls to Module:Function/Arity. &gt; dbg:tpl(M, F, A, [{'_', [], [{return_trace}]}]). % same as before, but also show return value. </code></pre> <p>The last argument is a match specification. You can play around with that by using <code>dbg:fun2ms</code>.</p> <p>You can select the processes to trace on with the call to p(). The items are described under erlang:trace. Some calls are:</p> <pre><code>&gt; dbg:p(all, c). % trace calls to selected functions by all functions &gt; dbg:p(new, c). % trace calls by processes spawned from now on &gt; dbg:p(Pid, c). % trace calls by given process &gt; dbg:p(Pid, [c, m]). % trace calls and messages of a given process </code></pre> <p>I guess you will never need to directly call <code>erlang:trace</code>, as <code>dbg</code> does pretty much everything for you.</p> <p>A golden rule for a live node is to generate only an amount of trace output to the shell, which lets you to type in <code>dbg:stop_clear().</code>. :)</p> <p>I often use a tracer that will auto-stop itself after a number of events. For example:</p> <pre><code>dbg:tracer(process, {fun (_,100) -&gt; dbg:stop_clear(); (Msg, N) -&gt; io:format("~p~n", [Msg]), N+1 end, 0 }). </code></pre> <p>If you are looking for debugging on remote nodes (or multiple nodes), search for <code>pan</code>, <code>eper</code>, <code>inviso</code> or <code>onviso</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload