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
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
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
900
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Jakarta EE meets AI
ivargrimstad
0
160
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Arm移行タイムアタック
qnighy
0
320
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
The World Runs on Bad Software
bkeepers
PRO
65
11k
The Invisible Side of Design
smashingmag
298
50k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Designing Experiences People Love
moore
138
23k
RailsConf 2023
tenderlove
29
900
The Cult of Friendly URLs
andyhume
78
6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Become a Pro
speakerdeck
PRO
25
5k
What's in a price? How to price your products and services
michaelherold
243
12k
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