tags:

views:

60

answers:

2

I am trying to inspect the messages a node receives from other nodes, but in some other manner other than flush(), because the message size is rather big and it doesn't help. Also, I can see the messages with erlang:process_info(self(), messages_queue_len)., but I would like some way of extracting one message at a time in some kind of variable for debugging purposes.

+1  A: 

receive is the erlang primitive for taking messages from the mailbox.

See: http://www.erlang.org/doc/getting_started/conc_prog.html#id2263965

If you just want to get the first message in the shell for debugging, you could try defining a fun like this:

1> self() ! foo.
foo
2> F = fun() -> receive X -> X end end.
#Fun<erl_eval.20.67289768>
3> F().
foo
cthulahoops
+2  A: 

You might want to have a look to the dbg module in Erlang.

Start the tracer:

dbg:tracer().

Trace all messages received (r) by a process (in this case self()):

dbg:p(self(), r).

More information here.

Roberto Aloi
Good info, thanks!
hyperboreean