//
you're reading...
Erlang

Tracing Erlang Functions


Tracing Erlang functions for debugging purposes is probably simpler than you could even imagine. Let say you have the following module and you want trace one of its functions.


-module(math).
-export([sum/2, diff/2]).

sum(A, B) -> A + B.
diff(A, B) -> A - B.

Just start the tracer:
> dbg:tracer()

Say the tracer that you are interested in all calls for all processes:
> dbg:p(all, c)

Finally, say it that you want to trace the function sum from the module math:
> dbg:tpl(math, sum, [])

Now, try to call the function, as usual. The tracer is active!
> math:sum(2, 3).

To stop the trace:
> dbg:stop().

To trace all the functions within the module math:
> dbg:tpl(math, [])

To trace the return value for a given function:
> dbg:tpl(math, sum, dbg:fun2ms(fun(_) -> return_trace() end)).

For more information, refer to the official documentation of the Erlang dbg module.

About these ads

About Roberto Aloi

Software Engineer and Erlanger. Author of www.tryerlang.org.

Discussion

One thought on “Tracing Erlang Functions

  1. Terrific, just the kind of quick reference I was looking for. Thank you! :)

    Posted by Anton | February 4, 2010, 7:31 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: