How to Use Dtrace Tracing Ruby Executing
http://googya.github.io/blog/categories/dtrace/
最近看了点关于Dtrace的东西,它是个通用型的工具,但我主要集中于分析ruby程序的执行上面。关于操作系统的性能分析,比如cpu、内存、io、文件系统等,使用起来貌似挺复杂,木有细看。
这里简单的输出一条命令:
sudo dtrace -n 'ruby$target:::object-create {@objects[copyinstr(arg0)]=count();}' -c 'ruby -e "puts :hello"'
输出的结果是:
dtrace: description 'ruby$target:::object-create ' matched 1 probe
-e:1: unterminated string meets end of file
dtrace: pid 15203 has exited
#<Class:0x007fabf38e0700> 1
ARGF.class 1
IOError 1
Mutex 1
NoMemoryError 1
SyntaxError 1
SystemStackError 1
ThreadGroup 1
Time 1
LoadError 2
Object 2
Gem::Specification 8
Gem::Version 10
Hash 11
Gem::Requirement 23
Array 96
String 260
ruby2.0已经有支持probe了,所以可以使用dtrace
2.0之前的如果要使用dtrace的话,要使用 ruby-dtrace这个gem
另外在学习的时候,写了dtrace的脚本,其实就是D语言了, rb_flowinfo.d,查看ruby方法的调用过程:
#!/usr/sbin/dtrace -Zs
#pragma D option quiet
#pragma D option switchrate=10
self int depth;
dtrace:::BEGIN
{
printf("%s %6s %10s %16s:%-4s %-8s -- %s\n", "C", "PID", "DELTA(us)", "FILE", "LINE", "TYPE", "NAME");
}
ruby*:::method-entry,
ruby*:::method-return
/self->last == 0/
{
self->last = timestamp;
}
ruby*:::method-entry
/copyinstr(arg0) == "Object"/
{
this->delta = (timestamp - self->last) / 1000;
this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
printf("%d %6d %10d %16s:%-4d %-8s %*s-> %s\n", cpu, pid, this->delta,
basename(copyinstr(arg2)), arg3, "method", self->depth * 2, "", this->name);
self->depth++;
self->last = timestamp;
}
ruby*:::method-return
/copyinstr(arg0) == "Object"/
{
this->delta = (timestamp - self->last) / 1000;
self->depth -= self->depth > 0 ? 1 : 0;
this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
printf("%d %6d %10d %16s:%-4d %-8s %*s<- %s\n", cpu, pid, this->delta,
basename(copyinstr(arg2)), arg3, "method", self->depth * 2, "", this->name);
self->last = timestamp;
}
用于测试的ruby脚本, trace_method_call.rb
dtrace_ruby $ cat trace_method_call.rb
#!/Users/wenleslie/.rvm/rubies/ruby-2.0.0-p0/bin/ruby
def func_c
puts "Function C"
sleep 1
end
def func_b
puts "Function B"
sleep 6
func_c
end
def func_a
puts "Function A"
func_b
end
func_a
执行:
sudo ./rb_flowinfo.d -c ./trace_method_call.rb
结果如下:
C PID DELTA(us) FILE:LINE TYPE -- NAME
Function A
Function B
4 15702 35986 trace_method_call.rb:13 method -> Object::func_a
4 15702 55 trace_method_call.rb:7 method -> Object::func_b
Function C0 15702 6001065 trace_method_call.rb:2 method -> Object::func_c
6 15702 1000922 trace_method_call.rb:5 method <- Object::func_c
6 15702 27 trace_method_call.rb:11 method <- Object::func_b
6 15702 19 trace_method_call.rb:16 method <- Object::func_a
^C
我的evernote上关于dtrace笔记有稍微详细一点的内容,有兴趣的话,可以看看
How to Use Dtrace Tracing Ruby Executing的更多相关文章
- dtrace 语法
Usage: dtrace [-aACeFHlqSvVwZ] [-arch i386|x86_64] [-b bufsz] [-c cmd] [-D name[=def]] [-I path ...
- Linux Perf Probes for Oracle Tracing
Luca Canali on 21 Jan 2016 Topic: this post is about Linux perf and uprobes for tracing and profilin ...
- Adding DTrace Probes to PHP Extensions
By cj on Dec 06, 2012 The powerful DTrace tracing facility has some PHP-specific probes that can b ...
- [转]Top 10 DTrace scripts for Mac OS X
org link: http://dtrace.org/blogs/brendan/2011/10/10/top-10-dtrace-scripts-for-mac-os-x/ Top 10 DTra ...
- End-to-End Tracing of Ajax/Java Applications Using DTrace
End-to-End Tracing of Ajax/Java Applications Using DTrace By Amit Hurvitz, July 2007 Aja ...
- Tracing mysqld Using DTrace
http://dev.mysql.com/doc/refman/5.6/en/dba-dtrace-server.html MySQL 5.6 Reference Manual -> 5 MyS ...
- Using Dtrace OEL 6.X and Oracle® Solaris 11.3 DTrace (Dynamic Tracing) Guide
http://www.hhutzler.de/blog/using-dtrace/ https://docs.oracle.com/cd/E53394_01/html/E53395/gkyaz.htm ...
- [转]Breaking Bad With DTrace
Source:http://initwithfunk.com/blog/2013/05/31/breaking-bad-with-dtrace/ I’ve spent an unwise amount ...
- Life of an Oracle I/O: tracing logical and physical I/O with systemtap
https://db-blog.web.cern.ch/blog/luca-canali/2014-12-life-oracle-io-tracing-logical-and-physical-io- ...
随机推荐
- FCKeditor自定义编辑区CSS样式
在网站后台使用FCKeditor编辑器的时候,见到的效果可能并不完全是”所见即所得”的,因为如果在FCKeditor编辑区中使用了前台样式表中的样式,在编辑区中并不能把这些样式显示出来.解决这个问题的 ...
- apple苹果产品国行和港行的区别
[iPhone国行和港行的区别]国行:耳机只能用在苹果设备上,不能用其它设备.充电器不用转接,直接可以用,保修的时候如果换新了,重新计算一年保修期.国行是三网通用.港行:耳机可以用在任何设备上.充电器 ...
- webdriver高级应用- 测试过程中发生异常或断言失败时进行屏幕截图
封装了三个类来实现这个功能: 1.DataUtil.py 用于获取当前的日期以及时间,用于生成保存截图文件的目录名,代码如下: #encoding=utf-8 import time from dat ...
- Ext.js二级联动
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link href ...
- 第3章 jquery中的事件和动画
一,jquery中的事件 (1).执行时机 $(document).ready()和window.onload方法有相似的功能,但是在执行时机方面有区别,windwo.onload在网页中所有的元素包 ...
- 山东理工大学第七届ACM校赛-G 飞花的传送门
G - 飞花的传送门 飞花壕最近手头比较宽裕,所以想买两个传送门来代步(夏天太热,实在是懒得走路).平面上有N个传送门,飞花壕想要挑两个距离最远的传送门带回家(距离为欧几里得距离,即两点之间直线距离) ...
- hibernate悲观锁,乐观锁
业务逻辑的实现过程中,往往需要保证数据访问的排他性.因此,我们就需要通过一些机制来保证这些数据在某个操作过程中不会被外界修改,这样的机制,在这里,也就是所谓的“锁”,即给我们选定的目标数据上锁,使其无 ...
- 洛谷P3625 - [APIO2009]采油区域
Portal Description 给出一个\(n\times m(n,m\leq1500)\)的矩阵,从中选出\(3\)个互不相交的\(k\times k\)方阵,使得被选出的数的和最大. Sol ...
- mybatis学习(五)——增删改查及自增主键的获取
一.mybatis的增删改查 1.修改hotelMapper接口 package com.pjf.mybatis.dao; import com.pjf.mybatis.po.Hotel; publi ...
- Jersey实现Client端:GET/PUT/POST/DELETE
原文地址:Jersey客户端API调用REST风格的Web服务 [节选] 要开始使用 Jersey 客户端 API,你首先需要创建一个 com.sun.jersey .api.client.Clien ...