[erlang-questions] Erlang tracing

Loïc Hoguin essen@REDACTED
Mon Sep 21 13:54:53 CEST 2015

On 09/21/2015 01:46 PM, Lukas Larsson wrote:
> Hello,
> On Mon, Sep 21, 2015 at 12:02 PM, Ulf Wiger <ulf@REDACTED
> <mailto:ulf@REDACTED>> wrote:
>     I have had some success using an event/[2,3] function for
>     lightweight debugging, where the functions event(Line, Event) and
>     event(Line Event, State) exist only to be traced. A simple way to
>     generalize this would be to create ‘null’ BIFs:
>     erlang:trace_event(Info, Event) -> ok, erlang:trace_event(Info,
>     Event, State) -> ok (just a trace_event/1 would of course suffice).
>     If not traced, these functions do nothing; when traced, they emit
>     trace info similar to io:format debugging.
>     See e.g. the locks application:
>     https://github.com/uwiger/locks/blob/master/src/locks_leader.erl#L140
>     https://github.com/uwiger/locks/blob/master/src/locks_leader.erl#L823
> So it should be possible define your own trace probes (for lack of a
> better word) in erlang code? That is a very good point. For dtrace we
> have the dyntrace module that you can put calls to with very little
> overhead. Maybe something similar can be done for Erlang tracing? I
> don't think we should step on the toes of logging though, as those (in
> my opinion) should be two different things.

I would quickly add dyntrace calls all over my projects if it didn't 
require me to have a dtrace/systemtap/.. enabled kernel to use it (and 
most importantly, confirm that it works).

>     I’ve found this extremely useful not least when enabled during
>     multi-node test suite execution, using ttb to merge logs and a final
>     pretty-printing step to produce a text log best viewed with emacs's
>     Erlang syntax highlighting. See
>     https://github.com/uwiger/locks/blob/master/src/locks_ttb.erl (Logs
>     fetched only if test case fails).
> I had completely forgot about the ttb. Will have to read up on what you
> can do with it.

It would be great to at least be able to use the ttb at the same time as 
dbg. I ran into this in the past, though I can't recall exactly what my 
issue was.

ttb also needs some love with regard to documentation. It's probably 
worse than dbg, and I would bet that much fewer people know about it.

Loïc Hoguin
Author of The Erlanger Playbook,
A book about software development using Erlang

More information about the erlang-questions mailing list