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
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
Security_for_introducing_eBPF
kentatada
0
110
命名をリントする
chiroruxx
1
420
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
230
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
510
Zoneless Testing
rainerhahnekamp
0
120
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
140
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
169
14k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Designing Experiences People Love
moore
138
23k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Thoughts on Productivity
jonyablonski
67
4.4k
For a Future-Friendly Web
brad_frost
175
9.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Visualization
eitanlees
146
15k
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