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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
ふつうのFeature Flag実践入門
irof
7
3.9k
Oxcを導入して開発体験が向上した話
yug1224
4
310
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
110
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
260
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
180
RTSPクライアントを自作してみた話
simotin13
0
600
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
130
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
170
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
340
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
5.8k
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Exploring anti-patterns in Rails
aemeredith
3
410
WCS-LA-2024
lcolladotor
0
630
30 Presentation Tips
portentint
PRO
1
320
Become a Pro
speakerdeck
PRO
31
6k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
65
55k
4 Signs Your Business is Dying
shpigford
187
22k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
What's in a price? How to price your products and services
michaelherold
247
13k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
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