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
170
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
950
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
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
Pinia Colada が実現するスマートな非同期処理
naokihaba
2
160
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
Piniaの現状と今後
waka292
5
1.5k
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
350
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
160
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
270
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
Six Lessons from altMBA
skipperchong
26
3.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Writing Fast Ruby
sferik
626
61k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Become a Pro
speakerdeck
PRO
24
5k
Making the Leap to Tech Lead
cromwellryan
132
8.9k
Practical Orchestrator
shlominoach
186
10k
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