博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
trancing in erlang
阅读量:6176 次
发布时间:2019-06-21

本文共 3458 字,大约阅读时间需要 11 分钟。

hot3.png

The dbg module is a bit complex to use, but it gives good control on what to trace, With using match specification it is possible to create more advanced filtering.

Standard debug tool in erlang enviroment - The dbg module. it is a part of the OTP. How to use? we need to specify three things:

  • which process(es) to trace
  • which function(s) to watch
  • under which conditions to receive a trace output(match specification)

Some type of faults require continuous logging functionality implemented in the product.(Log must be limited in memory and CPU usage)


Tracing with the dbg module

initialization dbg:tracer()

  • starts a trace server on the node
  • possible alternatives: send to another process for processing, or send to a file.

specify process(es) dbg:p(process, Flags).

process

  • a Pid
  • a tuple{X, Y, Z} -> turns to Pid
  • "all" -> all existing and future processes
  • "new" -> all future processes
  • "existing" -> all existing processes
  • "processname" -> the process with registered name "processname" is traced

Specify function dbg:tp and dbg:tpl

  • dbg:tp(Module, MatchSpec)
  • dbg:tpl(Module, MatchSpec) Module:
    {Module, '_', '_'}{Module, Function, '_'}{Module, Function, Arity}
  • dbg:tpl is the same as the equivalent dbg:tp, but enables tracing for local calls (and local functions) as well as for global calls(and functions)

Format of MatchSpec

[{MatchHead1, MatchConditions1, MatchBody1 }, {MatchHead1, MatchConditions1, MatchBody1 }, ...]
  • Examples of MatchSpec
[{'_', [], [{return_trace}]}]or:[{[gcpLinkTable, '_'], [], {return_trace}}]

  • Examples with dbg:tpl
Tracing for ets:insert/2  dbg:tpl(ets, insert, [{'_', [], [return_trace]}]).  Tracing for ets:insert/2, but only for one table  dbg:tpl(ets,          insert,          [{[Table, '_'], [], [{return_trace}]}]).  same as above, and include also the process stack in trace output  dbg:tpl(ets,          insert,          [{[Table, "_"],            [],            [{message, {process_dump}}, {return_trace}]}]).

  • Tracing into file
dbg:tracer(port,           dbg:trace_port(file, '/tmp/trace001.txt')).dbg:p(all, [c]).dbg:tpl(ets, insert, [{'_', [], [return_trace]}]).stop tracedbg:stop_clear().

  • close the file
At the end don't forget to stop tracing, it will close the file.  dbg:stop().    dbg:stop_clear().    same as stop/0, but also clears all trace patterns on local and global functions calls.
  • Trace on ets:insert/2. Receive trace output for a specific table (exercise) and a specific key value (99):
ets:new(exercise,      [named_table, ordered_set, public, {keypos, 2}]).	dbg:tracer().	dbg:p(all, [c]).	dbg:tpl(ets,         insert,          [{['$1', '$2'],              [{'==', exercise, '$1'},         {'==', 99, {element, 2, '$2'}}],               [{message, {process_dump}}, {return_trace}]}]).  	ets:insert(exercise, {exercise, 1, data1}).	ets:insert(exercise, {exercise, 99, data99}).
  • Try also the same exercise with trace output to a file instead of the shell log, and compare the results.

  • dbg:tpl(ets, insert, ..

    Tracing on module 'ets', function 'insert', arity unspecified -> all

  • [{['$1', '$2'], (Match Head)

    Matching ets:insert('$1', '$2').
    implicitly means; Tracing on arity= 2

  • [{'==', exercise, '$1'}, (Match Condition)

    {'==', 99, {element, 2, '$2'}}], (Match Condition)
    Tracing output when these conditions evaluates to ‘true’
    I.e. when ‘$1’ == exercise and element(2, ‘$2’) == 99

  • [{message, {process_dump}}, {return_trace}]}]) (Match Body)


links

转载于:https://my.oschina.net/lvhuizhenblog/blog/1785686

你可能感兴趣的文章
堆排序
查看>>
Java的热部署(后期完善)
查看>>
css总结
查看>>
Python学习笔记之六:在VS中调用Python
查看>>
node.js获取参数的常用方法
查看>>
jquery 的 change() 方法的使用
查看>>
本地计算机上的XXX服务启动后又停止了
查看>>
<s:iterator>标签迭代数据不显示
查看>>
判断 SQLServer 触发器类型,支持多行
查看>>
SQL表连接查询(inner join、full join、left join、right join)
查看>>
阿里云OTS(开放结构化数据服务)可视化管理工具的设计和功能介绍
查看>>
Github创建分支
查看>>
转换PHP脚本成为windows的执行程序
查看>>
Python组织文件 实践:将带有美国风格日期的文件改名为欧洲风格日期
查看>>
实现iOS7上tableView的切割线像iOS6中的效果
查看>>
使用阿里云接口进行银行卡四要素实名认证
查看>>
聊聊excel生成图片的几种方式
查看>>
20 万网络节点背后的数据创新应用
查看>>
理论 | 朴素贝叶斯模型算法研究与实例分析
查看>>
docker安装gitlab只需要3分钟
查看>>