Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Learning Dtrace

Outsider
November 21, 2012

Learning Dtrace

Presentation at play.node() 2012

Outsider

November 21, 2012
Tweet

More Decks by Outsider

Other Decks in Technology

Transcript

  1. 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/
  2. 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/
  3. 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/
  4. 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/
  5. 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/
  6. probe-description /optional predicate/ { action statements; } 01 02 03

    04 05 provider:module:function:name (ex: syscall:::entry)
  7. probe-description /optional predicate/ { action statements; } 01 02 03

    04 05 दझమ੄ ࢚కܳ ࣻ૘ೞח ݺ۸ޙ
  8. begin-end.d BEGIN { trace("begin the beguine"); exit(0); } END {

    trace("that's all..."); } 01 02 03 04 05 06 07 08 09
  9. 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
  10. 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
  11. @: aggregation’s prefix name: aggregation’s name key: D expression list

    (comma-separated) aggfunc: aggregation function Aggregate @name[key] = aggfunc(args)
  12. count() : ഐ୹പࣻ sum(expr) : ಴അध੄ ੹୓ ч avg(expr) :

    ಴അध੄ ಣӐ min(expr) : ಴അध ઺ о੢ ੘਷ ч max(expr) : ಴അध ઺ о੢ ௾ ч quantize(expr) : 2ઁғ੄ ࠼ب࠙ನ lquantize(expr,lower-bound, upper- bound, step-value) : ࢶഋ ࠼ب࠙ನ Aggregate Function
  13. 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
  14. 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
  15. 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
  16. 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
  17. profile.d profile-97 /execname == "node" && arg1/ { @[jstack(150, 8000)]

    = count(); } tick-10sec { exit(0); } 01 02 03 04 05 06 07 08 09
  18. $ sudo dtrace -s DSCRIPT > INPUT $ stackvis dtrace

    flamegraph-svg < INPUT > OUTPUT Make FrameGraph
  19. 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
  20. 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
  21. 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