Slide 1

Slide 1 text

@sartak DTRACE printf debugging for seventh-level wizards 12೥1݄14೔౔༵೔

Slide 2

Slide 2 text

ME ME ME ME ME ME ME Shawn M Moore @sartak I’m Bawstin’ Moose-lover Infinity Interactive 12೥1݄14೔౔༵೔

Slide 3

Slide 3 text

What’s my computer doing right now? Q: A: Find out with DTrace 12೥1݄14೔౔༵೔

Slide 4

Slide 4 text

iotop $ iotop dtrace: failed to initialize dtrace: DTrace requires additional privileges You may already have DTrace and not even know it. 12೥1݄14೔౔༵೔

Slide 5

Slide 5 text

Solaris & OS X (complete) Linux (partial) Profiler (Different and deeper than NYTProf) Debugger Kernel module “You don’t port DTrace to an OS, you port an OS to DTrace” DTRACE 12೥1݄14೔౔༵೔

Slide 6

Slide 6 text

SAFE! ɾNo unwanted side effects ɾVery low overhead ɾDo it in production! 12೥1݄14೔౔༵೔

Slide 7

Slide 7 text

σϞ pidpersec iotop execsnoop opensnoop dtruss plockstat iosnoop Global (high level) The metal (low level) 12೥1݄14೔౔༵೔

Slide 8

Slide 8 text

σϞ pidpersec iotop execsnoop opensnoop dtruss plockstat iosnoop Global (high level) The metal (low level) 12೥1݄14೔౔༵೔

Slide 9

Slide 9 text

PROGRAMMABILITY dtrace -n ' syscall::open:entry /strstr(copyinstr(arg0), "corpus") != NULL/ { printf("%s %s",execname,copyinstr(arg0)); }' Show processes that open a file whose name includes “corpus” 12೥1݄14೔౔༵೔

Slide 10

Slide 10 text

PROGRAMMABILITY dtrace -n ' syscall::open:entry /strstr(copyinstr(arg0), "corpus") != NULL/ { printf("%s %s",execname,copyinstr(arg0)); }' Show processes that open a file whose name includes “corpus” Event(Probe Description) 12೥1݄14೔౔༵೔

Slide 11

Slide 11 text

PROGRAMMABILITY dtrace -n ' syscall::open:entry /strstr(copyinstr(arg0), "corpus") != NULL/ { printf("%s %s",execname,copyinstr(arg0)); }' Show processes that open a file whose name includes “corpus” Predicate 12೥1݄14೔౔༵೔

Slide 12

Slide 12 text

PROGRAMMABILITY dtrace -n ' syscall::open:entry /strstr(copyinstr(arg0), "corpus") != NULL/ { printf("%s %s",execname,copyinstr(arg0)); }' Show processes that open a file whose name includes “corpus” Action 12೥1݄14೔౔༵೔

Slide 13

Slide 13 text

PROGRAMMABILITY dtrace -n ' syscall::open:entry /strstr(copyinstr(arg0), "corpus") != NULL/ { printf("%s %s",execname,copyinstr(arg0)); }' Show processes that open a file whose name includes “corpus” 12೥1݄14೔౔༵೔

Slide 14

Slide 14 text

DTrace instrumentation points ɾKernel function calls/returns (syscalls too) ɾPerl function calls/returns ɾSQL execution ɾthreads ɾsignals ɾmany more PROBES 12೥1݄14೔౔༵೔

Slide 15

Slide 15 text

THE COOL DEMO HEY, FORGETFUL! DEMO THE GPG THING 12೥1݄14೔౔༵೔

Slide 16

Slide 16 text

PROFILER Devel::NYTProf kicks ass 12೥1݄14೔౔༵೔

Slide 17

Slide 17 text

PROFILER But there’s more than one way to do it 12೥1݄14೔౔༵೔

Slide 18

Slide 18 text

PROFILER DEMO: syscalls intuit_method 12೥1݄14೔౔༵೔

Slide 19

Slide 19 text

XCode’s profiler uses DTrace 12೥1݄14೔౔༵೔

Slide 20

Slide 20 text

