OTP杂七杂八(sys模块)
2012-05-21 19:31
155 查看
sys模块主要是在OTP中抽象出一层系统消息处理层,该类消息形如{system, XXX}。包括了此类消息的发送以及相应处理。我们还可以通过它来构建自己简单的消息调试框架,收集一些额外的消息数据,如:接收消息数量,发送消息数量等……
主要又分为这样几种内部系统消息:
suspend:进程挂起消息。
resume:进程恢复消息。
change_code:代码改变消息。
get_status:当前状态消息。
debug属性设置消息:进程调试类消息(调试过程中可能会由sys:log, sys:trace...等类似方法对Debug属性进行调整)
在这里Sys分为两种状态suspended,running,主要通过sys:suspend,sys:resume进行切换。
首先我们通过debug_option来建立出debug设置属性(如打印,输出文件等),相当于后面消息处理的上下文
主要又分为这样几种内部系统消息:
suspend:进程挂起消息。
resume:进程恢复消息。
change_code:代码改变消息。
get_status:当前状态消息。
debug属性设置消息:进程调试类消息(调试过程中可能会由sys:log, sys:trace...等类似方法对Debug属性进行调整)
在这里Sys分为两种状态suspended,running,主要通过sys:suspend,sys:resume进行切换。
首先我们通过debug_option来建立出debug设置属性(如打印,输出文件等),相当于后面消息处理的上下文
debug_options(Options) -> debug_options(Options, []). debug_options([trace | T], Debug) -> debug_options(T, install_debug(trace, true, Debug)); debug_options([log | T], Debug) -> debug_options(T, install_debug(log, {10, []}, Debug)); debug_options([{log, N} | T], Debug) when is_integer(N), N > 0 -> debug_options(T, install_debug(log, {N, []}, Debug)); debug_options([statistics | T], Debug) -> debug_options(T, install_debug(statistics, init_stat(), Debug)); debug_options([{log_to_file, FileName} | T], Debug) -> case file:open(FileName, [write]) of {ok, Fd} -> debug_options(T, install_debug(log_to_file, Fd, Debug)); _Error -> debug_options(T, Debug) end; debug_options([{install, {Func, FuncState}} | T], Debug) -> debug_options(T, install_debug(Func, FuncState, Debug)); debug_options([_ | T], Debug) -> debug_options(T, Debug); debug_options([], Debug) -> Debug. 然后我们可以通过sys:statistics来开启和关闭,以及打印相关调试数据记录。 可以通过sys:handle_debug按照设置的debug属性来处理接收到的消息 除了内嵌的debug消息处理方法,我们还可以通过sys:install添加特定的消息处理回调函数,在handle_debug时进行回调。 同时sys模块定义了三个回调接口: system_continue:当resume先前suspend的进程时,回调。 system_terminate:当system进程在suspend时接收到EXIT消息时候,回调 system_code_change:当调用sys:code_change时,回调。
相关文章推荐
- Python3 sys(解释器 模块)
- python中sys模块各个类变量和方法(译文)(随学习加深而更新)
- Python中sys模块
- 【python】sys模块操作使用
- python之sys模块详解
- Python 中的os、sys模块
- python模块之sys
- 2.24 学python os模块 sys模块 hashlib模块 logging模块
- Python sys模块简介
- day25 模块,sys, logging, json, pickle
- python3中模块详解--os模块和sys模块
- Python os模块和sys模块 操作系统的各种接口
- 【Python模块】os & linecache & hashlib & commands & sys & time & datetime
- python中使用sys模板和logging模块获取行号和函数名的方法
- python模块—command and sys
- python 中sys,os模块及 .pyc文件
- Python系统操作(sys、os)模块
- Python Import机制备忘-模块搜索路径(sys.path)、嵌套Import、package Import
- [Erlang 0017]Erlang/OTP基础模块 proc_lib
- python的基础模块(os,sys,time,shutil,differlib,socket)