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.3k
Learning Dtrace
Presentation at play.node() 2012
Outsider
November 21, 2012
Tweet
Share
More Decks by Outsider
See All by Outsider
GitHub Actions의 다양한 기능 활용하기 - GitHub Universe '24 Recap
outsider
0
940
당근 개발자 플랫폼은 어떤 문제를 해결하고 있는가?
outsider
1
3.5k
오픈소스에 기여할 때 알면 좋을 개발 프로세스
outsider
0
1.7k
DevOps를 가속화하는 플랫폼 엔지니어링
outsider
0
3.8k
클라우드 시대에 맞는 사이트 신뢰성 엔지니어
outsider
0
1.6k
디자인에 이어 코딩까지 AI가 프로그램 개발을 척척? : GitHub Copilot, 어디까지 알아보셨나요
outsider
0
1.6k
Citizen 개발기
outsider
0
980
오픈소스 뒤에 메인테이너 있어요
outsider
0
120
오픈소스에 기여할 때 해도 되는 일과 하면 안되는 일
outsider
0
91
Other Decks in Technology
See All in Technology
doda開発 生成AI元年宣言!自家製AIエージェントから始める生産性改革 / doda Development Declaration of the First Year of Generated AI! Productivity Reforms Starting with Home-grown AI Agents
techtekt
0
180
Clineを含めたAIエージェントを 大規模組織に導入し、投資対効果を考える / Introducing AI agents into your organization
i35_267
4
1k
Observability в PHP без боли. Олег Мифле, тимлид Altenar
lamodatech
0
160
初めてのAzure FunctionsをClaude Codeで作ってみた / My first Azure Functions using Claude Code
hideakiaoyagi
1
140
25分で解説する「最小権限の原則」を実現するための AWS「ポリシー」大全
opelab
3
420
IAMのマニアックな話 2025を執筆して、 見えてきたAWSアカウント管理の現在
nrinetcom
PRO
4
620
本部長の代わりに提案書レビュー! KDDI営業が毎日使うAIエージェント「A-BOSS」開発秘話
minorun365
PRO
14
2k
米国国防総省のDevSecOpsライフサイクルをAWSのセキュリティサービスとOSSで実現
syoshie
0
330
「どこにある?」の解決。生成AI(RAG)で効率化するガバメントクラウド運用
toru_kubota
2
450
RubyOnRailsOnDevin+α / DevinMeetupJapan#2
ginkouno
0
820
監視のこれまでとこれから/sakura monitoring seminar 2025
fujiwara3
8
1.4k
What's new in OpenShift 4.19
redhatlivestreaming
1
410
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1370
200k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Building Adaptive Systems
keathley
43
2.6k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
The Cult of Friendly URLs
andyhume
79
6.4k
Building an army of robots
kneath
306
45k
Scaling GitHub
holman
459
140k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
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