• erlang调试方法


    1. 第一种方式,加打印记录
    %%-define(debug, ok).
    
    -ifdef(debug).
    -define(LOG(X), io:format("pid:~p , {~p,~p}: ~p~n", [self(), ?MODULE, ?LINE, X])).
    -else.
    -define(LOG(X), true).
    -endif.
    

    设置LOG的宏定义,调试只要在代码中加入?LOG(Val),就可以

    特点是,简单,调试清楚,对代码性能的影响小,也是最常用的方法,就不举例说明了

    第二种方法,加trace 日志

    %trace Mod 所有方法的调用
    trace(Mod) ->
        dbg:tracer(),
        dbg:p(all, [call]),
        dbg:tp(Mod,  [{'_', [], [{return_trace}]}]);
    
    
    %trace Mod 的Fun方法的调用
    trace(Mod, Fun) ->
        dbg:tracer(),
        dbg:p(all, [call]),
        dbg:tp(Mod, Fun, [{'_', [], [{return_trace}]}]);
    
    %停止trace
    trace_stop() ->
        dbg:stop_clear().

    特点:对整个模块,或者某些函数进行详细的调试,调试信息比较多,对性能有一段影响。

    举例

    ......
    ......
    init([Opt]) ->
        Tab = ets:new(xx, [set]),
        case opt_find(debug, Opt, false) of              %%如果设置了debug,开启debug跟踪
        true ->
            dbg:tracer(),
            dbg:p(all, [call]),
            dbg:tp(tt5, [{'_', [], [{return_trace}]}]);
        _ ->
            %% Keep silent
            ok
        end,
        {ok, #state{tab = Tab}}.
    
    .....
    .....
    .....
    1> c(tt5).
    {ok,tt5}
    2> tt5:start([{debug, true}]). 
    {ok,<0.39.0>}
    3> tt5:add(name, "wowchina"). 
    (<0.32.0>) call tt5:add(name,"wowchina")
    (<0.39.0>) call tt5:handle_call({add,name,"wowchina"},{<0.32.0>,#Ref<0.0.0.104>},{state,16400})
    (<0.39.0>) returned from tt5:handle_call/3 -> {reply,true,{state,16400}}
    (<0.32.0>) returned from tt5:add/2 -> true
    true
    4> tt5:find(name).           
    (<0.32.0>) call tt5:find(name)
    (<0.39.0>) call tt5:handle_call({find,name},{<0.32.0>,#Ref<0.0.0.113>},{state,16400})
    (<0.39.0>) returned from tt5:handle_call/3 -> {reply,
                                                   [{name,"wowchina"}],
                                                   {state,16400}}
    (<0.32.0>) returned from tt5:find/1 -> [{name,"wowchina"}]
    [{name,"wowchina"}]
    5> 
    
  • 相关阅读:
    Caffe--solver.prototxt配置文件 参数设置及含义
    关于KMP算法理解(快速字符串匹配)
    Lintcode--004(最小子串覆盖)
    Lintcode--003(乱序字符串)
    Lintcode--002(两个字符串是变位词)
    Lintcode--001(比较字符串)
    闭包的应用实例
    JavaScript完整性检查
    null和undefined相等比较
    JavaScript逻辑运算符(操作数运算符)
  • 原文地址:https://www.cnblogs.com/tudou008/p/5210109.html
Copyright © 2020-2023  润新知