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.9k
클라우드 시대에 맞는 사이트 신뢰성 엔지니어
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
_第3回__AIxIoTビジネス共創ラボ紹介資料_20250617.pdf
iotcomjpadmin
0
150
フィンテック養成勉強会#54
finengine
0
160
ハノーバーメッセ2025座談会.pdf
iotcomjpadmin
0
160
Definition of Done
kawaguti
PRO
6
470
Liquid Glass革新とSwiftUI/UIKit進化
fumiyasac0921
0
170
“社内”だけで完結していた私が、AWS Community Builder になるまで
nagisa53
1
340
Observability в PHP без боли. Олег Мифле, тимлид Altenar
lamodatech
0
330
BigQuery Remote FunctionでLooker Studioをインタラクティブ化
cuebic9bic
3
260
Agentic DevOps時代の生存戦略
kkamegawa
1
1.3k
製造業からパッケージ製品まで、あらゆる領域をカバー!生成AIを利用したテストシナリオ生成 / 20250627 Suguru Ishii
shift_evolve
PRO
1
120
AWS Summit Japan 2025 Community Stage - App workflow automation by AWS Step Functions
matsuihidetoshi
1
220
低レイヤを知りたいPHPerのためのCコンパイラ作成入門 完全版 / Building a C Compiler for PHPers Who Want to Dive into Low-Level Programming - Expanded
tomzoh
4
3.1k
Featured
See All Featured
A Tale of Four Properties
chriscoyier
160
23k
RailsConf 2023
tenderlove
30
1.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
Building Adaptive Systems
keathley
43
2.6k
The Cost Of JavaScript in 2023
addyosmani
51
8.4k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Docker and Python
trallard
44
3.4k
How STYLIGHT went responsive
nonsquared
100
5.6k
Documentation Writing (for coders)
carmenintech
71
4.9k
Writing Fast Ruby
sferik
628
61k
For a Future-Friendly Web
brad_frost
179
9.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