[Erlang 0012] Erlang process input queue we mentioned the use of Erlang: process_info/1 to capture the status information of processes at runtime. Sometimes we need to capture the information of all processes in the node, it is easy to analyze the running status of processes in the entire node, especially picking out some abnormal processes. For example, if the operation value of some processes is several orders of magnitude larger than that of other processes, you need to check the process.
The following code traverses all processes in the current node and writes the Process status to the text:
Process_infos ()-> filelib: ensure_dir (". /log/"), file = ". /log/processes_infos.log ", {OK, FD} = file: open (file, [write, raw, binary, append]), fun = fun (PI) -> info = io_lib: Format ("=> ~ P \ n ", [Pi]), Case filelib: is_file (File) of true-> file: Write (FD, Info); false-> file: close (FD), {OK, newfd} = file: open (file, [write, raw, binary, append]), file: Write (newfd, Info) End, Timer: sleep (20) End, [fun (Erlang: process_info (p) | P <-Erlang: Processes ()]. run the command to read the data: [{registered_name, Rex },
{Current_function, {gen_server, loop, 6 }},
{Initial_call, {proc_lib, init_p, 5 }},
{Status, waiting },
{Message_queue_len, 0 },
{Messages, []},
{Links, [<0.10.0>]},
{Dictionary, [{'$ ancestors', [kernel_sup, <0.9.0>]},
{'$ Initial_call', {RPC, init, 1}]},
{Trap_exit, true },
{Error_handler, error_handler },
{Priority, normal },
{Group_leader, <0.8.0> },
{Total_heap_size, 28657 },
{Heap_size, 10946 },
{Stack_size, 9 },
{Functions, 13905 },
{Garbage_collection, [{min_bin_vheap_size, 10946 },
{Min_heap_size, 10946 },
{Fullsweep_after, 65535 },
{Minor_gcs, 2}]}. The garbage collection method of % Erlang is Mark sweep. Major performs full GC. When minor is not enough memory, it will be reclaimed if it is insufficient.
{Suspending, []}] meanings of these fields:
-
{Current_function, {module, function, argS }}
-
Method M f a called by the current process
-
{Dictionary, Dictionary}
-
Process Dictionary data of the current process. Some special tags can be added to the process during debugging to identify the process.
-
{Garbage_collection, gcinfo}
-
Gcinfo is a list which contains miscellaneous information about garbage collection for this process. The content of gcinfo may be changed without prior notice.
-
{Group_leader, groupleader}
-
Groupleader determines where the final information is output. For example, RPC collects the remote execution result and displays it in the current shell. This groupleader is used.
-
{Heap_size, size}
-
Size is the size in words of youngest heap generation of the process. This generation currently include the stack of the process. This information is highly implementation dependent, and may change if the implementation change.
-
{Initial_call, {module, function, Arity }}
-
Module, function, Arity is the initial function call with which the process was spawned.
-
{Links, PIDs}
-
List of associated processes
-
{Last_cils, false | CILS}
-
The value is false if call saving is not active for the process (see process_flag/3 ). if call saving is active, a list is returned, in which the last element is the most recent called.
-
{Memory, size}
-
Size is the size in bytes of the process. This includes des call stack, heap and internal structures.
-
{Message_binary, bininfo}
-
Bininfo is a list containing miscellaneous information about binaries currently being referred to by the message area. this infotuple is only valid on an emulator using the hybrid heap type. this infotuple may be changed or removed without prior notice.
-
{Message_queue_len, messagequeuelen}
-
This is the length of the Message Queue that we pay special attention to above.
-
{Messages, messagequeue}
-
Stacked message list
-
{Min_heap_size, minheapsize}
-
Minimum heap size
-
{Min_bin_vheap_size, minbinvheapsize}
-
Minimum binary virtual heap size of a process
-
{Monitored_by, PIDs}
-
List of monitored processes of the current process
-
{Priority, level}
-
Process Priority, set through process_flag (priority, level ).
-
{Functions, number}
-
This parameter is a rough Evaluation Indicator of the process load. It is abbreviated as reds.
Operation is an approximate measure of how much CPU time they have used.
This is a count. It is a basis for the Erlang Virtual Machine to schedule processes and ensure fair scheduling.
For example, if a process executes a function, the function will increase and the execution of GC function will decrease.
Replied to February 1, April 13 by litaocheng
-
{Registered_name, Atom}
-
Name of the process registration.
-
{Stack_size, size}
-
Process stack size (unit: Word)
-
{Status, status}
-
Process status, including exiting, garbage_collecting, waiting (for a message), running, runnable (ready to run, but another process is running), or suincluded
-
{Total_heap_size, size}
-
Size is the total size in words of all heap fragments of the process. This currently include the stack of the process.
-
{Trap_exit, Boolean}
-
System process or not
See http://www.erlang.org/doc/man/erlang.html#process_info-2 for details
How much memory does a single Erlang process occupy?
An Erlang process is lightweight compared to operating systems threads and processes.
A newly spawned Erlang process uses 309 words of memory in the non-SMP emulator without hipe support. (SMP support and hipe support will both add to this size .) the size can be found out like this:
Erlang (BEAM) emulator version 5.6 [async-threads:0] [kernel-poll:false]Eshell V5.6 (abort with ^G)1> Fun = fun() -> receive after infinity -> ok end end.#Fun<...>2> {_,Bytes} = process_info(spawn(Fun), memory).{memory,1232}3> Bytes div erlang:system_info(wordsize).309
The size limit des 233 words for the heap area (which has des the stack). The Garbage Collector will increase the heap as needed.
Link: http://www.erlang.org/doc/efficiency_guide/processes.html