Erlang提供了豐富的開發工具,你認爲沒有的時候,很可能是你不知道它存在.
在OS中,我們經常查看操作系統的進程信息,幫助我們進行診斷。
Erlang提供了一個小工具 etop (Erlang top), 用來查看Erlang運行環境中,內存,ets,binary,進程等相關信息。
這些被收集的信息大部分是通過erlang module的相關bif輸出,etop只是做了一個好的展現。
etop位於: erlang/lib/observer-xxx/priv/bin 目錄下, etop爲CLI,getop爲GUI表現,在windows下也可以通過調用etop.bat和getop.bat顯示相關信息.
下面是用法:
./etop Args
Args:
node
- 被監控的Node
- Value: atom()
Mandatory - setcookie
-
etop節點的Cookie,必須和被監控節點的Cookie一致
Value: atom() - lines
-
顯示多少行Process相關信息
Value: integer()
Default: 10 - interval
-
刷新頻率(秒)
Value: integer()
Default: 5 - accumulate
- 數據是否以累加方式顯示
Value: boolean()
Default: false - sort
-
Process排序依據
Value: runtime | reductions | memory | msg_q
Default: runtime (reductions if tracing=off ) - tracing
- etop使用trace機制進行執行時間的檢測,當爲on時,可以顯示runtime,這樣作增加了系統負載.
- 當爲off時,無法顯示runtime
- Value: on | off
Default: on
例子:
etop -node ip@litaocheng -lines 5 -sort memory -interval 1 -accumulate true -tracing on
顯示信息如下:
ip@litaocheng 05:54:40
Load: cpu 0 Memory: total 69176 binary 42113
procs 41 processes 23524 code 2307
runq 0 atom 311 ets 152
Pid Name or Initial Func Time Reds Memory MsgQ Current Function
----------------------------------------------------------------------------------------
<4705.31.0> erlang:apply/2 0 31385517249824 0 shell:get_command1/5
<4705.54.0> erlang:apply/2 0 2192005 6171152 0 shell:eval_loop/3
<4705.26.0> code_server 0 171428 131756 0 code_server:loop/1
<4705.5.0> application_controll 0 8560 119080 0 gen_server:loop/6
<4705.30.0> group:server/3 0 34084 33972 0 group:get_line1/3
========================================================================================
其中Memory單位爲KB, process中的mmemory爲bytes.