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
Learning Dtrace
Search
Outsider
November 21, 2012
Technology
2
3.2k
Learning Dtrace
Presentation at play.node() 2012
Outsider
November 21, 2012
Tweet
Share
More Decks by Outsider
See All by Outsider
당근 개발자 플랫폼은 어떤 문제를 해결하고 있는가?
outsider
1
2.4k
오픈소스에 기여할 때 알면 좋을 개발 프로세스
outsider
0
1.4k
DevOps를 가속화하는 플랫폼 엔지니어링
outsider
0
3k
클라우드 시대에 맞는 사이트 신뢰성 엔지니어
outsider
0
1.3k
디자인에 이어 코딩까지 AI가 프로그램 개발을 척척? : GitHub Copilot, 어디까지 알아보셨나요
outsider
0
1.4k
Citizen 개발기
outsider
0
840
오픈소스 뒤에 메인테이너 있어요
outsider
0
78
오픈소스에 기여할 때 해도 되는 일과 하면 안되는 일
outsider
0
47
Lessons from maintaining Mocha, an open source project
outsider
0
2.9k
Other Decks in Technology
See All in Technology
Money-saving tips for the frugal serverless developer
theburningmonk
0
280
回り回って効いてくる副次的効果としての技術広報/techpr
nishiuma
1
180
DevRelによる信頼構築とデータ駆動で変わるエンジニア採用 / DevRel Trust Building to Data Driven Engineering Hiring
bobtani
1
130
Google Cloudを組織(企業)で運用する時のベストプラクティス × 健康の環境分離戦略 #まるクラ勉強会
yasumuusan
0
170
QA経験のないエンジニアリング マネージャーがQAのカジュアル面談に出て 苦労していること・気づいたこと / scrum fest niigata 2024
yoshikiiida
2
660
Dungeons and Dragons and Rails
joelq
0
230
Blazor WASM × Code-first gRPC で始める C# ⼤統⼀理論
sansantech
PRO
1
500
kcp: Kubernetes APIs Are All You Need #techfeed_live / TechFeed Experts Night 28th
ytaka23
1
190
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
0
2k
能動学習のいろは:書籍「Human-in-the-Loop機械学習」3〜5章
hiroyoshiito
0
290
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
12
7.9k
本当のガバクラ基礎
toru_kubota
0
320
Featured
See All Featured
Infographics Made Easy
chrislema
238
18k
Design by the Numbers
sachag
274
18k
It's Worth the Effort
3n
180
27k
Atom: Resistance is Futile
akmur
260
25k
The Invisible Customer
myddelton
114
12k
Web development in the modern age
philhawksworth
203
10k
Side Projects
sachag
451
41k
4 Signs Your Business is Dying
shpigford
176
21k
The Cult of Friendly URLs
andyhume
74
5.7k
How to Ace a Technical Interview
jacobian
273
22k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
221
21k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
20
1.8k
Transcript
Learning Dtrace 2012.11.20 Outsider at
DTrace is a comprehensive dynamic tracing framework created by Sun
Microsystems for troubleshooting kernel and application problems on production systems in real time. http://dtrace.org/blogs/about/dtracepony/
DTrace is a comprehensive dynamic tracing framework created by Sun
Microsystems for troubleshooting kernel and application problems on production systems in real time. http://dtrace.org/blogs/about/dtracepony/
DTrace is a comprehensive dynamic tracing framework created by Sun
Microsystems for troubleshooting kernel and application problems on production systems in real time. http://dtrace.org/blogs/about/dtracepony/
DTrace is a comprehensive dynamic tracing framework created by Sun
Microsystems for troubleshooting kernel and application problems on production systems in real time. http://dtrace.org/blogs/about/dtracepony/
DTrace is a comprehensive dynamic tracing framework created by Sun
Microsystems for troubleshooting kernel and application problems on production systems in real time. http://dtrace.org/blogs/about/dtracepony/
http://www.flickr.com/photos/ghost_of_kuji/370072145 Bryan Cantrill Mike Shapiro Adam Leventhal
Originally developed for 2003
Open-sourced in 2005 http://www.flickr.com/photos/tinou/171803338
http://www.flickr.com/photos/epu/4299657320 Ported to Unix-like systems
MIT Technology Review 2005 “Innovators Under 35” http://www2.technologyreview.com/tr35/profile.aspx?trid=91
Technology Innovation Awards 2006 Gold Winner http://www.dowjones.com/innovation/ei_winners_2006.html
STUG award 2008 https://www.usenix.org/about/stug
Dive into Dtrace
None
٘о प೯غח زਵ۽ ࢤࢿ ۽؋࣌ীࢲ ࢎਊоמ Probe
Probe List: sudo dtrace -l
Probe ղࠗ ID
Probeܳ ઁҕೞח Ҕ (ex: syscall, profile)
Unix ݽٕա Probe যܻா࣌ ۄ࠳۞ܻ ܴ
Probeо ઓೞח ೣࣻ ܴ
Probe ܴ
sudo dtrace -l -n PROBEܴ
sudo dtrace -l -f FUNCTION
sudo dtrace -l -P PROVIDER
sudo dtrace -l -m MODULE
DScript D Programming Language
.d ഛ ஹੌ೧ࢲ ழօۨ߰ীࢲ प೯ উࢿਸ ਤೠ ਬബࢿ Ѩࢎ ۽؋࣌ীࢲ
উೞѱ प೯ Features
DScript Kernel User DProgram Output Dtrace
probe-description /optional predicate/ { action statements; } 01 02 03
04 05
probe-description /optional predicate/ { action statements; } 01 02 03
04 05 provider:module:function:name (ex: syscall:::entry)
probe-description /optional predicate/ { action statements; } 01 02 03
04 05 दझమ ࢚కܳ ࣻೞח ݺ۸ޙ
probe-description /optional predicate/ { action statements; } 01 02 03
04 05 0 ইפѢա trueݶ action ࣻ೯
begin-end.d BEGIN { trace("begin the beguine"); exit(0); } END {
trace("that's all..."); } 01 02 03 04 05 06 07 08 09
begin-end.d BEGIN { trace("begin the beguine"); exit(0); } END {
trace("that's all..."); } 01 02 03 04 05 06 07 08 09 sudo dtrace -s begin-end.d
timer.d profile:::tick-5sec { trace("5sec timer"); } profile:::tick-800msec { trace("800msec timer");
} 01 02 03 04 05 06 07 08
beer.d int bottles; BEGIN { bottles = 5; } profile:::tick-1sec
/bottles >= 0/ { printf("%d bottles on the wall\n", bottles); printf("%d bottles.\n", bottles); printf("take one down, pass it around\n"); printf("%d bottles on the wall\n\n", bottles); bottles--; } profile:::tick-1sec /bottles < 0/ { exit(0); } END { printf("that's all..."); } 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17
no if-else no loop ?: operator is exist No Flow
Control
process.d proc:::exec-success { printf("%s", execname); } 01 02 03 04
@: aggregation’s prefix name: aggregation’s name key: D expression list
(comma-separated) aggfunc: aggregation function Aggregate @name[key] = aggfunc(args)
count() : ഐപࣻ sum(expr) : അध ч avg(expr) :
അध ಣӐ min(expr) : അध о ч max(expr) : അध о ч quantize(expr) : 2ઁғ ࠼ب࠙ನ lquantize(expr,lower-bound, upper- bound, step-value) : ࢶഋ ࠼ب࠙ನ Aggregate Function
aggr-count.d syscall::read:entry { @counts[execname] = count(); } profile:::tick-5s { exit(0);
} 01 02 03 04 05 06 07 08
aggr-quant.d syscall::read:entry { self->ts = timestamp; } syscall::read:return /self->ts/ {
delta = timestamp - self->ts; @quanttime[execname] = quantize(delta); } profile:::tick-5s { exit(0); } 01 02 03 04 05 06 07 08 09 10 11 12 13 14
Dtrace with Node.js
http://www.flickr.com/photos/abandonedhero/3404826467 OS Requirements -Dtrace -ustack helper
USDT User-Level Statically Defined Tracing landed in node v0.6.7
http://www.flickr.com/photos/jepoirrier/2043728206 Full features work on OpenSolaris
Mac OS Dtrace ustack helper
Linux Dtrace ustack helper
Windows Dtrace ustack helper
http://www.flickr.com/photos/vectorlyme/206472613 node.js is compiled with --with-dtrace
“SunOSীࢲ ഝࢿചغ݅ ܲ दझమীࢶ زೞ ঋח”
Dtrace with node.js on SmartOS of Joyent Demo
server.js var http = require('http'); http.createServer(function(req, res) { res.writeHead(200, {
'Content-Type': 'text/plain' }); res.end('Hello World\n'); }).listen(8124); console.log('Server running!'); 01 02 03 04 05 06 07 08 09
http-server.d BEGIN { printf("%7s %2s %5s %20s (%5s) %8s %s
(%s)\n", "WHO", "FD", "RPORT", "REMOTE", "BUFFR", "METHOD", "URL", "FWDFOR"); } node*:::http-server-request { printf("+SERVER %2d %5d %20s (%5d) %8s %s (%s)\n", args[1]->fd, args[1]->remotePort, args[1]->remoteAddress, args[1]->bufferSize, args[0]->method, args[0]->url, args[0]->forwardedFor); } node*:::http-server-response { printf("-SERVER %2d %5d %20s (%5d)\n", args[0]->fd, args[0]->remotePort, args[0]->remoteAddress, args[0]->bufferSize); } 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21
request-count.d http-server-request { @[args[0]->url]=count() } 01 02 03 04
loop.js new Error().stack; function main() { func1(); } function func1()
{ func2(); } function func2() { (function () { for (;;); })(); } main(); 01 02 03 04 05 06 07 08 09 10 11
profile.d profile-97 /execname == "node" && arg1/ { @[jstack(150, 8000)]
= count(); } tick-10sec { exit(0); } 01 02 03 04 05 06 07 08 09
FlameGraph stack trace visualizer
http://dtrace.org/blogs/brendan/files/2011/12/mysql-flame.png
node-stackvis $ npm install -g stackvis
$ sudo dtrace -s DSCRIPT > INPUT $ stackvis dtrace
flamegraph-svg < INPUT > OUTPUT Make FrameGraph
Alternative on non-OpenSolarises
node-dtrace-provider https://github.com/chrisa/node-dtrace-provider $ npm install dtrace-provider
var d = require('dtrace-provider'); var dtp = d.createDTraceProvider('nodeapp'); var p1
= dtp.addProbe('probe1', 'int', 'int'); var p2 = dtp.addProbe('probe2', 'char *'); dtp.enable(); 01 02 03 04 05
dtp.fire("probe1", function(p) { return [1, 2]; }); dtp.fire("probe2", function(p) {
return ["hello, dtrace via provider", "foo"]; }); 01 02 03 04 05 06
data type : int, char maximum argument : 32 Limitations
interval.js function interval(msg) { console.log(msg); } setInterval(function() { interval('Hello Dtrace');
}, 1000); 01 02 03 04 05 06 07
interval.js interval.js var d = require('dtrace-provider'); var dtp = d.createDTraceProvider('nodeapp');
var p2 = dtp.addProbe('echo', 'char *'); function interval(msg) { dtp.fire('echo', function () { return [msg]; }); console.log(msg); } setInterval(function() { interval('Hello Dtrace'); }, 1000); dtp.enable(); 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
interval.d nodeapp*:::echo { trace(copyinstr(arg0)); } 01 02 03 04
Thank you~ http://blog.outsider.ne.kr
[email protected]
@outsideris