Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

erlang - inspect mailbox messages once at a time

Tags:

erlang

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.

like image 940
hyperboreean Avatar asked Dec 28 '22 13:12

hyperboreean


2 Answers

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.

like image 133
Roberto Aloi Avatar answered Jan 07 '23 11:01

Roberto Aloi


or you can use:

1> F = fun() -> receive X -> {message, X} after 0 -> no_message end end.
#Fun<erl_eval.20.111823515>
2> F().
no_message
3> self() ! foo.
foo
4> self() ! bar.
bar
5> F().
{message, foo}
6> F().
{message, bar}

... to prevent blocking

like image 22
Gustavo Chaín Avatar answered Jan 07 '23 12:01

Gustavo Chaín