12೥1݄14೔౔༵೔

Slide 21

Slide 21 text

TRANSLATION “I am comfortable being ignorant and helpless” 12೥1݄14೔౔༵೔

Slide 22

Slide 22 text

DEBUGGER Request Tracker (e.g. rt.cpan.org) was failing tests on mod_perl. On only my computer. Probably because of all the Japanese. 12೥1݄14೔౔༵೔

Slide 23

Slide 23 text

DEBUGGER Failed test 'gpg: error reading key: ެ։伴͕ݟ͔ͭΓ·ͤΜ' doesn't match '(?-xism:public key not found)' 12೥1݄14೔౔༵೔

Slide 24

Slide 24 text

DEBUGGER ެ։伴͕ݟ͔ͭΓ·ͤΜ isn’t part of RT’s Japanese i18n 12೥1݄14೔౔༵೔

Slide 25

Slide 25 text

DEBUGGER ެ։伴͕ݟ͔ͭΓ·ͤΜ possibly from GPG’s i18n? 12೥1݄14೔౔༵೔

Slide 26

Slide 26 text

DEBUGGER gpg-2.0.18 $ ack -a ެ։伴͕ݟ͔ͭΓ·ͤΜ gpg-2.0.18 $ 12೥1݄14೔౔༵೔

Slide 27

Slide 27 text

DEBUGGER gpg-2.0.18 $ echo "ެ։伴͕ݟ͔ͭΓ·ͤΜ" | iconv -f UTF-8 -t EUCJP | xargs ack -ao | iconv -f EUCJP -t UTF-8 Binary file po/ja.gmo matches po/ja.po:2965:ެ։伴͕ݟ͔ͭΓ·ͤΜ po/ja.po:6525:ެ։伴͕ݟ͔ͭΓ·ͤΜ po/ja.po:8311:ެ։伴͕ݟ͔ͭΓ·ͤΜ gpg-2.0.18 $ 12೥1݄14೔౔༵೔

Slide 28

Slide 28 text

DEBUGGER probably a mis-set $LANG, $LC_ALL? 12೥1݄14೔౔༵೔

Slide 29

Slide 29 text

DEBUGGER Ͱ΋ LC_ALL=en gpg LC_ALL=ja gpg LC_ALL= gpg opensnoop 12೥1݄14೔౔༵೔

Slide 30

Slide 30 text

DEBUGGER Without DTrace, woulda had to add print statements to GPG itself 12೥1݄14೔౔༵೔

Slide 31

Slide 31 text

DEBUGGER then compiled it 12೥1݄14೔౔༵೔

Slide 32

Slide 32 text

DEBUGGER then installed it 12೥1݄14೔౔༵೔

Slide 33

Slide 33 text

DEBUGGER then repeated a couple of times because I’m a “throw everything til something sticks” kinda guy 12೥1݄14೔౔༵೔

Slide 34

Slide 34 text

DEBUGGER then cleaned up after all that hot mess 12೥1݄14೔౔༵೔

Slide 35

Slide 35 text

DEBUGGER DTrace is great for debugging interactions between programs 12೥1݄14೔౔༵೔

Slide 36

Slide 36 text

DEBUGGER DTrace is great for debugging interactions between YOUR BEAUTIFUL CODE and THE IDIOTS 12೥1݄14೔౔༵೔

Slide 37

Slide 37 text

Perl ɾ5.10.0+: sub-entry, sub-return ɾ5.15.1+: phase-change (${^GLOBAL_PHASE}) ɹ ɾFuture?: string eval, etc. perldoc perldtrace 12೥1݄14೔౔༵೔

Slide 38

Slide 38 text

Perl ɾ5.10.0Ҏ߱: sub-entry, sub-return ɾ5.15.1Ҏ߱: phase-change ɹ ɾকདྷʁ: string eval౳ My first Perl patch! Was simple! perldtrace 12೥1݄14೔౔༵೔

Slide 39

Slide 39 text

QUESTIONS? ೔ຊޠͰ΋̤̠Ͱ͢ʂ slides: http://twitter.com/sartak 12೥1݄14೔౔༵೔