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
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
920
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
520
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.7k
役立つログに取り組もう
irof
26
8.7k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
440
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
9
1k
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.4k
Pinia Colada が実現するスマートな非同期処理
naokihaba
2
160
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Making the Leap to Tech Lead
cromwellryan
132
8.9k
Code Review Best Practice
trishagee
64
17k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
Producing Creativity
orderedlist
PRO
341
39k
Optimizing for Happiness
mojombo
376
69k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
680
Visualization
eitanlees
144
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