Cover by Francesco Cesarini, Simon Thompson

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

The Trace BIFs

The built-in function erlang:trace/3 enables and disables the low-level trace mechanisms in the Erlang runtime system. It provides you with a means to monitor concurrency, code execution, and memory usage. Tools such as the debugger and the process manager use this BIF to collect and display trace events. You prefix the BIF with the name of the erlang module that contains it, as it is not autoimported.

The beauty of the trace BIF is that you can use it without having to trace-compile the code. You can use it in live systems, resulting in an incredibly powerful troubleshooting tool that gives full visibility of what is going on.

Trace events are sent as messages of the following format:

{trace, Pid, Tag, Data1 [,Data2]}

where [,Data2] denotes an optional field dependent on the trace message type. Trace events that are generated include the following:

  • Global and local function calls

  • Garbage collection and memory usage

  • Process-related activities and message passing

At any one time, only one process may receive trace events from another process. This is known as the tracer process. The tracer process that receives the trace events is the one that made the call to:

erlang:trace(PidSpec, Bool, TraceFlags).

In this call, PidSpec defines which processes you want to trace. It is either a process identifier or one of the atoms existing, new, or all:

  • The existing atom enables tracing for all existing processes, but will exclude the tracer process and any process spawned after the call. ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required