0

I would like to trace all behavior of Erlang GC using dbg:tracer and print out the tracked events.

1> dbg:tracer().
2> dbg:p(self(), [garbage_collection]).
3> my_module:function([Args]).
4> dbg:stop().
5> dbg:show_trace().
...

I would like to only trace garbage collection during the execution of my_module:function/0 function call. Once the function has returned tracing should stop.

Stratus3D
  • 4,648
  • 4
  • 35
  • 67
fvarj
  • 205
  • 1
  • 3
  • 9
  • Can you explain the problem with the commands you have shown? Does nothing get printed? Also which version of Erlang are you using? – Stratus3D Dec 07 '16 at 16:45
  • I know that I can trace Erlang GC using line 2, but actually I want trace the GC behavior during the execution of line 3. How can I do this ? The second question is after stop the trace process (line 4, how can I print out the data tracked ? – fvarj Dec 07 '16 at 18:30
  • fvarj let me know if my answer fixes your issue. – Stratus3D Dec 07 '16 at 19:23
  • @Stratus3D Thank you for all help, it works o/ – fvarj Dec 08 '16 at 18:32

1 Answers1

1

There may be a better way of doing this, but I would suggest turning off tracing as soon as the function you care about has returned. Something like this should work:

1> dbg:tracer().
2> GcOfMyModule = fun() ->
    dbg:p(self(), [garbage_collection]),
    my_module:function([Args]),
    dbg:stop()
end
3> GcOfMyModule().
5> dbg:show_trace().

Wrapping the dbg:p/2, my_module:function/1, and dbg:stop/0 calls all in one function will mean each function will be executed immediately after the function before it. I got idea originally from the last part of this answer where it takes about automatically stopping a trace after a certain number of events https://stackoverflow.com/a/1954980/1245380.

Community
  • 1
  • 1
Stratus3D
  • 4,648
  • 4
  • 35
  • 67