简单调试

sys 模块包含了简单调试用行为实现的进程的函数。我们用来自 Gen_Event行为 一章中的 code_lock 例子来进行解释:

  1. % erl
  2. Erlang (BEAM) emulator version 5.2.3.6 [hipe] [threads:0]
  3.  
  4. Eshell V5.2.3.6 (abort with ^G)
  5. 1> code_lock:start_link([1,2,3,4]).
  6. {ok,<0.32.0>}
  7. 2> sys:statistics(code_lock, true).
  8. ok
  9. 3> sys:trace(code_lock, true).
  10. ok
  11. 4> code_lock:button(4).
  12. *DBG* code_lock got event {button,4} in state closed
  13. ok
  14. *DBG* code_lock switched to state closed
  15. 5> code_lock:button(3).
  16. *DBG* code_lock got event {button,3} in state closed
  17. ok
  18. *DBG* code_lock switched to state closed
  19. 6> code_lock:button(2).
  20. *DBG* code_lock got event {button,2} in state closed
  21. ok
  22. *DBG* code_lock switched to state closed
  23. 7> code_lock:button(1).
  24. *DBG* code_lock got event {button,1} in state closed
  25. ok
  26. OPEN DOOR
  27. *DBG* code_lock switched to state open
  28. *DBG* code_lock got event timeout in state open
  29. CLOSE DOOR
  30. *DBG* code_lock switched to state closed
  31. 8> sys:statistics(code_lock, get).
  32. {ok,[{start_time,{{2003,6,12},{14,11,40}}},
  33. {current_time,{{2003,6,12},{14,12,14}}},
  34. {reductions,333},
  35. {messages_in,5},
  36. {messages_out,0}]}
  37. 9> sys:statistics(code_lock, false).
  38. ok
  39. 10> sys:trace(code_lock, false).
  40. ok
  41. 11> sys:get_status(code_lock).
  42. {status,<0.32.0>,
  43. {module,gen_fsm},
  44. [[{'$ancestors',[<0.30.0>]},
  45. {'$initial_call',{gen,init_it,
  46. [gen_fsm,<0.30.0>,<0.30.0>,
  47. {local,code_lock},
  48. code_lock,
  49. [1,2,3,4],
  50. []]}}],
  51. running,<0.30.0>,[],
  52. [code_lock,closed,{[],[1,2,3,4]},code_lock,infinity]]}