[erlang-questions] erlang:trace/3

Emilio De Camargo Francesquini <>
Fri Apr 13 08:58:59 CEST 2012


I added the 'exiting' flag to all/0 and ran some tests. It worked perfectly.


Le 12 avril 2012 23:20, Björn-Egil Dahlberg
<> a écrit :
>
>
> Den 12 april 2012 19:39 skrev Emilio De Camargo Francesquini
> <>:
>
>> Hello again,
>>
>> I was playing around with dbg:p/2 and I realized that it does not
>> accept the flag 'exiting'. I browsed the code a little bit and found
>> out that it accepts only the flags declared in dbg:all/0. Here's the
>> code:
>>
>> all() ->
>>    [send,'receive',call,procs,garbage_collection,running,
>>     set_on_spawn,set_on_first_spawn,set_on_link,set_on_first_link,
>>     timestamp,arity,return_to].
>>
>> I took a brief look at the documentation, and found that "The list can
>> also include any of the flags allowed in erlang:trace/3".
>>
>> Is this a bug or a deliberate decision?
>
>
> I am not so sure that this is a deliberate decision .. in fact a believe the
> opposite.
>
> If I recall correctly, the 'exiting' option is newer tracing option (though
> it apparently older than R13B03). I think it was added when some process
> termination internals got rewritten. dbg were probably overlooked when
> implementing it.
>
> Does it work as intended for you if you add 'exiting' to all/0 in this case?
>
> // Björn-Egil
>>
>>
>> Thanks!
>>
>>
>> Le 10 avril 2012 14:46, Björn-Egil Dahlberg <> a écrit :
>> > On 2012-04-09 19:49, Emilio De Camargo Francesquini wrote:
>> >>
>> >> Hello,
>> >>
>> >> I'm having some trouble understanding the exact meaning of two of the
>> >> flags for the erlang:trace/3 function.
>> >>
>> >> Flag:
>> >>
>> >> - running
>> >>     Trace scheduling of processes.
>> >>     Message tags: in, and out.
>> >>
>> >> I imagine that a message tagged "in" means that the process was chosen
>> >> by a scheduler and will begin/resume execution and a tag "out" means
>> >> that the processes has been preempted. Is that correct?
>> >
>> > Correct but, to be clear, not only preempted. The tag "out" will be sent
>> > if
>> > the process is scheduled out for any reason.
>> >
>> >> - exiting
>> >>     Trace scheduling of an exiting processes.
>> >>     Message tags: in_exiting, out_exiting, and out_exited.
>> >>
>> >> I guess that these messages are sent when the proccess is about to
>> >> exit or has already exited. Am I right? What is the exact difference
>> >> between each one of them?
>> >
>> > With "in_exiting" and "out_exiting" the process is scheduled as normal
>> > but
>> > it is in limbo. This means the process is dead but has to be scheduled
>> > in
>> > order to terminate and cleanup internally in the runtime. In other
>> > words, it
>> > will not execute beam-code any more just terminate. Why? It simplifies
>> > things internally.
>> >
>> >> Moreover, what is the difference between "exiting" flag with the tag
>> >> "out_exited" and "procs" flag with the tag "exit"?
>> >
>> > The tag "exit" from procs is sent when the process is deemed dead, i.e.
>> > it
>> > is exiting. The last chunk of beam code the process executed was some
>> > form
>> > of exit.  At this moment in time process has the state EXITING but will
>> > potentially be scheduled again.
>> >
>> > The trace will after this be out_exited or, if more has to be done to
>> > terminate it, out_exiting and in_exiting. Ex:
>> >
>> >
>> > Eshell V5.9  (abort with ^G)
>> > 1> P = spawn(fun() -> receive Ok -> ok end end).
>> > <0.34.0>
>> > 2> erlang:trace(P, true, [running, procs, exiting]).
>> > 1
>> > 3> P ! ok.
>> > ok
>> > 4> flush().
>> > Shell got {trace,<0.34.0>,in,{erl_eval,receive_clauses,6}}
>> > Shell got {trace,<0.34.0>,exit,normal}
>> > Shell got {trace,<0.34.0>,out_exited,0}
>> > ok
>> >
>> > I hope this clarifies things.
>> >
>> > Regards,
>> > Björn-Egil
>> > Erlang/OTP
>> > _______________________________________________
>> > erlang-questions mailing list
>> > 
>> > http://erlang.org/mailman/listinfo/erlang-questions
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>
>



More information about the erlang-questions mailing list