Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Tracing your way through Ruby
Search
elise_huard
September 08, 2012
Programming
4
530
Tracing your way through Ruby
Solve the more complex problems with DTrace
elise_huard
September 08, 2012
Tweet
Share
More Decks by elise_huard
See All by elise_huard
FRP in games
elise_huard
0
180
Game in Haskell at Strangeloop 2014
elise_huard
4
510
Functional Programming is the new black
elise_huard
4
1.2k
Ruby's bin men
elise_huard
1
150
Ruby's bin men
elise_huard
2
960
data driven development
elise_huard
5
250
git hygiene
elise_huard
3
390
Data Driven Development
elise_huard
3
430
Ruby goes to Hollywood
elise_huard
1
530
Other Decks in Programming
See All in Programming
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
たのしいparse.y
ydah
3
120
선언형 UI에서의 상태관리
l2hyunwoo
0
180
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
280
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
160
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
nekko cloudにおけるProxmox VE利用事例
irumaru
3
440
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
480
良いユニットテストを書こう
mototakatsu
8
2.8k
テストコード書いてみませんか?
onopon
2
140
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Building Applications with DynamoDB
mza
91
6.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Agile that works and the tools we love
rasmusluckow
328
21k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Designing Experiences People Love
moore
138
23k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Being A Developer After 40
akosma
87
590k
Transcript
Tracing your way through ruby Elise Huard @elise_huard Baruco 2012
Saturday, 8 September 12
99% of problems standard errors Saturday, 8 September 12
undefined method `to_str' for nil:NilClass wrong number of arguments(3 for
0) (ArgumentError) No such file or directory - records.csv (Errno::ENOENT) Saturday, 8 September 12
Saturday, 8 September 12
Tracing the hell out of your ruby Saturday, 8 September
12
DTrace Saturday, 8 September 12
Producer: Probes Saturday, 8 September 12
probes.d provider ruby { probe function__entry(const char *, const char
*, const char *, int); (...) probe gc__begin(); probe gc__end(); (...) } https://github.com/tenderlove/ruby/tree/probes Saturday, 8 September 12
probes.h #define RUBY_DTRACE_FUNCTION_ENTRY(arg0, arg1, arg2, arg3) \ do { \
__asm__ volatile(".reference " RUBY_DTRACE_TYPEDEFS); \ __dtrace_probe$ruby$function__entry$v1$63686172202a $63686172202a$63686172202a$696e74(arg0, arg1, arg2, arg3); \ __asm__ volatile(".reference " RUBY_DTRACE_STABILITY); \ } while (0) #define RUBY_DTRACE_FUNCTION_ENTRY_ENABLED() \ (...) Saturday, 8 September 12
Ruby C code if (RUBY_DTRACE_FUNCTION_ENTRY_ENABLED()) { const char * classname
= rb_class2name(klass); const char * methodname = rb_id2name(id); const char * filename = rb_sourcefile(); if (classname && methodname && filename) { RUBY_DTRACE_FUNCTION_ENTRY( classname, methodname, filename, rb_sourceline()); } } Saturday, 8 September 12
On the system dtrace -l dtrace -lP ruby Saturday, 8
September 12
Consumer: D language Saturday, 8 September 12
Let’s start simple ruby*:::function-entry { printf("-> %s::%s (%s:%d)\n", copyinstr(arg0), copyinstr(arg1),
copyinstr(arg2), arg3); } Saturday, 8 September 12
Ruby C code if (RUBY_DTRACE_FUNCTION_ENTRY_ENABLED()) { const char * classname
= rb_class2name(klass); const char * methodname = rb_id2name(id); const char * filename = rb_sourcefile(); if (classname && methodname && filename) { RUBY_DTRACE_FUNCTION_ENTRY( classname, methodname, filename, rb_sourceline()); } } Saturday, 8 September 12
➜ baruco-2012 sudo dtrace -q -s simple.d -p 70239 ->
Class::now (/usr/local/lib/ruby/2.0.0/webrick/utils.rb:177) -> Time::initialize (/usr/local/lib/ruby/2.0.0/webrick/utils.rb: 177) -> Fixnum::+ (/usr/local/lib/ruby/2.0.0/webrick/utils.rb:177) -> Hash::keys (/usr/local/lib/ruby/2.0.0/webrick/utils.rb:178) -> Array::each (/usr/local/lib/ruby/2.0.0/webrick/utils.rb:178) -> Kernel::sleep (/usr/local/lib/ruby/2.0.0/webrick/utils.rb:186) -> Class::now (/usr/local/lib/ruby/2.0.0/webrick/utils.rb:177) -> Time::initialize (/usr/local/lib/ruby/2.0.0/webrick/utils.rb: 177) -> Fixnum::+ (/usr/local/lib/ruby/2.0.0/webrick/utils.rb:177) Saturday, 8 September 12
thread-local variables #pragma D option quiet ruby*:::gc-begin { self->gstart =
timestamp; } ruby*:::gc-end / self->gstart != NULL / { printf("GC time %d\n",timestamp - self->gstart); } Saturday, 8 September 12
thread-local variables #pragma D option quiet ruby*:::gc-begin { self->gstart =
timestamp; } ruby*:::gc-end / self->gstart != NULL / { printf("GC time %d\n",timestamp - self->gstart); } Saturday, 8 September 12
➜ baruco-2012 sudo dtrace -s gc_time.d -p 73340 GC time
24788699 GC time 20332615 GC time 88187 GC time 116567 GC time 29605 GC time 31248 GC time 29645 GC time 21863365 Saturday, 8 September 12
Aggregate #pragma D option aggsortrev ruby*:::function-entry { @[copyinstr(arg0), copyinstr(arg1)] =
count(); } Saturday, 8 September 12
➜ baruco-2012 sudo dtrace -s aggregate.d -p 73340 ^C Module
to_s 4883 Kernel inspect 4868 StringScanner scan 685 Proc call 430 Hash []= 421 Symbol == 298 Array each 232 Kernel hash 211 Class new 204 String sub 189 Rack::Lint::Assertion assert 188 Saturday, 8 September 12
Aggregate #pragma D option quiet ruby*:::gc-begin { self->gstart = timestamp;
} ruby*:::gc-end / self->gstart != NULL / { @length = quantize(timestamp - self->gstart); } Saturday, 8 September 12
Aggregate #pragma D option quiet ruby*:::gc-begin { self->gstart = timestamp;
} ruby*:::gc-end / self->gstart != NULL / { @length = quantize(timestamp - self->gstart); } Saturday, 8 September 12
➜ baruco-2012 sudo dtrace -s aggregate_q.d -p 73340 ^C value
------------- Distribution ------------- count 65536 | 0 131072 |@@ 1 262144 |@@@@@@@@@@@@@@ 6 524288 |@@@@@@@@@@@@ 5 1048576 |@@@@@@@ 3 2097152 |@@@@@ 2 4194304 | 0 Saturday, 8 September 12
count sum avg min max stddev lquantize quantize Saturday, 8
September 12
Tools based on dtrace Saturday, 8 September 12
dtruss: syscalls (strace) Saturday, 8 September 12
iosnoop Saturday, 8 September 12
execsnoop: executing programs Saturday, 8 September 12
Instruments Saturday, 8 September 12
Saturday, 8 September 12
Saturday, 8 September 12
JRuby ➜ baruco-2012 sudo dtrace -ln 'hotspot*:::gc-begin' ➜ baruco-2012 sudo
dtrace -ln 'hotspot*:::thread-start' http://www.solarisinternals.com/wiki/index.php/ DTrace_Topics_Java#Listing_Probes Saturday, 8 September 12
Sometimes ... Saturday, 8 September 12
Saturday, 8 September 12
Thanks Gracies Gracias Elise Huard @elise_huard Baruco 2012 Saturday, 8
September 12