erlang memory leak check

Excessive memory usage recent project, check erlang memory usage.

1. can be easily obtained by etop case erlang memory usage

spawn(fun() -> etop:start([{output, text}, {interval, 5}, {lines, 20}, {sort, memory}]) end).

Can define the display time, number of rows, the size of the memory used in accordance with the arrangement.

2. Generally etop work can be very stable, but in individual extreme cases, etop will not use. In this case, only the command:

RawList = [{Pid, element(2, erlang:process_info (Pid, memory))} ||  Pid <- processes ()].
SortList = lists:reverse(lists:keysort(2, RawList)).
rp(lists:sublist(SortList, 20)).

The above two methods can identify the most memory-intensive process 20.

Then we can find out the memory of memory.

Pid is assumed that a memory <0.928.0> using the shell terminal rp () to print all of the information.

rp(erlang:process_info(pid(0, 928, 0))).

If the process information is relatively large, direct output to a file:

file:write_file("process_info.txt", [io_lib:format("~p", [erlang:process_info(pid(0, 928, 0))])]).

Note: Write file above, if the process uses too much memory, will lead to the collapse of the project on-line, with caution.

The above process can get into the process of dictionary information, but the information is not state of the process here.

Get process status information:

rp(erlang:process_info(pid(0, 928, 0), backtrace)).

Current information status above this method small footprint, you can quickly locate the process, it is recommended to use the first time.  

Reproduced in: https: //my.oschina.net/u/191928/blog/618623

Guess you like

Origin blog.csdn.net/weixin_34208185/article/details/91986983