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
3k
오픈소스에 기여할 때 알면 좋을 개발 프로세스
outsider
0
1.6k
DevOps를 가속화하는 플랫폼 엔지니어링
outsider
0
3.5k
클라우드 시대에 맞는 사이트 신뢰성 엔지니어
outsider
0
1.4k
디자인에 이어 코딩까지 AI가 프로그램 개발을 척척? : GitHub Copilot, 어디까지 알아보셨나요
outsider
0
1.4k
Citizen 개발기
outsider
0
910
오픈소스 뒤에 메인테이너 있어요
outsider
0
89
오픈소스에 기여할 때 해도 되는 일과 하면 안되는 일
outsider
0
63
Lessons from maintaining Mocha, an open source project
outsider
0
3k
Other Decks in Technology
See All in Technology
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
640
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
390
アプリエンジニアのためのGraphQL入門.pdf
spycwolf
0
110
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.7k
Platform Engineering for Software Developers and Architects
syntasso
1
520
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
330
SSMRunbook作成の勘所_20241120
koichiotomo
3
170
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
【LT】ソフトウェア産業は進化しているのか? #Agilejapan
takabow
0
100
Zennのパフォーマンスモニタリングでやっていること
ryosukeigarashi
0
230
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
270
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Code Review Best Practice
trishagee
64
17k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
A Philosophy of Restraint
colly
203
16k
4 Signs Your Business is Dying
shpigford
180
21k
Unsuck your backbone
ammeep
668
57k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Happy Clients
brianwarren
98
6.7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
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