- 简单调试
简单调试
sys 模块包含了简单调试用行为实现的进程的函数。我们用来自 Gen_Event行为 一章中的 code_lock 例子来进行解释:
- % erl
- Erlang (BEAM) emulator version 5.2.3.6 [hipe] [threads:0]
- Eshell V5.2.3.6 (abort with ^G)
- 1> code_lock:start_link([1,2,3,4]).
- {ok,<0.32.0>}
- 2> sys:statistics(code_lock, true).
- ok
- 3> sys:trace(code_lock, true).
- ok
- 4> code_lock:button(4).
- *DBG* code_lock got event {button,4} in state closed
- ok
- *DBG* code_lock switched to state closed
- 5> code_lock:button(3).
- *DBG* code_lock got event {button,3} in state closed
- ok
- *DBG* code_lock switched to state closed
- 6> code_lock:button(2).
- *DBG* code_lock got event {button,2} in state closed
- ok
- *DBG* code_lock switched to state closed
- 7> code_lock:button(1).
- *DBG* code_lock got event {button,1} in state closed
- ok
- OPEN DOOR
- *DBG* code_lock switched to state open
- *DBG* code_lock got event timeout in state open
- CLOSE DOOR
- *DBG* code_lock switched to state closed
- 8> sys:statistics(code_lock, get).
- {ok,[{start_time,{{2003,6,12},{14,11,40}}},
- {current_time,{{2003,6,12},{14,12,14}}},
- {reductions,333},
- {messages_in,5},
- {messages_out,0}]}
- 9> sys:statistics(code_lock, false).
- ok
- 10> sys:trace(code_lock, false).
- ok
- 11> sys:get_status(code_lock).
- {status,<0.32.0>,
- {module,gen_fsm},
- [[{'$ancestors',[<0.30.0>]},
- {'$initial_call',{gen,init_it,
- [gen_fsm,<0.30.0>,<0.30.0>,
- {local,code_lock},
- code_lock,
- [1,2,3,4],
- []]}}],
- running,<0.30.0>,[],
- [code_lock,closed,{[],[1,2,3,4]},code_lock,infinity]]}