When you enable tracing with
dbg:tracer().
dbg:p(all, c).
dbg:tp({queue, in, '_'}, []).
you end up flooding the tracer with an (almost) unlimited stream of trace messages. Usually this hangs your session (or floods your mailbox) because every call to queue:in/1 is being traced. The solution is to limit the number of events that are delivered – there are essentially two common approaches:
1. Limit the Trace by Using a Count in the Match Spec
You can modify your trace pattern so that it automatically removes itself after a fixed number of matches. One way to do this is to use a match specification that includes a count (often done with the {return_trace, Limit} option). For example, to stop after 10 events, you can do:
dbg:tracer().
dbg:p(all, [c]).
dbg:tpl(queue, in, '_', [{return_trace,10}]).
Here, instead of using dbg:tp/2, we use dbg:tpl/4 which lets you specify a count (in this case, 10). Once 10 trace events have been delivered, the trace pattern is automatically removed.
2. Restrict the Set of Processes Being Traced
Often it isn’t necessary to trace all processes. Instead of
dbg:p(all, c).
you can attach the trace only to specific processes of interest. This not only limits the number of trace messages but also reduces overhead. For instance, if you know the PID (or how to find it) for the process that uses queue:in/1, you can attach only to that process:
dbg:tracer().
dbg:p(PidOfInterest, [c]).
dbg:tpl(queue, in, '_', [{return_trace,10}]).
Adjust PidOfInterest as needed.
Why the Hang?
The hang you observed is due to the tracer process being overwhelmed:
- With no limit on the number of messages, its mailbox grows without bound.
- The tracing calls (in the traced code) block when the tracer isn’t keeping up.
By limiting either via a count on the trace pattern or by reducing the number of processes that emit traces, you avoid this overload.
Summary
To fix the hang and have only a limited number of messages, change your trace call to something like:
dbg:tracer().
dbg:p(all, [c]).
dbg:tpl(queue, in, '_', [{return_trace,10}]).
This sets up a tracer that will stop tracing after 10 messages for queue:in/1.
Feel free to adjust the trace count or the process selection as suited for your debugging needs.