Reputation: 215
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.
Upvotes: 0
Views: 362
Reputation: 4906
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.
Upvotes: 1