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
Finding out what's *really* going on, with DTrace!
Search
Colin Jones
May 08, 2016
Programming
410
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Finding out what's *really* going on, with DTrace!
A talk from !!Con 2016!
Colin Jones
May 08, 2016
More Decks by Colin Jones
See All by Colin Jones
A Bug's Life: What if `select` is Broken After All?
trptcolin
0
190
Underestimated costs of microservice architectures
trptcolin
3
1.6k
FP vs. OOP: Beyond the Bikeshed
trptcolin
0
470
Diving into the Details with DTrace! (RubyConf 2016 edition)
trptcolin
2
540
Diving into the Details with DTrace
trptcolin
3
540
Adopting FP: the good, the familiar, and the unknown
trptcolin
0
280
Beyond top: Command-Line Monitoring on the JVM (ClojureRemote)
trptcolin
0
170
Beyond top: Command-Line Monitoring on the JVM (JavaOne 2015)
trptcolin
1
700
ZooKeeper: Wait-free coordination for Internet-scale systems
trptcolin
2
230
Other Decks in Programming
See All in Programming
AI時代のUIはどこへ行く?その2!
yusukebe
21
7.1k
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
240
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
260
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.9k
Creating Composable Callables in Contemporary C++
rollbear
0
130
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
130
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
7
4.4k
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
130
AIで効率化できた業務・日常
ochtum
0
130
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
130
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
Featured
See All Featured
Exploring anti-patterns in Rails
aemeredith
3
410
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
190
Become a Pro
speakerdeck
PRO
31
6k
How STYLIGHT went responsive
nonsquared
100
6.2k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Making Projects Easy
brettharned
120
6.7k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
620
AI: The stuff that nobody shows you
jnunemaker
PRO
8
710
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
400
Site-Speed That Sticks
csswizardry
13
1.2k
エンジニアに許された特別な時間の終わり
watany
107
250k
Transcript
Finding out what's really going on, with DTrace! Colin Jones
@trptcolin
What even is DTrace?
system-wide! $ sudo dtrace -qn ' syscall:::entry { @[probefunc, execname]
= count(); } dtrace:::END { trunc(@, 10); printa(@); }'
system-wide! $ sudo dtrace -qn 'syscall:::entry { @[probefunc, execname] =
count(); } dtrace:::END { trunc(@, 10); printa(@); }' ^C read_nocancel dbfseventsd 145 workq_kernreturn mds 164 kevent_qos Google Chrome He 170 psynch_cvwait java 197 gettimeofday java 199 psynch_cvsignal Box Sync 264 psynch_cvwait Box Sync 265 select Box Sync 521 kevent_qos hidd 765 stat64 java 1386
known events! $ sudo dtrace -qn 'mysql*::: { @[probename] =
count(); } dtrace:::END { trunc(@, 10); printa(@); }' ^C query-exec-start 3 query-parse-done 3 query-parse-start 3 query-start 3 select-done 3 select-start 3 net-read-done 18 net-read-start 18 net-write-done 18 net-write-start 18
arbitrary functions! (aka Dynamic tracing) $ sudo dtrace -n 'fbt:mach_kernel::entry
{ self->in = timestamp; } fbt:mach_kernel::return /self->in/ { @ = quantize(timestamp - self->in) }' dtrace: description 'fbt:mach_kernel::entry ' matched 24482 probes ^C value ------------- Distribution ------------- count 256 | 0 512 |@@@@@@@@@@@@@@@@@@@@@@@@ 5591792 1024 |@@@@@@@@@ 2013056 2048 |@@@@@@ 1461593 4096 |@ 321681 8192 | 31373 16384 | 3764 32768 | 2129 65536 | 1331 131072 | 749 262144 | 485 524288 | 394 1048576 | 445 2097152 | 438 4194304 | 395 8388608 | 104 16777216 | 2 33554432 | 0
Weird slowness… it happens
Slooooooooow tests (…sometimes)
Multiple tests, multiple machines
Affects some teammates worse than others
annoying productivity-sapping stressful
Hypotheses?
Use DTrace!
Rule out the usual suspect(s) #!/usr/sbin/dtrace -s #pragma D option
quiet #pragma D option switchrate=10hz dtrace:::BEGIN { printf("%-8s %s\n", "PID", "GC (ms)"); self->start = 0; } hotspot*:::gc-begin { self->start = timestamp; } hotspot*:::gc-end /self->start/ { this->time = (timestamp - self->start) / 1000000; printf("%-8d %-8d\n", pid, this->time); }
Garbage Collection $ sudo gc_time.d PID GC (ms) 40320 9
40320 9 73113 1 73113 1 73113 1 40320 36 73184 1 73184 1 73184 1 40320 9 40320 160 72735 7
CPU? $ sudo dtrace -qn 'profile-997 { @[execname] = count();
}' ^C Alfred 2 1 UserEventAgent 1 mDNSResponder 1 tmux 1 CrashPlanService 2 launchd 2 symptomsd 2 Box Sync 3 Google Drive 3 java 3 Google Chrome 9 systemstatsd 11 iTerm 14 Google Chrome He 24 WindowServer 25 hidd 26 Box Sync Monitor 47 kernel_task 9527
CPU? $ sudo dtrace -qn 'profile-997 /execname=="kernel_task"/ { @[stack()] =
count(); }' ^C [...] kernel`0xffffff80010f3d30+0x358 kernel`0xffffff800158d890+0x793 kernel`kevent+0x44 kernel`unix_syscall64+0x251 kernel`hndl_unix_scall64+0x16 116 kernel`processor_idle+0x107 121 kernel`machine_idle+0x2e0 kernel`call_continuation+0x17 82967
CPU $ sudo dtrace -qn 'profile-997 { @[execname] = count();
}' ^C Alfred 2 1 UserEventAgent 1 mDNSResponder 1 tmux 1 CrashPlanService 2 launchd 2 symptomsd 2 Box Sync 3 Google Drive 3 java 3 Google Chrome 9 systemstatsd 11 iTerm 14 Google Chrome He 24 WindowServer 25 hidd 26 Box Sync Monitor 47 kernel_task 9527
High-level resources CPU Memory Disk Network
Network connections https://github.com/brendangregg/DTrace-book-scripts/blob/master/Chap6/soconnect_mac.d $ sudo soconnect_mac.d PID PROCESS FAM ADDRESS
PORT LAT(us) RESULT 88161 java 2 127.0.0.1 5432 144 Success 88161 java 2 127.0.0.1 5432 171 Success 88161 java 2 127.0.0.1 5432 150 Success 114 AirPlayXPCHelper 2 192.168.1.27 7000 1762 In progress 88161 java 2 127.0.0.1 5432 141 Success 88161 java 2 127.0.0.1 5432 179 Success 88161 java 2 127.0.0.1 5432 137 Success 88161 java 2 72.52.4.119 80 29977 Success 88161 java 2 72.52.4.119 80 42121 Success 88161 java 2 72.52.4.119 80 29471 Success 88161 java 2 72.52.4.119 80 29360 Success 88161 java 2 72.52.4.119 80 34731 Success 88161 java 2 72.52.4.119 80 28824 Success
DNS dtrace:::BEGIN { printf("%-8s %-8s %s\n", "TICK", "ms", "HOST"); timezero
= timestamp; } pid$target::getaddrinfo:entry { self->host = copyinstr(arg0); self->start = timestamp; } pid$target::getaddrinfo:return /self->start/ { this->now = (timestamp - timezero) / 1000000; this->time = (timestamp - self->start) / 1000000; printf("%-8d %-8d %s\n", this->now, this->time, self->host); self->start = 0; self->host = 0; } $ sudo dns_latency.d -p 41161 Password: TICK ms HOST 74450 274 redclay.local 74734 0 redclay.local 105006 30075 someplace.com 145171 30075 someplace.com 145191 1 redclay.local 145192 0 redclay.local 177055 0 example.com 252314 2 redclay.local 252315 0 redclay.local 284392 0 example.com
Now we know what to fix!
What did we learn?
DTrace gets you answers
You can do it!
Where can we learn more?
Brendan Gregg's blog: http://www.brendangregg.com/dtrace.html The DTrace guide http://dtrace.org/guide Read
Scripts that ship with OS X find /usr/bin -name "*.d"
more DTrace scripts https://github.com/brendangregg/DTrace-book-scripts Examples
Extrapolate
Try it out!
Thanks! Colin Jones @trptcolin