Cover by Francesco Cesarini, Simon Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Tracing Calls with the trace_pattern BIF

You use the erlang:trace_pattern/3 BIF to enable tracing of local and global function calls. You must use this BIF in conjunction with the erlang:trace/3 BIF, called with the call and return_to flags. Tracing will be enabled on the intersection of the sets created through the calls to the two trace BIFs (see Figure 17-3). Using trace/3, you define which processes you want to monitor. Using trace_pattern/3, you define the subset of functions you are tracing. An event will be generated only if a traced process executes a traced function.

The trace messages generated by the intersection of these two BIFs will be of the following form:

{trace, Pid, call, {M, F, Args}}
{trace, Pid, return_to, {M, F, Args}}

where call is generated when the function F in module M with argument Args is called. The return_to event is generated when the call returns and the execution of the function is completed. When tracing recursive calls, the return_to event is sent only when the recursive base case has been reached, and not for every iteration of the function. You can use the return_to flag only in conjunction with the call flag.

Using the arity flag in conjunction with the call flag, all event tags containing an {M, F, Args} tuple will instead return function arity information, {M, F, Arity}. This is useful if you are not interested in the arguments passed to a function and you want to minimize the size of the messages passed as a result of the call trace.

Figure 17-3. The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required