learning dtrace
DESCRIPTION
preTRANSCRIPT
![Page 1: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/1.jpg)
LearningDtrace2012.11.20Outsider at
![Page 2: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/2.jpg)
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/
![Page 3: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/3.jpg)
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/
![Page 4: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/4.jpg)
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/
![Page 5: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/5.jpg)
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/
![Page 6: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/6.jpg)
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/
![Page 7: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/7.jpg)
http://www.flickr.com/photos/ghost_of_kuji/370072145
Bryan Cantrill Mike Shapiro Adam Leventhal
![Page 8: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/8.jpg)
Originallydevelopedfor
2003
![Page 9: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/9.jpg)
Open-sourcedin 2005
http://www.flickr.com/photos/tinou/171803338
![Page 10: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/10.jpg)
http://www.flickr.com/photos/epu/4299657320
Ported to Unix-like systems
![Page 11: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/11.jpg)
MITTechnology Review2005
“Innovators Under 35”http://www2.technologyreview.com/tr35/profile.aspx?trid=91
![Page 12: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/12.jpg)
TechnologyInnovationAwards 2006
Gold Winnerhttp://www.dowjones.com/innovation/ei_winners_2006.html
![Page 13: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/13.jpg)
STUG award 2008
https://www.usenix.org/about/stug
![Page 14: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/14.jpg)
Dive into Dtrace
![Page 15: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/15.jpg)
![Page 16: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/16.jpg)
코드가 실행되는 지점동적으로 생성프로덕션에서 사용가능
Probe
![Page 17: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/17.jpg)
Probe List:
sudo dtrace -l
![Page 18: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/18.jpg)
Probe의 내부 ID
![Page 19: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/19.jpg)
Probe를 제공하는 곳(ex: syscall, profile)
![Page 20: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/20.jpg)
Unix 모듈이나Probe의 어플리케이션 라이브러리의 이름
![Page 21: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/21.jpg)
Probe가 존재하는함수의 이름
![Page 22: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/22.jpg)
Probe의 이름
![Page 23: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/23.jpg)
sudo dtrace -l -n PROBE이름
![Page 24: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/24.jpg)
sudo dtrace -l -f FUNCTION
![Page 25: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/25.jpg)
sudo dtrace -l -P PROVIDER
![Page 26: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/26.jpg)
sudo dtrace -l -m MODULE
![Page 27: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/27.jpg)
DScriptD Programming Language
![Page 28: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/28.jpg)
.d 확장자컴파일해서 커널레벨에서 실행안전성을 위한 유효성 검사프로덕션에서 안전하게 실행
Features
![Page 29: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/29.jpg)
DScript
KernelUser
DProgram
Output
Dtrace
![Page 30: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/30.jpg)
probe-description/optional predicate/{ action statements;}
0102030405
![Page 31: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/31.jpg)
probe-description/optional predicate/{ action statements;}
0102030405
provider:module:function:name(ex: syscall:::entry)
![Page 32: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/32.jpg)
probe-description/optional predicate/{ action statements;}
0102030405
시스템의 상태를 수집하는 명령문
![Page 33: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/33.jpg)
probe-description/optional predicate/{ action statements;}
0102030405
0이 아니거나 true면 action 수행
![Page 34: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/34.jpg)
begin-end.dBEGIN { trace("begin the beguine"); exit(0); }END{ trace("that's all...");}
010203040506070809
![Page 35: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/35.jpg)
begin-end.dBEGIN { trace("begin the beguine"); exit(0); }END{ trace("that's all...");}
010203040506070809
sudo dtrace -s begin-end.d
![Page 36: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/36.jpg)
timer.dprofile:::tick-5sec{ trace("5sec timer");}profile:::tick-800msec{ trace("800msec timer");}
0102030405060708
![Page 37: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/37.jpg)
beer.dint 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..."); }
0102030405060708091011121314151617
![Page 38: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/38.jpg)
no if-elseno loop?: operator is exist
No Flow Control
![Page 39: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/39.jpg)
process.dproc:::exec-success{ printf("%s", execname);}
01020304
![Page 40: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/40.jpg)
@: aggregation’s prefixname: aggregation’s namekey: D expression list (comma-separated)aggfunc: aggregation function
Aggregate
@name[key] = aggfunc(args)
![Page 41: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/41.jpg)
count() : 호출횟수sum(expr) : 표현식의 전체 값avg(expr) : 표현식의 평균min(expr) : 표현식 중 가장 작은 값max(expr) : 표현식 중 가장 큰 값quantize(expr) : 2제곱의 빈도분포lquantize(expr,lower-bound, upper-bound, step-value) : 선형 빈도분포
Aggregate Function
![Page 42: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/42.jpg)
aggr-count.dsyscall::read:entry{ @counts[execname] = count();}profile:::tick-5s{ exit(0);}
0102030405060708
![Page 43: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/43.jpg)
aggr-quant.dsyscall::read:entry{ self->ts = timestamp;}syscall::read:return/self->ts/{ delta = timestamp - self->ts; @quanttime[execname] = quantize(delta);}profile:::tick-5s{ exit(0);}
0102030405060708091011121314
![Page 44: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/44.jpg)
Dtracewith Node.js
![Page 45: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/45.jpg)
http://www.flickr.com/photos/abandonedhero/3404826467
OS Requirements-Dtrace-ustack helper
![Page 46: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/46.jpg)
USDTUser-Level Statically Defined Tracing
landed in node v0.6.7
![Page 47: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/47.jpg)
http://www.flickr.com/photos/jepoirrier/2043728206
Full featureswork on OpenSolaris
![Page 48: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/48.jpg)
Mac OS
Dtraceustack helper
![Page 49: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/49.jpg)
Linux
Dtraceustack helper
![Page 50: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/50.jpg)
WindowsDtrace
ustack helper
![Page 51: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/51.jpg)
http://www.flickr.com/photos/vectorlyme/206472613
node.js is compiled with
--with-dtrace
![Page 52: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/52.jpg)
“SunOS에서 활성화되지만 다른 시스템에선 동작하지 않는다”
![Page 53: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/53.jpg)
Dtrace with node.json SmartOS of Joyent
Demo
![Page 54: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/54.jpg)
server.jsvar 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!');
010203040506070809
![Page 55: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/55.jpg)
http-server.dBEGIN{ 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);}
010203040506070809101112131415161718192021
![Page 56: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/56.jpg)
request-count.dhttp-server-request{ @[args[0]->url]=count()}
01020304
![Page 57: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/57.jpg)
loop.jsnew Error().stack;
function main() { func1(); }function func1() { func2(); }
function func2() { (function () { for (;;); })();}main();
0102030405060708091011
![Page 58: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/58.jpg)
profile.dprofile-97/execname == "node" && arg1/{ @[jstack(150, 8000)] = count();}tick-10sec{ exit(0);}
010203040506070809
![Page 59: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/59.jpg)
FlameGraphstack trace visualizer
![Page 60: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/60.jpg)
http://dtrace.org/blogs/brendan/files/2011/12/mysql-flame.png
![Page 61: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/61.jpg)
node-stackvis
$ npm install -g stackvis
![Page 62: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/62.jpg)
$ sudo dtrace -s DSCRIPT > INPUT$ stackvis dtrace flamegraph-svg < INPUT > OUTPUT
Make FrameGraph
![Page 63: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/63.jpg)
Alternativeon non-OpenSolarises
![Page 64: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/64.jpg)
node-dtrace-providerhttps://github.com/chrisa/node-dtrace-provider
$ npm install dtrace-provider
![Page 65: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/65.jpg)
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();
0102030405
![Page 66: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/66.jpg)
dtp.fire("probe1", function(p) { return [1, 2];});dtp.fire("probe2", function(p) { return ["hello, dtrace via provider", "foo"];});
010203040506
![Page 67: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/67.jpg)
data type : int, charmaximum argument : 32
Limitations
![Page 68: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/68.jpg)
interval.jsfunction interval(msg) { console.log(msg);}
setInterval(function() { interval('Hello Dtrace');}, 1000);
01020304050607
![Page 69: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/69.jpg)
interval.jsinterval.jsvar 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();
010203040506070809101112131415
![Page 70: Learning Dtrace](https://reader034.vdocuments.us/reader034/viewer/2022052508/559457ae1a28ab512f8b4716/html5/thumbnails/70.jpg)
interval.dnodeapp*:::echo{ trace(copyinstr(arg0));}
01020304