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
290
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
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
350
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
350
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
240
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
0
160
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
200
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
500
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.7k
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
390
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
150
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
220
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1.1k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
670
Agile that works and the tools we love
rasmusluckow
331
22k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
410
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
310
Done Done
chrislema
186
16k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
460
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
220
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
56k
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