tracing
Serge Aleynikov
serge@REDACTED
Fri Sep 9 23:54:11 CEST 2005
True, but I thought there might be a more "light-weight" solution. Dbg
starts it's own process which in turn starts a process handling the
trace process function.
One way to get its internal state that I could think of would be to
store the trace in the trace process function's process dictionary, and do:
trace(F, M, Args) ->
% Set up a tracer
dbg:tracer(process, {fun(M,A) -> T=[M|A], put(trace, T), T end, []}),
dbg:p(self(), call),
dbg:tpl(dbg, [{'_',[],[{return_trace}]}]),
% Call the function
Res = apply(F, M, Args),
% Retrieve trace
{ok, Tracer} = dbg:get_tracer(),
Dict = process_info(Tracer, dictionary),
dbg:stop(),
case lists:keysearch(trace, 1, Dict) of
{value, {_, Val}} ->
{Res, format_trace(Val)};
false
{Res, undefined}
end.
Are there more elegant ways?
Serge
Brian Buchanan wrote:
> On Fri, 9 Sep 2005, Serge Aleynikov wrote:
>
>> When a tracing process is setup with dbg:tracer/2 it accepts a
>> function that can accumulate traces in a custom accumulator, such as
>> this:
>
>
> ...
>
>> Is there a way to retrieve the content of this accumulator before
>> calling dbg:stop()?
>
>
> Serge,
>
> Why not write a simple gen_server that abstracts this functionality?
> The trace fun would post messages to the server, which would record them
> as part of its internal state. The "stop trace" function would
> terminate the gen_server and return the collected trace results.
>
> - Brian
>
--
Serge Aleynikov
R&D Telecom, IDT Corp.
Tel: (973) 438-3436
Fax: (973) 438-1464
serge@REDACTED
More information about the erlang-questions
mailing list