Guido García · @palmerabollo · 2014
"DTrace is a magician that conjures up rainbows, ponies and unicorns — and does it all entirely safely and in production!" – dtrace.org
"A probe is a location or activity to which DTrace can bind a request to perform a set of actions, like recording a stack trace or the argument to a function"
CPU ID FUNCTION:NAME
3 1218 __mac_execve:exec-success login
0 1140 posix_spawn:exec-success mdworker
1 1218 __mac_execve:exec-success zsh
2 1218 __mac_execve:exec-success git
2 1218 __mac_execve:exec-success git
...
https://google.com/?q=dtrace%20oneliners
http://brendangregg.com/DTrace/dtrace_oneliners.txt
http://solarisinternals.com/wiki/index.php/DTrace_Topics_One_Liner
BEGIN { inicialización }
selector_sonda / filtros /
{
acciones, acceso a información
}
END { terminación }
syscall::open:entry /pid==$target/{printf("%s", copyinstr(arg0));}
# dtrace -n 'node*:::http-server-request {printf("%s %s", copyinstr(arg4), copyinstr(arg5))}'
dtrace: description 'node*:::http-server-request' matched 2 probes
CPU ID FUNCTION:NAME
2 5296 _DTRACE_HTTP_SERVER_REQUEST:http-server-request GET /bubbles
2 5296 _DTRACE_HTTP_SERVER_REQUEST:http-server-request GET /bubbles
0 5296 _DTRACE_HTTP_SERVER_REQUEST:http-server-request GET /bubbles
0 5296 _DTRACE_HTTP_SERVER_REQUEST:http-server-request GET /bubbles
...
# dtrace -n 'node*:::http-server-request {@[copyinstr(arg2)] = count()}'
dtrace: description 'node*:::http-server-request ' matched 1 probe
^C
10.95.61.78 124
10.95.61.93 34
#!/usr/sbin/dtrace -s node*:::http-server-request /pid == $target/ { ip = copyinstr(arg2); rport = arg3; reqs[ip, rport] = timestamp; }
node*:::http-server-response /reqs[copyinstr(arg1), arg2]/ { latency = (timestamp - reqs[copyinstr(arg1), arg2]) / 1000000; @result = quantize(latency); reqs[copyinstr(arg1), arg2] = 0; }
# dtrace -s nodelatency.d -p 50026
dtrace: script './nodelatency.d' matched 4 probes
^C
value ------------- Distribution ------------- count
64 | 0
128 |@@ 7
256 |@@@@@@@@@@@ 33
512 |@@@@@@@@@@@@@@@@@@@@@@ 65
1024 |@@@@@@@@@@@ 32
2048 | 0
# bunyan -p 50026
...
[2014-06-12T08:15:16] DEBUG: myapp/50026 on tizona: run cleanup 1 bubbles
[2014-06-12T08:15:46] DEBUG: myapp/50026 on tizona: run cleanup 0 bubbles
...
myprovider:::myprobe
var dtrace = require('dtrace-provider'); var provider = dtrace.createDTraceProvider('myprovider'); var probe = provider.addProbe('myprobe', 'int', 'char *');
provider.enable(); ... probe.fire(function () { return [1, 'foo'] });
5 LOC
#!/usr/sbin/dtrace -s node*:::gc-start
{ trace("gc start"); self->ts = timestamp; } node*:::gc-done /self->ts/ { @result = quantize((timestamp - self->ts) / 1000); self->ts = 0; }
# sudo dtrace -s gc.d
dtrace: script 'gc.d' matched 4 probes
CPU ID FUNCTION:NAME
3 4485 _dtrace_gc_start_GCCallbackFlagsE:gc-start gc start
...
^C
value ------------- Distribution ------------- count
256 | 0
512 |@ 1
1024 |@@@@@@@@@@@@@@@@ 12
2048 |@@@@@@@@@@@@@@@ 11
4096 |@@@@@ 4
8192 |@ 1
16384 | 0
syscall:::entry/execname == "node"/{ @[probefunc] = count() }tick-5sec
{ printa(@); clear(@); }
syscall::open:return/execname == "node" && errno == ENOENT/{ trace(pid); raise(SIGABRT); exit(0); }
proc:::signal-send/args[2] == SIGSEGV/{ trace(pid); system("gcore %d", pid); exit(0); }
dtrace -n 'mysql*:::query-start{ trace(copyinstr(arg0)) }'
...
0 30046 _enum_server_command:query-start
select * from Configuration where name like 'mail%'
0 30046 _enum_server_command:query-start
SHOW FULL COLUMNS FROM `Configuration` FROM `BillyDB`
0 30046 _enum_server_command:query-start
drop table Configuration
:::query-start{self->query = arg0}:::query-done/self->query && arg0 == 1/{trace(copyinstr(self->query));self->query = NULL}
providers https://wikis.oracle.com/display/DTrace/Providers
http://joyent.com/developers/node/debug
http://blog.nodejs.org/2012/04/25/profiling-node-js/
http://www.solarisinternals.com/wiki/index.php/DTrace_Topics_Overhead
http://dtrace.org/blogs/brendan/2011/02/18/dtrace-pid-provider-overhead/
http://joyent.com/blog/understanding-dtrace-ustack-helpers