[erlang-questions] erlang:trace/3
Björn-Egil Dahlberg
egil@REDACTED
Tue Apr 10 14:46:52 CEST 2012
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
More information about the erlang-questions
mailing list