Process message counter in process_info

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Process message counter in process_info

Max Lapshin-2

Looks that there is no possibility to ask process: how many messages has it received, no such counter.

Are there any problems with such counter? It maybe possible to sort processs by receive and send message rate with such counter.


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Process message counter in process_info

Stanislaw Klekot
On Thu, Sep 28, 2017 at 02:46:57PM +0300, Max Lapshin wrote:
> Looks that there is no possibility to ask process: how many messages has it
> received, no such counter.

You mean something like message_queue_len? There sure is.

#v+
1> erlang:process_info(self(), message_queue_len).
{message_queue_len,0}
2> self() ! foo.                                  
foo
3> self() ! bar.
bar
4> self() ! baz.
baz
5> erlang:process_info(self(), message_queue_len).
{message_queue_len,3}
6> receive M -> M end.
foo
7> erlang:process_info(self(), message_queue_len).
{message_queue_len,2}
#v-

--
Stanislaw Klekot
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Process message counter in process_info

Max Lapshin-2
No.

I mean:

process_info(self(), total_messages_received)
process_info(self(), total_messages_sent)


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Process message counter in process_info

Fred Hebert-2
Those don't exist by default as far as I can tell, but you can work around that for some processes using the sys module and gen_* debug attributes:

     sys:statistics(Pid, true | false) -> ok
     sys:statistics(Pid, get [, Timeout]) -> {ok, Stats}

It can be used interactively as:

1> sys:statistics(error_logger, true).
ok
2> sys:statistics(error_logger, get).
{ok,[{start_time,{{2017,9,28},{9,48,35}}},
     {current_time,{{2017,9,28},{9,48,37}}},
     {reductions,25},
     {messages_in,0},
     {messages_out,0}]}
3> error_logger:info_msg("test", []).
ok
4>
=INFO REPORT==== 28-Sep-2017::09:48:50 ===
5> sys:statistics(error_logger, get).
{ok,[{start_time,{{2017,9,28},{9,48,35}}},
     {current_time,{{2017,9,28},{9,48,52}}},
     {reductions,674},
     {messages_in,1},
     {messages_out,0}]}

You can also start the server as `gen_Whatever:start_link(Arg1, ..., [{debug, [statistics]}])' to enable the gathering from start time on the required processes.

I know of no other way to handle that kind of stuff at the moment.

On Thu, Sep 28, 2017 at 9:35 AM, Max Lapshin <[hidden email]> wrote:
No.

I mean:

process_info(self(), total_messages_received)
process_info(self(), total_messages_sent)


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Process message counter in process_info

Max Lapshin-2
Or make a patch to beam?

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions