Erlang跟踪(仅在我的模块中从流程中收集数据) [英] Erlang tracing (collect data from processes only in my modules)
问题描述
作为一个例子,当我在一些模块功能中调用io:format时,我不需要知道io模块创建哪个进程。有没有人知道如何解决这个问题?
简答:
一种方法是查看调用消息,然后是生成消息。
长回答:
我不是 dbg 的专家。原因是我一直在使用(更好,更安全,更方便)的替代方案: pan ,来自 https://gist.github.com/gebi/jungerl/tree/master/lib/pan
API总结了 html文档。
使用 pan:start 可以跟踪指定接收所有内容的回调模块跟踪消息。那么你的回调模块可以处理它们,例如跟踪ETS中的进程或传入每个呼叫的状态数据。
跟踪消息的格式在 pan:scan 下指定。
有关回调模块的示例,可以查看 src / cb _ *。erl 。
现在您的问题:
使用平移可以跟踪过程处理和调用在您的favourit模块,如下所示:
pan:start({ip,CallbackModule},Node,all, procs,call],{Module})。
其中Module是模块的名称(在这种情况下是sptest)
然后回调模块(在这种情况下为cb_write)可以在相同的过程中查看调用消息之后的生成消息,例如:
32 - {call,{< 6761.194.0>,{'fun',{shell,< node>}}},{sptest,run, [97,97,97]]},{1332,247999,200771}}
33 - {spawn,{< 6761.194.0>,{'fun',{shell,< node>}}} ,{{< 6761.197.0>,{IO,fwrite的,2}},{IO,fwrite的,[[77,101,115,115,97,103,101,58,32,126,115,126,110],[[97,97,97]]]}},{1332 ,247999,200805}}
由于平底锅也使用相同的跟踪后端作为 dbg ,跟踪消息(和信息)也可以使用Erlang跟踪BIF-s收集,但 pan 更加安全。
While tracing my modules using dbg, I encountered with the problem how to collect messages such as spawn, exit, register, unregister, link, unlink, getting_linked, getting_unlinked, which are allowed by erlang:trace, but only for those processes which were spawned from my modules directly? As an examle I don't need to know which processes io module create, when i call io:format in some module function. Does anybody know how to solve this problem?
Short answer:
one way is to look at call messages followed by spawn messages.
Long answer:
I'm not an expert on dbg. The reason is that I've been using an (imho much better, safer and even handier) alternative: pan , from https://gist.github.com/gebi/jungerl/tree/master/lib/pan
The API is summarized in the html doc.
With pan:start you can trace specifying a callback module that receives all the trace messages. Then your callback module can process them, e.g. keep track of processes in ETS or a state data that is passed into every call. The format of the trace messages is specified under pan:scan.
For examples of callback modules, you may look at src/cb_*.erl.
Now to your question: With pan you can trace on process handling and calls in your favourit module like this:
pan:start({ip, CallbackModule}, Node, all, [procs,call], {Module}).
where Module is the name of your module (in this case: sptest) Then the callback module (in this case: cb_write) can look at the spawn messages that follow a call message within the same process, e.g.:
32 - {call,{<6761.194.0>,{'fun',{shell,<node>}}},{sptest,run,[[97,97,97]]},{1332,247999,200771}}
33 - {spawn,{<6761.194.0>,{'fun',{shell,<node>}}},{{<6761.197.0>,{io,fwrite,2}},{io,fwrite,[[77,101,115,115,97,103,101,58,32,126,115,126,110],[[97,97,97]]]}},{1332,247999,200805}}
As pan is also using the same tracing back end as dbg, the trace messages (and the information) can be collected using the Erlang trace BIF-s as well, but pan is much more secure.
这篇关于Erlang跟踪(仅在我的模块中从流程中收集数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!