在Erlang中使用trace和dbg [英] Using trace and dbg in Erlang

查看:135
本文介绍了在Erlang中使用trace和dbg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开始使用erlang:trace / 3和dbg模块来跟踪现场制作系统的行为,而不会使服务器关闭。

I am trying to start using erlang:trace/3 and the dbg module to trace the behaviour of a live production system without taking the server down.

a href =http://erldocs.com/R13B03/erts/erlang.html?search=erlang:trace&i=0#trace/3 =noreferrer>文档是 opaque (轻轻地放),那里似乎没有任何有用的在线教程。

The documentation is opaque (to put it mildly) and there don't appear to be any useful tutorials online.

我一整天努力做的都是通过尝试应用跟踪来捕获特定功能中发生的情况模块:使用dbg:c和dbg:p的功能,但根本没有成功...

What I spent all day trying to do was capture what was happening in a particular function by trying to apply a trace to module:function using dbg:c and dbg:p but with no success at all...

有没有人有简洁的说明如何在活Erlang中使用跟踪系统?

Does anyone have a succinct explanation of how to use trace in a live Erlang system?

推荐答案

跟踪功能调用的基本步骤是在非实时节点上:

The basic steps of tracing for function calls are on a non-live node:

> dbg:start().   % start dbg
> dbg:tracer().  % start a simple tracer process
> dbg:tp(Module, Function, Arity, []).   % specify MFA you are interested in
> dbg:p(all, c).   % trace calls (c) of that MFA for all processes.

... trace here

> dbg:stop_clear().   % stop tracer and clear effect of tp and p calls.

您可以同时跟踪多个功能。通过为每个函数调用 tp 添加函数。如果要跟踪未导出的函数,则需要调用 tpl 。要删除功能,请以类似的方式调用 ctp ctpl 。一些一般的电话是:

You can trace for multiple functions at the same time. Add functions by calling tp for each function. If you want to trace for non-exported functions, you need to call tpl. To remove functions, call ctp or ctpl in a similar manner. Some general tp calls are:

> dbg:tpl(Module, '_', []).  % all calls in Module
> dbg:tpl(Module, Function, '_', []).   % all calls to Module:Function with any arity.
> dbg:tpl(Module, Function, Arity, []). % all calls to Module:Function/Arity.
> dbg:tpl(M, F, A, [{'_', [], [{return_trace}]}]).   % same as before, but also show return value.

最后一个参数是匹配规范。您可以使用 dbg:fun2ms

The last argument is a match specification. You can play around with that by using dbg:fun2ms.

您可以选择要跟踪的进程调用p()。项目描述在erlang:trace下。有些电话是:

You can select the processes to trace on with the call to p(). The items are described under erlang:trace. Some calls are:

> dbg:p(all, c).   % trace calls to selected functions by all functions
> dbg:p(new, c).   % trace calls by processes spawned from now on
> dbg:p(Pid, c).   % trace calls by given process
> dbg:p(Pid, [c, m]).  % trace calls and messages of a given process

我想你永远不需要直接调用 erlang:trace ,因为 dbg 几乎为你做的一切。

I guess you will never need to directly call erlang:trace, as dbg does pretty much everything for you.

活动节点的黄金规则是仅向shell生成一定量的跟踪输出,这样可以输入 dbg:stop_clear()。。 :)

A golden rule for a live node is to generate only an amount of trace output to the shell, which lets you to type in dbg:stop_clear().. :)

我经常使用一个跟踪器,它会在一些事件之后自动停止。例如:

I often use a tracer that will auto-stop itself after a number of events. For example:

dbg:tracer(process, {fun (_,100) -> dbg:stop_clear();
                        (Msg, N) -> io:format("~p~n", [Msg]), N+1 end, 0
                    }).

如果您正在寻找远程节点(或多个节点)上的调试,请搜索 pan eper inviso onviso

If you are looking for debugging on remote nodes (or multiple nodes), search for pan, eper, inviso or onviso.

这篇关于在Erlang中使用trace和dbg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