├── smartmachine ├── dnsconnect.d ├── gethostbyaddr.d ├── mysqld_pid_slow.d ├── libmysql_pid_snoop.d ├── mysqld_pid_latency.d ├── libmysql_pid_connect.d ├── mysqld_pid_fslatency.d ├── mysqld_pid_syscall_offcpu.d ├── mysqld_pid_fslatency_slowlog0.d ├── mysqld_pid_fslatency_slowlog1.d └── README ├── kvm ├── README └── kvmexitstat.d ├── system ├── xcalls.d ├── koncpu.d ├── cpuutil.d ├── rcapd_stat.d ├── capslat.d ├── gethostbyaddr.d ├── displat.d ├── cv_wakeup_slow.d ├── zonecapslat.d ├── zonecalls.d ├── zonedisplat.d ├── zonetop.d └── zonecpu.d ├── erlang ├── erlang_msgqueue.d ├── erlang_pnext.d ├── erlang_pspawn.d ├── erlang_heapshrink.d ├── erlang_niftime.d ├── erlang_plife.d ├── erlang_msgsize.d ├── erlang_biftime.d ├── erlang_psched_thr.d ├── erlang_plifefunc.d ├── beam_realloc.d ├── erlang_localsend.d ├── erlang_gc.d ├── riak_1blat.d ├── bashobench_1blat.d ├── erlang_plslower.d └── erlang_punslower.d ├── mysql ├── README ├── mclt10k.d ├── libmysql_pid_qtime.d ├── mysqld_pid_latency.d ├── libmysql_pid_connect.d ├── libmysql_pid_snoop.d ├── mysqld_latency.d ├── innodb_thread_concurrency.d ├── mysqld_command.d ├── mysqld_pid_querys.d ├── mysqld_pid_latency_stat.d ├── mysqld_pid_filesort.d ├── mysqld_pid_slow.d ├── mysqld_pid_avg.d ├── mysqld_pid_fslatency.d ├── mysqld_pid_offcpu.d ├── mysqld_zfs_iolatency.d ├── innodb_pid_iolatency.d ├── mysqld_pid_syscall_offcpu.d ├── mysqld_pid_fslatency_slowlog0.d ├── mysqld_pid_fslatency_slowlog1.d ├── innodb_pid_ioslow.d └── mysqld_pid_rowerrors.d ├── net ├── macrxstacklat.d ├── ixgbecheck.d ├── tcprefused.d ├── tcpslowstart.d ├── ipdropper.d ├── tcpconnreqmaxq_sdc5.d ├── tcpconnreqmaxq_sdc6.d ├── tcpretranshosts.d ├── tcp-fbt-accept_sdc5.d ├── tcp-fbt-accept_sdc6.d ├── tcplistendrop_sdc5.d ├── tcplistendrop_sdc6.d ├── tcpretransstate.d ├── tcptimewaited.d ├── tcptimewait.d ├── tcpconnreqmaxq-pid_sdc5.d ├── tcpconnreqmaxq-pid_sdc6.d ├── tcpsackretrans.d ├── tcptimretransdropsnoop_sdc6.d ├── tcpretranssnoop_sdc5.d ├── tcpretranssnoop_sdc6.d ├── tcpretransport.d └── dnsconnect.d ├── disk ├── iolatency.d ├── dilt.d ├── dilt10k.d ├── iostacks.d ├── megasaslatency.d ├── ioslow.d └── scsilatencydist.d ├── node.js ├── node_gc.d ├── nodesockread2write.d ├── node_slatency.d ├── node_surls.d ├── README ├── nodesockslower.d ├── nslt10k.d ├── nodeslower.d └── nodecslower.d ├── go ├── go_maincounts.txt ├── README ├── go_stat.txt ├── go_maincounts.d ├── go_mainlatency.d ├── go_stat.d ├── go_funccounts.d ├── go_pkgcounts.d ├── go_mainflow.txt ├── go_mainflow.d ├── go_flow.d ├── lib │ └── go.d ├── oneliners.txt ├── go_pkgcounts.txt ├── go_funccounts.txt └── go_mainlatency.txt ├── README.md ├── locks ├── umutexmax.d └── umutexsum.d ├── postgres ├── postgres_latency.d ├── postgres_sort.d ├── ptlt10k.d └── postgres_slower.d ├── apache ├── httpd_latency.d ├── httpd_urls.d └── httpdslower.d ├── fs ├── sollife.d └── solvfssnoop.d ├── zfs ├── ziostacks.d ├── ziocreatestacks.d ├── ziowait.d ├── zilt10k.d ├── metaslab_free.d ├── zfsdist.d ├── spasync.d ├── zfswhozone.d ├── zfsslowzone.d └── zfsslower.d └── redis ├── redislat.d └── redisslower.d /smartmachine/dnsconnect.d: -------------------------------------------------------------------------------- 1 | ../net/dnsconnect.d -------------------------------------------------------------------------------- /smartmachine/gethostbyaddr.d: -------------------------------------------------------------------------------- 1 | ../system/gethostbyaddr.d -------------------------------------------------------------------------------- /smartmachine/mysqld_pid_slow.d: -------------------------------------------------------------------------------- 1 | ../mysql/mysqld_pid_slow.d -------------------------------------------------------------------------------- /smartmachine/libmysql_pid_snoop.d: -------------------------------------------------------------------------------- 1 | ../mysql/libmysql_pid_snoop.d -------------------------------------------------------------------------------- /smartmachine/mysqld_pid_latency.d: -------------------------------------------------------------------------------- 1 | ../mysql/mysqld_pid_latency.d -------------------------------------------------------------------------------- /smartmachine/libmysql_pid_connect.d: -------------------------------------------------------------------------------- 1 | ../mysql/libmysql_pid_connect.d -------------------------------------------------------------------------------- /smartmachine/mysqld_pid_fslatency.d: -------------------------------------------------------------------------------- 1 | ../mysql/mysqld_pid_fslatency.d -------------------------------------------------------------------------------- /smartmachine/mysqld_pid_syscall_offcpu.d: -------------------------------------------------------------------------------- 1 | ../mysql/mysqld_pid_syscall_offcpu.d -------------------------------------------------------------------------------- /smartmachine/mysqld_pid_fslatency_slowlog0.d: -------------------------------------------------------------------------------- 1 | ../mysql/mysqld_pid_fslatency_slowlog0.d -------------------------------------------------------------------------------- /smartmachine/mysqld_pid_fslatency_slowlog1.d: -------------------------------------------------------------------------------- 1 | ../mysql/mysqld_pid_fslatency_slowlog1.d -------------------------------------------------------------------------------- /kvm/README: -------------------------------------------------------------------------------- 1 | KVM Scripts 2 | 3 | These were written for analyzing KVM performance on SmartOS 4 | -------------------------------------------------------------------------------- /smartmachine/README: -------------------------------------------------------------------------------- 1 | These are scripts that should execute inside a SmartMachine (Zone). (They are 2 | actually symlinks to other locations in this toolkit.) 3 | -------------------------------------------------------------------------------- /system/xcalls.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * xcalls.d show who and what the CPU cross calls (xcalls) are. 4 | */ 5 | 6 | sysinfo:::xcalls 7 | { 8 | @[strjoin(zonename, strjoin(":", execname)), stack()] = count(); 9 | } 10 | -------------------------------------------------------------------------------- /erlang/erlang_msgqueue.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_msgqueue.d Erlang message queue length. 4 | */ 5 | 6 | erlang*:::message-queued 7 | { 8 | @["qlen"] = quantize(arg2); 9 | } 10 | 11 | profile:::tick-1s 12 | { 13 | printa(@); 14 | trunc(@); 15 | } 16 | -------------------------------------------------------------------------------- /erlang/erlang_pnext.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | 3 | #pragma D option quiet 4 | 5 | dtrace:::BEGIN 6 | { 7 | trace("Tracing process schedule next-function counts. Ctrl-C to end\n"); 8 | } 9 | 10 | erlang*:::process-scheduled 11 | { 12 | @[copyinstr(arg1)] = count(); 13 | } 14 | -------------------------------------------------------------------------------- /system/koncpu.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * koncpu.d sample kernel CPU stacks at a gentle rate (101 Hertz) 4 | * 5 | * From Chapter 12 of the DTrace book. 6 | */ 7 | 8 | profile:::profile-101 9 | { 10 | @["\n on-cpu (count @101hz):", stack()] = count(); 11 | } 12 | -------------------------------------------------------------------------------- /mysql/README: -------------------------------------------------------------------------------- 1 | MySQL Scripts 2 | 3 | mysql_pid_*.d scripts that use the pid provider to trace a single 4 | mysqld instance. 5 | 6 | mysql_*.d scripts that use the mysql provider probes (if available) 7 | to trace all runinng mysqlds. 8 | 9 | innodb_*.d trace innodb internals using the pid provider. 10 | -------------------------------------------------------------------------------- /erlang/erlang_pspawn.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | 3 | #pragma D option quiet 4 | 5 | dtrace:::BEGIN 6 | { 7 | trace("Tracing process schedule next-function counts. Ctrl-C to end\n"); 8 | } 9 | 10 | erlang*:::process-spawn 11 | { 12 | @[copyinstr(arg1)] = count(); 13 | } 14 | 15 | profile:::tick-1s 16 | { 17 | printa(@); 18 | trunc(@); 19 | } 20 | -------------------------------------------------------------------------------- /net/macrxstacklat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * macrxstacklat.d - RX packet latency from receive to free. 4 | * 5 | * work in progress. 6 | */ 7 | 8 | fbt::mac_rx:entry 9 | { 10 | ts[arg2] = timestamp; 11 | } 12 | 13 | fbt::freemsg:entry, 14 | fbt::freeb:entry 15 | /this->t = ts[arg0]/ 16 | { 17 | @["ns"] = quantize(timestamp - this->t); 18 | ts[arg0] = 0; 19 | } 20 | -------------------------------------------------------------------------------- /disk/iolatency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * iolatency.d Show distribution of disk I/O latency. 4 | * 5 | * From Chapter 4 of the DTrace book. 6 | */ 7 | 8 | io:::start 9 | { 10 | start[arg0] = timestamp; 11 | } 12 | 13 | io:::done 14 | /this->start = start[arg0]/ 15 | { 16 | @time["disk I/O latency (ns)"] = quantize(timestamp - this->start); 17 | start[arg0] = 0; 18 | } 19 | -------------------------------------------------------------------------------- /erlang/erlang_heapshrink.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_heapshrink.d Show a distribution of Erlang heap shrink sizes. 4 | * 5 | * See otp/erts/emulator/beam/erlang_dtrace.d for probe details. 6 | */ 7 | 8 | erlang*:::process-heap_shrink 9 | { 10 | @["heap shrink bytes"] = quantize(arg1 - arg2); 11 | } 12 | 13 | profile:::tick-1s 14 | { 15 | printa(@); 16 | trunc(@); 17 | } 18 | -------------------------------------------------------------------------------- /erlang/erlang_niftime.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | 3 | #pragma D option dynvarsize=8m 4 | 5 | erlang*:::nif-entry 6 | { 7 | ts[copyinstr(arg0)] = timestamp; 8 | } 9 | 10 | erlang*:::nif-return 11 | /(this->ts = ts[copyinstr(arg0)]) > 0/ 12 | { 13 | @[copyinstr(arg1), "ns"] = quantize(timestamp - this->ts); 14 | ts[copyinstr(arg0)] = 0; 15 | } 16 | 17 | tick-1s 18 | { 19 | printa(@); trunc(@); 20 | } 21 | -------------------------------------------------------------------------------- /erlang/erlang_plife.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_plife.d Erlang process life span. 4 | */ 5 | 6 | #pragma D option dynvarsize=8m 7 | 8 | erlang*:::process-spawn 9 | { 10 | ts[copyinstr(arg0)] = timestamp; 11 | } 12 | 13 | erlang*:::process-exit 14 | /(this->ts = ts[copyinstr(arg0)]) > 0/ 15 | { 16 | @["ns"] = quantize(timestamp - this->ts); 17 | ts[copyinstr(arg0)] = 0; 18 | } 19 | 20 | profile:::tick-1s 21 | { 22 | printa(@); trunc(@); 23 | } 24 | -------------------------------------------------------------------------------- /node.js/node_gc.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | 3 | #pragma D option quiet 4 | 5 | dtrace:::BEGIN 6 | { 7 | trace("Tracing node.js GC... Ctrl-C for summary.\n"); 8 | } 9 | 10 | node*:::gc-start 11 | { 12 | self->ts = timestamp; 13 | } 14 | 15 | node*:::gc-done 16 | /self->ts/ 17 | { 18 | this->delta = (timestamp - self->ts) / 1000000; 19 | printf("%Y PID %-5d GC %d ms\n", walltimestamp, pid, this->delta); 20 | @["GC (ms) summary:"] = quantize(this->delta); 21 | self->ts = 0; 22 | } 23 | -------------------------------------------------------------------------------- /erlang/erlang_msgsize.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_msgsize.d Erlang message send/receive size (words). 4 | */ 5 | 6 | erlang*:::message-send 7 | { 8 | @[probename, "words"] = quantize(arg2); 9 | } 10 | 11 | erlang*:::message-send-remote 12 | { 13 | @[probename, "words"] = quantize(arg3); 14 | } 15 | 16 | erlang*:::message-receive, 17 | erlang*:::message-queued 18 | { 19 | @[probename, "words"] = quantize((int)arg1); 20 | } 21 | 22 | profile:::tick-1s 23 | { 24 | printa(@); 25 | trunc(@); 26 | } 27 | -------------------------------------------------------------------------------- /node.js/nodesockread2write.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * nodesockread2write.d - time from read() on a socket to 1st write() 4 | */ 5 | 6 | syscall::read:entry 7 | /execname == "node" && fds[arg0].fi_fs == "sockfs"/ 8 | { 9 | self->fd = arg0; 10 | } 11 | 12 | syscall::read:return 13 | /self->fd && arg0 > 0/ 14 | { 15 | self->ts[self->fd] = timestamp; 16 | self->fd = 0; 17 | } 18 | 19 | syscall::write:entry 20 | /self->ts[arg0]/ 21 | { 22 | @["ms"] = quantize((timestamp - self->ts[arg0]) / 1000000); 23 | self->ts[arg0] = 0; 24 | } 25 | -------------------------------------------------------------------------------- /go/go_maincounts.txt: -------------------------------------------------------------------------------- 1 | # ./go_maincounts.d -p 40148 1 2 | Tracing PID 40148; output every 1 secs. 3 | 4 | 2013 Nov 14 23:02:41: 5 | 6 | main.processreq 5657 7 | 8 | 2013 Nov 14 23:02:42: 9 | 10 | main.processreq 6777 11 | 12 | 2013 Nov 14 23:02:43: 13 | 14 | main.processreq 6562 15 | 16 | 2013 Nov 14 23:02:44: 17 | 18 | main.processreq 6496 19 | 20 | [...] 21 | -------------------------------------------------------------------------------- /erlang/erlang_biftime.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_biftime.d Time built-in function (BIF) calls. 4 | * 5 | * See otp/erts/emulator/beam/erlang_dtrace.d for probe details. 6 | */ 7 | 8 | #pragma D option dynvarsize=8m 9 | 10 | erlang*:::bif-entry 11 | { 12 | ts[copyinstr(arg0)] = timestamp; 13 | } 14 | 15 | erlang*:::bif-return 16 | /(this->ts = ts[copyinstr(arg0)]) > 0/ 17 | { 18 | @[copyinstr(arg1), "ns"] = quantize(timestamp - this->ts); 19 | ts[copyinstr(arg0)] = 0; 20 | } 21 | 22 | profile:::tick-1s 23 | { 24 | printa(@); trunc(@); 25 | } 26 | -------------------------------------------------------------------------------- /node.js/node_slatency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * node_slatency.d Summarize node.js HTTP server latency. 4 | * 5 | * Requires the node DTrace provider, and a working version of the node 6 | * translator (/usr/lib/dtrace/node.d). 7 | * 8 | * 25-Jun-2013 Brendan Gregg Created this (lost the originals). 9 | */ 10 | 11 | node*:::http-server-request 12 | { 13 | ts[pid, args[1]->fd] = timestamp; 14 | } 15 | 16 | node*:::http-server-response 17 | /this->start = ts[pid, args[0]->fd]/ 18 | { 19 | @["ns"] = quantize(timestamp - this->start); 20 | ts[pid, args[0]->fd] = 0; 21 | } 22 | -------------------------------------------------------------------------------- /erlang/erlang_psched_thr.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_psched_thr.d Erlang thread scheduled times. 4 | * 5 | * This is based on thread-local variables for efficiency; 6 | * I checked it vs using an associative array keyed on the 7 | * Erlang PID, and there wasn't a difference. 8 | */ 9 | 10 | erlang*:::process-scheduled 11 | { 12 | self->ts = timestamp; 13 | } 14 | 15 | erlang*:::process-unscheduled 16 | /self->ts/ 17 | { 18 | @["ns"] = quantize(timestamp - self->ts); 19 | self->ts = 0; 20 | } 21 | 22 | profile:::tick-1s 23 | { 24 | printa(@); 25 | trunc(@); 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | These are some DTrace tools I've written while debugging performance issues on a SmartOS-based SmartDataCenter (SDC) cloud. SmartOS is based on the illumos-kernel, which is Solaris based. These scripts are not supported. 2 | 3 | The smartmachine directory links to scripts that work within a SmartMachine. All other directories are intended for operators of the cloud to execute from the compute node (global zone). 4 | 5 | Scripts have a suffix to describe where they execute. "_sdc5" and "_sdc6" describe different SDC versions, SDC5 was based on an OpenSolaris kernel, and SDC6 on the illumos kernel. 6 | -------------------------------------------------------------------------------- /net/ixgbecheck.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * ixgbecheck.d - dig out various ixgbe counters. 4 | * 5 | * work in progress. 6 | */ 7 | 8 | fbt::ixgbe_stall_check:entry 9 | { 10 | printf("\n%Y\n", walltimestamp); 11 | printf("\tadapter_stopped:\t%d\n", args[0]->hw.adapter_stopped); 12 | printf("\tmac_type:\t%d\n", args[0]->hw.mac.type); 13 | printf("\treset_if_overtemp:\t%d\n", args[0]->hw.phy.reset_if_overtemp); 14 | printf("\tsmart_speed:\t%d\n", args[0]->hw.phy.smart_speed); 15 | printf("\tmultispeed_fiber:\t%d\n", args[0]->hw.phy.multispeed_fiber); 16 | } 17 | -------------------------------------------------------------------------------- /locks/umutexmax.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * umutexmax.d User-space mutex, summarize max block time. 4 | * 5 | * Prints output every second, for the given PID. 6 | * 7 | * USAGE: ./umutexmax.d -p PID 8 | * 9 | * 17-Jun-2013 Brendan Gregg Created this. 10 | */ 11 | 12 | plockstat$target:::mutex-block 13 | { 14 | self->ts[arg0] = timestamp; 15 | } 16 | 17 | plockstat$target:::mutex-acquire 18 | /self->ts[arg0]/ 19 | { 20 | @["max blocked (ms)"] = max(timestamp - self->ts[arg0]); 21 | self->ts[arg0] = 0; 22 | } 23 | 24 | profile:::tick-1s 25 | { 26 | normalize(@, 1000000); 27 | printa(@); 28 | trunc(@); 29 | } 30 | -------------------------------------------------------------------------------- /erlang/erlang_plifefunc.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_plifefunc.d Erlang process life span, with function. 4 | */ 5 | 6 | #pragma D option dynvarsize=8m 7 | 8 | dtrace:::BEGIN 9 | { 10 | trace("Tracing Erlang process times. Ctrl-C to end.\n"); 11 | } 12 | 13 | erlang*:::process-spawn 14 | { 15 | this->p = copyinstr(arg0); 16 | name[this->p] = copyinstr(arg1); 17 | ts[this->p] = timestamp; 18 | } 19 | 20 | erlang*:::process-exit 21 | /(this->p = copyinstr(arg0)) != NULL && (this->ts = ts[this->p]) > 0/ 22 | { 23 | @[name[this->p], "ns"] = quantize(timestamp - this->ts); 24 | ts[this->p] = 0; 25 | name[this->p] = 0; 26 | } 27 | -------------------------------------------------------------------------------- /net/tcprefused.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcprefused.d Trace refused TCP connect() and accept()s. 4 | * 5 | * This is intended to debug sessions with connection refused errors (getting 6 | * RSTs). It uses the tcp probes that only trace the codepaths related to 7 | * refusing connections (ie, low rate). 8 | */ 9 | 10 | #pragma D option switchrate=5 11 | 12 | tcp:::connect-refused 13 | { 14 | printf("%s -> %s:%d", args[3]->tcps_laddr, 15 | args[3]->tcps_raddr, args[3]->tcps_rport); 16 | } 17 | 18 | tcp:::accept-refused 19 | { 20 | printf("%s -> %s:%d", args[3]->tcps_raddr, 21 | args[3]->tcps_laddr, args[3]->tcps_lport); 22 | } 23 | -------------------------------------------------------------------------------- /erlang/beam_realloc.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * beam_realloc.d erts_alcu_realloc_thr_spec() call statistics. 4 | * 5 | * USAGE: ./beam_realloc.d -p PID 6 | * 7 | * This uses the DTrace pid provider to dynamically trace Erlang/beam.smp 8 | * internals. 9 | */ 10 | 11 | #pragma D option quiet 12 | 13 | dtrace:::BEGIN 14 | { 15 | /* prime for printing */ 16 | @num = sum(0); 17 | @bytes = sum(0); 18 | } 19 | 20 | pid$target::erts_alcu_realloc_thr_spec:entry 21 | { 22 | @num = sum(1); 23 | @bytes = sum(arg3); 24 | } 25 | 26 | profile:::tick-1s 27 | { 28 | printf("%Y ", walltimestamp); 29 | printa("realloc: %4@d calls %@8d bytes\n", @num, @bytes); 30 | clear(@num); 31 | clear(@bytes); 32 | } 33 | -------------------------------------------------------------------------------- /node.js/node_surls.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * node_surls.d node.js server URL summary. 4 | * 5 | * This traces all node processes on the system. 6 | * 7 | * Requires the node DTrace provider, and a working version of the node 8 | * translator (/usr/lib/dtrace/node.d). 9 | * 10 | * 26-Jun-2013 Brendan Gregg Created this. 11 | */ 12 | 13 | #pragma D option quiet 14 | 15 | dtrace:::BEGIN 16 | { 17 | printf("Tracing node server URLs. Summary every 10 secs or Ctrl-C.\n"); 18 | } 19 | 20 | node*:::http-server-request 21 | { 22 | @[args[0]->url] = count(); 23 | } 24 | 25 | profile:::tick-10s 26 | { 27 | printf("\n%Y:\n", walltimestamp); 28 | printa(" %@6d %s\n", @); 29 | trunc(@); 30 | } 31 | -------------------------------------------------------------------------------- /postgres/postgres_latency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * postgres_latency.d Summarize PostgreSQL server transaction latency. 4 | * 5 | * This requires the postgres DTrace provider. It will trace all running 6 | * instances of postgres. 7 | * 8 | * 26-Jun-2013 Brendan Gregg Created this. 9 | */ 10 | 11 | #pragma D option quiet 12 | 13 | dtrace:::BEGIN 14 | { 15 | trace("Tracing postgres server transaction latency. Ctrl-C to end.\n"); 16 | } 17 | 18 | postgres*:::transaction-start 19 | { 20 | self->ts = timestamp; 21 | } 22 | 23 | 24 | postgres*:::transaction-commit, 25 | postgres*:::transaction-abort 26 | /self->ts/ 27 | { 28 | @["ns"] = quantize(timestamp - self->ts); 29 | self->ts = 0; 30 | } 31 | -------------------------------------------------------------------------------- /postgres/postgres_sort.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * postgres_sort.d Summarize PostgreSQL server sort latency. 4 | * 5 | * This requires the postgres DTrace provider. It will trace all running 6 | * instances of postgres. 7 | * 8 | * 26-Jun-2013 Brendan Gregg Created this. 9 | */ 10 | 11 | #pragma D option quiet 12 | 13 | dtrace:::BEGIN 14 | { 15 | trace("Tracing postgres sort latency. Ctrl-C to end.\n"); 16 | } 17 | 18 | postgres*:::sort-start 19 | { 20 | self->ts = timestamp; 21 | self->vts = vtimestamp; 22 | } 23 | 24 | 25 | postgres*:::sort-done 26 | /self->ts/ 27 | { 28 | @["elapsed ns"] = quantize(timestamp - self->ts); 29 | @["CPU ns"] = quantize(vtimestamp - self->vts); 30 | self->ts = 0; 31 | self->vts = 0; 32 | } 33 | -------------------------------------------------------------------------------- /erlang/erlang_localsend.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_localsend.d Measure Erlang local process send time. 4 | * 5 | * I'm not sure this works, as the token_label (arg3) is always 0, 6 | * which I was hoping to use as a unique message ID. 7 | * 8 | * See otp/erts/emulator/beam/erlang_dtrace.d for probe details. 9 | */ 10 | 11 | #pragma D option dynvarsize=8m 12 | 13 | erlang*:::message-send 14 | { 15 | ts[copyinstr(arg1), arg3] = timestamp; 16 | } 17 | 18 | erlang*:::message-receive 19 | /(this->p = copyinstr(arg0)) != NULL && 20 | (this->ts = ts[this->p, arg3]) > 0/ 21 | { 22 | @["ns"] = quantize(timestamp - this->ts); 23 | ts[this->p, arg3] = 0; 24 | } 25 | 26 | profile:::tick-1s 27 | { 28 | printa(@); 29 | trunc(@); 30 | } 31 | -------------------------------------------------------------------------------- /disk/dilt.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * dilt.d Disk I/O Latency Trace. 4 | * 5 | * This emits basic details for consumption by other tools. 6 | * 7 | * 02-Jun-2013 Brendan Gregg Created this. 8 | */ 9 | 10 | #pragma D option quiet 11 | #pragma D option switchrate=2 12 | #pragma D option dynvarsize=8m 13 | 14 | BEGIN 15 | { 16 | printf("ENDTIME(us) LATENCY(us) DIR SIZE(bytes) PROCESS\n"); 17 | start = timestamp; 18 | } 19 | 20 | io:::start 21 | { 22 | ts[arg0] = timestamp; 23 | } 24 | 25 | io:::done 26 | /this->ts = ts[arg0]/ 27 | { 28 | printf("%d %d %s %d %s\n", 29 | (timestamp - start) / 1000, (timestamp - this->ts) / 1000, 30 | args[0]->b_flags & B_READ ? "R" : "W", args[0]->b_bcount, 31 | execname); 32 | ts[arg0] = 0; 33 | } 34 | -------------------------------------------------------------------------------- /erlang/erlang_gc.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_gc.d Time Erlang garbage collect. 4 | * 5 | * See otp/erts/emulator/beam/erlang_dtrace.d for probe details. 6 | */ 7 | 8 | #pragma D option quiet 9 | 10 | dtrace:::BEGIN 11 | { 12 | trace("Tracing Erlang GC time.\n") 13 | } 14 | 15 | erlang*:::gc_major-start, 16 | erlang*:::gc_minor-start 17 | { 18 | /* 19 | * I'm using a thread local variable since erts_garbage_collect() 20 | * like like it begins and ends on the same thread. 21 | */ 22 | self->ts = timestamp; 23 | } 24 | 25 | erlang*:::gc_major-end, 26 | erlang*:::gc_minor-end 27 | /self->ts/ 28 | { 29 | @[probename, "ns"] = quantize(timestamp - self->ts); 30 | } 31 | 32 | profile:::tick-1s 33 | { 34 | printa(@); 35 | trunc(@); 36 | } 37 | -------------------------------------------------------------------------------- /go/README: -------------------------------------------------------------------------------- 1 | DTrace oneliners, scripts (*.d), and example outputs (*.txt) for go lang. 2 | 3 | The lib directory can be sourced for argument translation, and provides 4 | variables goarg0..9 for function arguments. Eg, to frequency count the first 5 | argument to the foo() function: 6 | 7 | dtrace -Llib -n 'pid$target::main.foo:entry { @[goarg0] = count(); }' -p PID 8 | 9 | The go.d file in the lib directory can also be copied into the default DTrace 10 | library search path, which is usually /usr/lib/dtrace, so that "-Llib" is no 11 | longer required. 12 | 13 | NOTE: For these to work, they need a fix for the DTrace pid provider so that 14 | it can handle UTF-8 characters: 15 | https://github.com/joyent/illumos-joyent/commit/4a6f2ba4e313d3ba11ec5fd34d3c18c9c28be355 16 | -------------------------------------------------------------------------------- /node.js/README: -------------------------------------------------------------------------------- 1 | node.js 2 | 3 | Some short scripts for node.js tracing. These require the node DTrace provider, 4 | and a working version of the translator (/usr/lib/dtrace/node.d). 5 | 6 | You should also check out: 7 | 8 | - Robert Mustacchi's post on the node.js DTrace provider: 9 | http://dtrace.org/blogs/rm/2011/03/01/dtrace-probes-for-node-v0-4-x/ 10 | 11 | - Dave Pacheco's nhttpsnoop 12 | https://github.com/davepacheco/nhttpsnoop 13 | 14 | - Dave Pacheco's post on profiling node.js stack traces using DTrace (with my 15 | flame graphs :) 16 | http://dtrace.org/blogs/dap/2012/04/25/profiling-node-js/ 17 | 18 | - Bryan Cantrill's Velocity talk on node.js and DTrace 19 | http://www.slideshare.net/bcantrill/instrumenting-the-realtime-web-nodejs-in-production 20 | -------------------------------------------------------------------------------- /locks/umutexsum.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * umutexsum.d User-space mutex, sum block time by lock. 4 | * 5 | * Prints output every second, for the given PID. 6 | * 7 | * USAGE: ./umutexsum.d -p PID 8 | * 9 | * 17-Jun-2013 Brendan Gregg Created this. 10 | */ 11 | 12 | #pragma D option quiet 13 | 14 | dtrace:::BEGIN 15 | { 16 | printf("Tracing mutex for %d.\n", $target); 17 | } 18 | 19 | plockstat$target:::mutex-block 20 | { 21 | self->ts[arg0] = timestamp; 22 | } 23 | 24 | plockstat$target:::mutex-acquire 25 | /self->ts[arg0]/ 26 | { 27 | @[arg0] = sum(timestamp - self->ts[arg0]); 28 | self->ts[arg0] = 0; 29 | } 30 | 31 | profile:::tick-1s 32 | { 33 | normalize(@, 1000000); 34 | printf(" %10s %s\n", "TBLOCK(ms)", "LOCK"); 35 | printa(" %@10d %6A\n", @); 36 | trunc(@); 37 | } 38 | -------------------------------------------------------------------------------- /erlang/riak_1blat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * riak_1blat.d Riak 1st byte latency.d 4 | * 5 | * This is experimental, and makes assumptions about the operation 6 | * of beam that may be wrong. It attempts to measure the 1st byte 7 | * latency of riak (well, beam.smp), by measuring the time from 8 | * a recv() to a writev() on the same file descriptor. 9 | */ 10 | 11 | syscall::recv:entry 12 | /execname == "beam.smp"/ 13 | { 14 | self->fd1 = arg0 + 1; 15 | } 16 | 17 | syscall::recv:return 18 | /self->fd1/ 19 | { 20 | ts[pid, self->fd1] = timestamp; 21 | self->fd1 = 0; 22 | } 23 | 24 | syscall::writev:entry 25 | /ts[pid, arg0 + 1]/ 26 | { 27 | @["ns"] = quantize(timestamp - ts[pid, arg0 + 1]); 28 | ts[pid, arg0 + 1] = 0; 29 | } 30 | 31 | tick-10s 32 | { 33 | printa(@); trunc(@); 34 | } 35 | -------------------------------------------------------------------------------- /go/go_stat.txt: -------------------------------------------------------------------------------- 1 | # ./go_stat.d -p 40816 2 | TIME main/s syscalls/s TU%CPU 3 | 2013 Nov 14 23:51:01 1726 201421 27 4 | 2013 Nov 14 23:51:02 1890 220661 31 5 | 2013 Nov 14 23:51:03 1905 222235 25 6 | 2013 Nov 14 23:51:04 2121 247734 35 7 | 2013 Nov 14 23:51:05 2862 333939 22 8 | 2013 Nov 14 23:51:06 2844 331744 23 9 | 2013 Nov 14 23:51:07 2385 278526 35 10 | 2013 Nov 14 23:51:08 2805 327147 34 11 | 2013 Nov 14 23:51:09 2187 255410 29 12 | 2013 Nov 14 23:51:10 2436 284318 20 13 | 2013 Nov 14 23:51:11 2120 247321 33 14 | 2013 Nov 14 23:51:12 2211 258045 28 15 | 2013 Nov 14 23:51:13 2257 263416 31 16 | [...] 17 | -------------------------------------------------------------------------------- /apache/httpd_latency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * httpd_latency.d Summarize HTTP server latency. 4 | * 5 | * This requires the httpd DTrace provider, which is available as mod_usdt 6 | * for Apache, and the translators. If they are in not in /usr/lib/dtrace, 7 | * you may need to invoke this with the actual location with -L, eg: 8 | * dtrace -L /opt/local/lib/dtrace -s httpdslower.d 9 | * 10 | * This script will trace all running instances of Apache. 11 | * 12 | * 26-Jun-2013 Brendan Gregg Created this. 13 | */ 14 | 15 | #pragma D option quiet 16 | 17 | dtrace:::BEGIN 18 | { 19 | trace("Tracing HTTP server latency... Hit Ctrl-C to end.\n"); 20 | } 21 | 22 | httpd*:::request-start 23 | { 24 | self->ts = timestamp; 25 | } 26 | 27 | httpd*:::request-done 28 | /self->ts/ 29 | { 30 | @["ns"] = quantize(timestamp - self->ts); 31 | self->ts = 0; 32 | } 33 | -------------------------------------------------------------------------------- /erlang/bashobench_1blat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * bashobench_1blat.d Basho bench 1st byte latency.d 4 | * 5 | * This works by tracing the time from a writev() to a FD, to when the 6 | * first recv() on the same FD completes. These syscalls are an 7 | * implementation detail of Erlang/beam.smp, and may change at any time. 8 | */ 9 | 10 | syscall::writev:entry 11 | /execname == "beam.smp"/ 12 | { 13 | /* key on pid and FD + 1 */ 14 | ts[pid, arg0 + 1] = timestamp; 15 | } 16 | 17 | syscall::recv:entry 18 | /ts[pid, arg0 + 1]/ 19 | { 20 | self->fd1 = arg0 + 1; 21 | } 22 | 23 | syscall::recv:return 24 | /self->fd1 && ts[pid, self->fd1]/ 25 | { 26 | @["ns"] = quantize(timestamp - ts[pid, self->fd1]); 27 | ts[pid, self->fd1] = 0; 28 | } 29 | 30 | syscall::recv:return 31 | /self->fd1/ 32 | { 33 | self->fd1 = 0; 34 | } 35 | 36 | tick-1s 37 | { 38 | printa(@); trunc(@); 39 | } 40 | -------------------------------------------------------------------------------- /apache/httpd_urls.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * httpd_urls.d Summarize HTTP server requests by URL. 4 | * 5 | * This requires the httpd DTrace provider, which is available as mod_usdt 6 | * for Apache, and the translators. If they are in not in /usr/lib/dtrace, 7 | * you may need to invoke this with the actual location with -L, eg: 8 | * dtrace -L /opt/local/lib/dtrace -s httpd_urls.d 9 | * 10 | * This script will trace all running instances of Apache. 11 | * 12 | * 26-Jun-2013 Brendan Gregg Created this. 13 | */ 14 | 15 | #pragma D option quiet 16 | 17 | dtrace:::BEGIN 18 | { 19 | printf("Tracing HTTP server URLs. Summary every 10 secs or Ctrl-C.\n"); 20 | } 21 | 22 | node*:::http-server-response 23 | { 24 | @[args[1]->rq_uri] = count(); 25 | } 26 | 27 | profile:::tick-10s 28 | { 29 | printf("\n%Y:\n", walltimestamp); 30 | printa(" %@6d %s\n", @); 31 | trunc(@); 32 | } 33 | -------------------------------------------------------------------------------- /fs/sollife.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * sollife.d Solaris FS life span. 4 | * 5 | * This prints details of file system create and remove calls, allowing the 6 | * life span of objects to be seen. 7 | * 8 | * This is from the DTrace book, chapter 5. See http://www.dtracebook.com. 9 | * 10 | * 18-Jun-2010 Brendan Gregg Created this. 11 | */ 12 | 13 | #pragma D option quiet 14 | #pragma D option switchrate=10hz 15 | 16 | dtrace:::BEGIN 17 | { 18 | printf("%-12s %6s %6s %-12.12s %-12s %s\n", "TIME(ms)", "UID", 19 | "PID", "PROCESS", "CALL", "PATH"); 20 | } 21 | 22 | /* see /usr/include/sys/vnode.h */ 23 | 24 | fbt::fop_create:entry, 25 | fbt::fop_remove:entry 26 | { 27 | printf("%-12d %6d %6d %-12.12s %-12s %s/%s\n", 28 | timestamp / 1000000, uid, pid, execname, probefunc, 29 | args[0]->v_path != NULL ? stringof(args[0]->v_path) : "", 30 | stringof(arg1)); 31 | } 32 | -------------------------------------------------------------------------------- /node.js/nodesockslower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * nodesockslower.d - time from read() on a socket to 1st write() 4 | * 5 | * USAGE: ./nodesockslower.d [min_ms] 6 | */ 7 | 8 | #pragma D option quiet 9 | #pragma D option defaultargs 10 | #pragma D option switchrate=5 11 | 12 | dtrace:::BEGIN 13 | { 14 | min_ns = $1 * 1000000; 15 | printf("Tracing node.js socket returns slower than %d ms\n", $1); 16 | } 17 | 18 | syscall::read:entry 19 | /execname == "node" && fds[arg0].fi_fs == "sockfs"/ 20 | { 21 | self->fd = arg0; 22 | } 23 | 24 | syscall::read:return 25 | /self->fd && arg0 > 0/ 26 | { 27 | self->ts[self->fd] = timestamp; 28 | self->fd = 0; 29 | } 30 | 31 | syscall::write:entry 32 | /self->ts[arg0] && 33 | (this->delta = timestamp - self->ts[arg0]) > min_ns/ 34 | { 35 | printf("%Y %d ms\n", walltimestamp, this->delta / 1000000); 36 | } 37 | 38 | syscall::write:entry 39 | /self->ts[arg0]/ 40 | { 41 | self->ts[arg0] = 0; 42 | } 43 | -------------------------------------------------------------------------------- /go/go_maincounts.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * gomaincounts.d Summarize main package function call counts 4 | * 5 | * USAGE: gomaincounts.d -p PID [interval] 6 | * 7 | * This traces all functions in the main package in go. 8 | * 9 | * An optional interval can be provided, which will print a summary 10 | * every interval seconds. 11 | */ 12 | 13 | #pragma D option defaultargs 14 | #pragma D option quiet 15 | 16 | dtrace:::BEGIN 17 | { 18 | interval = $1; 19 | sec = 0; 20 | } 21 | 22 | dtrace:::BEGIN 23 | /interval/ 24 | { 25 | printf("Tracing PID %d; output every %d secs.\n", $target, interval); 26 | } 27 | 28 | dtrace:::BEGIN 29 | /!interval/ 30 | { 31 | printf("Tracing PID %d; Ctrl-C to stop.\n", $target); 32 | } 33 | 34 | pid$target::main.*:entry 35 | { 36 | @[probefunc] = count(); 37 | } 38 | 39 | profile:::tick-1s 40 | /interval && ++sec == interval/ 41 | { 42 | sec = 0; 43 | printf("\n%Y:\n", walltimestamp); 44 | printa(@); 45 | trunc(@); 46 | } 47 | -------------------------------------------------------------------------------- /disk/dilt10k.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * dilt10k.d Disk I/O Latency Trace. 4 | * 5 | * This emits basic details for consumption by other tools. It ideally captures 6 | * at least 10,000 I/O. It has a 15 minute timeout if that is not possible. 7 | * 8 | * 25-Jun-2013 Brendan Gregg Created this. 9 | */ 10 | 11 | #pragma D option quiet 12 | #pragma D option switchrate=2 13 | #pragma D option dynvarsize=8m 14 | 15 | BEGIN 16 | { 17 | printf("ENDTIME(us) LATENCY(us) DIR SIZE(bytes) PROCESS\n"); 18 | start = timestamp; 19 | n = 0; 20 | } 21 | 22 | io:::start 23 | { 24 | ts[arg0] = timestamp; 25 | } 26 | 27 | io:::done 28 | /this->ts = ts[arg0]/ 29 | { 30 | printf("%d %d %s %d %s\n", 31 | (timestamp - start) / 1000, (timestamp - this->ts) / 1000, 32 | args[0]->b_flags & B_READ ? "R" : "W", args[0]->b_bcount, 33 | execname); 34 | ts[arg0] = 0; 35 | } 36 | 37 | io:::start 38 | /n++ > 10100/ 39 | { 40 | exit(0); 41 | } 42 | 43 | profile:::tick-15m { exit(0); } 44 | -------------------------------------------------------------------------------- /go/go_mainlatency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * gomainlatency.d Summarize main package function latency distributions 4 | * 5 | * USAGE: gomainlatency.d -p PID [interval] 6 | * 7 | * An optional interval can be provided, which will print a summary 8 | * every interval seconds. 9 | */ 10 | 11 | #pragma D option defaultargs 12 | #pragma D option quiet 13 | 14 | dtrace:::BEGIN 15 | { 16 | interval = $1; 17 | sec = 0; 18 | } 19 | 20 | dtrace:::BEGIN 21 | /interval/ 22 | { 23 | printf("Tracing PID %d; output every %d secs.\n", $target, interval); 24 | } 25 | 26 | dtrace:::BEGIN 27 | /!interval/ 28 | { 29 | printf("Tracing PID %d; Ctrl-C to stop.\n", $target); 30 | } 31 | 32 | pid$target::main.*:entry 33 | { 34 | self->ts = timestamp; 35 | } 36 | 37 | pid$target::main.*:return 38 | /self->ts/ 39 | { 40 | @[probefunc, "ns"] = quantize(timestamp - self->ts); 41 | } 42 | 43 | profile:::tick-1s 44 | /interval && ++sec == interval/ 45 | { 46 | sec = 0; 47 | printf("%Y:\n", walltimestamp); 48 | printa(@); 49 | trunc(@); 50 | } 51 | -------------------------------------------------------------------------------- /erlang/erlang_plslower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_plslower.d Erlang process life span slower than threshold. 4 | * 5 | * USAGE: ./erlang_plslower.d [min_ms] # defaults to 1 ms 6 | * 7 | * 12-Jun-2013 Brendan Gregg Created this. 8 | */ 9 | 10 | #pragma D option dynvarsize=8m 11 | #pragma D option quiet 12 | #pragma D option switchrate=4 13 | 14 | dtrace:::BEGIN 15 | { 16 | min_ns = $1 ? $1 * 1000000 : 1000000; 17 | printf("Tracing Erlang process times slower than %d ms.\n", 18 | min_ns / 1000000); 19 | } 20 | 21 | erlang*:::process-spawn 22 | { 23 | this->p = copyinstr(arg0); 24 | name[this->p] = copyinstr(arg1); 25 | ts[this->p] = timestamp; 26 | } 27 | 28 | erlang*:::process-exit 29 | /(this->p = copyinstr(arg0)) != NULL && 30 | (this->ts = ts[this->p]) && 31 | (this->d = (timestamp - this->ts)) > min_ns/ 32 | { 33 | printf("%Y %6d ms: %s\n", walltimestamp, this->d / 1000000, 34 | name[this->p]); 35 | } 36 | 37 | erlang*:::process-exit 38 | /this->p != NULL/ 39 | { 40 | ts[this->p] = 0; 41 | name[this->p] = 0; 42 | } 43 | -------------------------------------------------------------------------------- /go/go_stat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * go_stat.d go status tool 4 | * 5 | * USAGE: go_stat.d -p PID [interval] 6 | * 7 | * COLUMNS: 8 | * 9 | * main main package functions 10 | * syscalls system calls 11 | * TU%CPU total percent CPU in user-mode 12 | * 13 | * NOTE: the 14 | * If an interval is not provided, this defaults to 1 second. 15 | */ 16 | 17 | #pragma D option defaultargs 18 | #pragma D option quiet 19 | 20 | dtrace:::BEGIN 21 | { 22 | interval = $1 ? $1 : 1; 23 | sec = 0; 24 | printf("%-20s %10s %10s %10s\n", "TIME", "main/s", "syscalls/s", 25 | "TU%CPU"); 26 | main = 0; syscalls = 0; oncpu = 0; 27 | } 28 | 29 | pid$target:a.out:main.*:entry { main++; } 30 | syscall:::entry /pid == $target/ { syscalls++; } 31 | profile-100 /arg1 && pid == $target/ { oncpu++; } 32 | 33 | profile:::tick-1s 34 | /interval && ++sec == interval/ 35 | { 36 | sec = 0; 37 | printf("%-20Y %10d %10d %10d\n", walltimestamp, 38 | main / interval, syscalls / interval, oncpu / interval); 39 | main = 0; syscalls = 0; oncpu = 0; 40 | } 41 | -------------------------------------------------------------------------------- /go/go_funccounts.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * go_funccounts.d Summarize function call counts 4 | * 5 | * USAGE: gofunccounts.d -p PID [interval] 6 | * 7 | * This traces all functions in all packages in go. 8 | * 9 | * WARNING: For busy programs, this is likely to cause significant overhead, 10 | * slowing the target. 11 | * 12 | * An optional interval can be provided, which will print a summary 13 | * every interval seconds. 14 | */ 15 | 16 | #pragma D option defaultargs 17 | #pragma D option quiet 18 | 19 | dtrace:::BEGIN 20 | { 21 | interval = $1; 22 | sec = 0; 23 | } 24 | 25 | dtrace:::BEGIN 26 | /interval/ 27 | { 28 | printf("Tracing PID %d; output every %d secs.\n", $target, interval); 29 | } 30 | 31 | dtrace:::BEGIN 32 | /!interval/ 33 | { 34 | printf("Tracing PID %d; Ctrl-C to stop.\n", $target); 35 | } 36 | 37 | pid$target:a.out::entry 38 | { 39 | @[probefunc] = count(); 40 | } 41 | 42 | profile:::tick-1s 43 | /interval && ++sec == interval/ 44 | { 45 | sec = 0; 46 | printf("\n%Y:\n", walltimestamp); 47 | printa(@); 48 | trunc(@); 49 | } 50 | -------------------------------------------------------------------------------- /net/tcpslowstart.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpslowstart.d Show the in-effect slow start MSS value. 4 | * 5 | * This traces the congestion window size in terms of MSS for the first 6 | * sent data packet of an accepted connection. Tuned using 7 | * tcp_slow_start_initial. 8 | * 9 | * Idea: Theo Schlossnagle 10 | * 11 | * While the probes this script uses are stable (tcp provider), it uses a 12 | * unstable variable (arg3), making the script unstable. It's the args[N] 13 | * versions that are stable, not the argN versions. 14 | */ 15 | 16 | #pragma D option quiet 17 | #pragma D option switchrate=5 18 | 19 | dtrace:::BEGIN 20 | { 21 | trace("Tracing tcp slow start.\n"); 22 | } 23 | 24 | tcp:::accept-established 25 | { 26 | /* key on the tcp_t, which is arg3 (undocumented and unstable) */ 27 | a[arg3] = 1; 28 | } 29 | 30 | tcp:::send 31 | /a[arg3] && (args[2]->ip_plength - args[4]->tcp_offset)/ 32 | { 33 | printf("%3d MSS: %15s -> %15s\n", 34 | args[3]->tcps_cwnd / args[3]->tcps_mss, 35 | args[2]->ip_saddr, args[2]->ip_daddr); 36 | a[arg3] = 0; 37 | } 38 | -------------------------------------------------------------------------------- /erlang/erlang_punslower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * erlang_punslower.d Process unscheduled events slower than arg. 4 | * 5 | * USAGE: ./erlang_punslower.d [min_ms] 6 | * 7 | * This shows the next function that will be run. 8 | * 9 | * 13-Jun-2013 Brendan Gregg Created this. 10 | */ 11 | 12 | #pragma D option dynvarsize=8m 13 | #pragma D option quiet 14 | #pragma D option switchrate=4 15 | 16 | dtrace:::BEGIN 17 | { 18 | min_ns = $1 ? $1 * 1000000 : 1000000; 19 | printf("Tracing Erlang process unscheduled events with next\n"); 20 | printf("function call, slower than %d ms.\n", min_ns / 1000000); 21 | } 22 | 23 | erlang*:::process-unscheduled 24 | { 25 | ts[copyinstr(arg0)] = timestamp; 26 | } 27 | 28 | erlang*:::process-scheduled 29 | /(this->p = copyinstr(arg0)) != NULL && 30 | (this->ts = ts[this->p]) > 0 && 31 | (this->d = (timestamp - this->ts)) > min_ns/ 32 | { 33 | printf("%Y %8d ms: %s\n", walltimestamp, 34 | (timestamp - this->ts) / 1000000, copyinstr(arg1)); 35 | } 36 | 37 | erlang*:::process-scheduled 38 | /this->p != NULL/ 39 | { 40 | ts[this->p] = 0; 41 | } 42 | -------------------------------------------------------------------------------- /postgres/ptlt10k.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * ptlt10k.d Postgres Transaction Latency Trace. 4 | * 5 | * This traces Postgres transactions using the DTrace postgres provider. All 6 | * running instances of postgres will be traced. 7 | * 8 | * This emits basic details for consumption by other tools. It ideally 9 | * captures at least 10,000 transactions. It has a 15 minute timeout if that 10 | * is not possible. 11 | * 12 | * 26-Jun-2013 Brendan Gregg Created this. 13 | */ 14 | 15 | #pragma D option quiet 16 | #pragma D option switchrate=5 17 | 18 | dtrace:::BEGIN 19 | { 20 | printf("ENDTIME(us) LATENCY(ns) PID\n"); 21 | start = timestamp; 22 | n = 0; 23 | } 24 | 25 | postgres*:::transaction-start 26 | { 27 | self->ts = timestamp; 28 | } 29 | 30 | postgres*:::transaction-commit, 31 | postgres*:::transaction-abort 32 | /self->ts/ 33 | { 34 | printf("%d %d %d\n", 35 | (timestamp - start) / 1000, timestamp - self->ts, pid); 36 | self->ts = 0; 37 | } 38 | 39 | postgres*:::transaction-start 40 | /n++ > 10100/ 41 | { 42 | exit(0); 43 | } 44 | 45 | profile:::tick-15m { exit(0); } 46 | -------------------------------------------------------------------------------- /node.js/nslt10k.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * nslt10k.d node.js Server Latency Trace. 4 | * 5 | * This traces node.js HTTP server requests using the node DTrace provider. 6 | * All node instances on the system will be traced. 7 | * 8 | * This emits basic details for consumption by other tools, and includes the 9 | * PID. It ideally captures at least 10,000 requests. It has a 15 minute 10 | * timeout if that is not possible. 11 | * 12 | * 25-Jun-2013 Brendan Gregg Created this. 13 | */ 14 | 15 | #pragma D option quiet 16 | #pragma D option switchrate=5 17 | 18 | dtrace:::BEGIN 19 | { 20 | printf("ENDTIME(us) LATENCY(ns) PID\n"); 21 | start = timestamp; 22 | n = 0; 23 | } 24 | 25 | node*:::http-server-request 26 | { 27 | ts[pid, args[1]->fd] = timestamp; 28 | } 29 | 30 | node*:::http-server-response 31 | /this->start = ts[pid, args[0]->fd]/ 32 | { 33 | printf("%d %d %d\n", 34 | (timestamp - start) / 1000, timestamp - this->start, pid); 35 | ts[pid, args[0]->fd] = 0; 36 | } 37 | 38 | node*:::http-server-request 39 | /n++ > 10100/ 40 | { 41 | exit(0); 42 | } 43 | 44 | profile:::tick-15m { exit(0); } 45 | -------------------------------------------------------------------------------- /go/go_pkgcounts.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * go_pkgcounts.d Summarize function call counts by package name 4 | * 5 | * USAGE: go_pkgcounts.d -p PID [interval] 6 | * 7 | * This traces all functions in all packages in go. 8 | * 9 | * WARNING: This traces all functions, which can cause significant overhead 10 | * slowing the target. 11 | * 12 | * An optional interval can be provided, which will print a summary 13 | * every interval seconds. 14 | */ 15 | 16 | #pragma D option defaultargs 17 | #pragma D option quiet 18 | 19 | dtrace:::BEGIN 20 | { 21 | interval = $1; 22 | sec = 0; 23 | } 24 | 25 | dtrace:::BEGIN 26 | /interval/ 27 | { 28 | printf("Tracing PID %d; output every %d secs.\n", $target, interval); 29 | } 30 | 31 | dtrace:::BEGIN 32 | /!interval/ 33 | { 34 | printf("Tracing PID %d; Ctrl-C to stop.\n", $target); 35 | } 36 | 37 | pid$target:a.out::entry 38 | /strstr(probefunc, ".") != NULL/ 39 | { 40 | @[strtok(probefunc, ".")] = count(); 41 | } 42 | 43 | profile:::tick-1s 44 | /interval && ++sec == interval/ 45 | { 46 | sec = 0; 47 | printf("\n%Y:\n", walltimestamp); 48 | printa(@); 49 | trunc(@); 50 | } 51 | -------------------------------------------------------------------------------- /mysql/mclt10k.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mclt10k.d MySQL Command Latency Trace. 4 | * 5 | * This traces MySQL commands using the mysql DTrace provider. All 6 | * mysqld instances on the system will be traced. 7 | * 8 | * This emits basic details for consumption by other tools, and includes the 9 | * MySQL command ID (numeric) and PID. It ideally captures at least 10,000 10 | * commands. It has a 15 minute timeout if that is not possible. 11 | * 12 | * 25-Jun-2013 Brendan Gregg Created this. 13 | */ 14 | 15 | #pragma D option quiet 16 | #pragma D option switchrate=5 17 | 18 | dtrace:::BEGIN 19 | { 20 | printf("ENDTIME(us) LATENCY(ns) CMD PID\n"); 21 | start = timestamp; 22 | n = 0; 23 | } 24 | 25 | mysql*:::command-start 26 | { 27 | self->ts = timestamp; 28 | self->cmd = arg1; 29 | } 30 | 31 | mysql*:::command-done 32 | /self->ts/ 33 | { 34 | printf("%d %d %d %d\n", 35 | (timestamp - start) / 1000, timestamp - self->ts, self->cmd, pid); 36 | self->ts = 0; 37 | self->cmd = 0; 38 | } 39 | 40 | mysql*:::command-start 41 | /n++ > 10100/ 42 | { 43 | exit(0); 44 | } 45 | 46 | profile:::tick-15m { exit(0); } 47 | -------------------------------------------------------------------------------- /zfs/ziostacks.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * ziostacks.d Show kernel stacks for ZFS zio_read/writes. 4 | * 5 | * SEE ALSO: iostacks.d, ziocreatestacks.d 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | fbt::zio_read:entry, 33 | fbt::zio_write:entry 34 | { 35 | @[probefunc, stack()] = count(); 36 | } 37 | -------------------------------------------------------------------------------- /zfs/ziocreatestacks.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * ziocreatestacks.d Show kernel stacks for ZFS zio creation. 4 | * 5 | * SEE ALSO: ziostacks.d (preferred), iostacks.d 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | fbt::zio_create:entry 33 | /arg0 == NULL/ 34 | { 35 | @[probefunc, stack()] = count(); 36 | } 37 | -------------------------------------------------------------------------------- /disk/iostacks.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * iostacks.d Show kernel stacks for io:::start (block-device interface). 4 | * 5 | * SEE ALSO: ziostacks.d (ZFS, preferred) 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | io:::start 33 | { 34 | @[args[0]->b_flags & B_READ ? "read" : "write", stack()] = count(); 35 | } 36 | -------------------------------------------------------------------------------- /apache/httpdslower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * httpdslower.d Show HTTP server requests slower than threshold. 4 | * 5 | * USAGE: httpdslower.d [min_ms] 6 | * eg, 7 | * httpdslower.d 10 # show requests slower than 10 ms 8 | * httpdslower.d # show all requests 9 | * 10 | * This requires the httpd DTrace provider, which is available as mod_usdt 11 | * for Apache, and the translators. If they are in not in /usr/lib/dtrace, 12 | * you may need to invoke this with the actual location with -L, eg: 13 | * dtrace -L /opt/local/lib/dtrace -s httpdslower.d 14 | * 15 | * This script will trace all running instances of Apache. 16 | * 17 | * 26-Jun-2013 Brendan Gregg Created this. 18 | */ 19 | 20 | #pragma D option quiet 21 | #pragma D option defaultargs 22 | #pragma D option switchrate=10 23 | 24 | dtrace:::BEGIN 25 | { 26 | min_ns = $1 * 1000000; 27 | printf("Tracing HTTP server ops slower than %d ms\n", $1); 28 | printf("%-20s %-6s %6s %s\n", "TIME", "PID", "ms", "URL"); 29 | } 30 | 31 | node*:::http-server-request 32 | { 33 | self->ts = timestamp; 34 | } 35 | 36 | node*:::http-server-response 37 | /self->ts && (this->delta = timestamp - self->ts) > min_ns/ 38 | { 39 | printf("%-20Y %-6d %6d %s\n", walltimestamp, pid, 40 | this->delta / 1000000, args[1]->rq_uri); 41 | self->ts = 0; 42 | } 43 | -------------------------------------------------------------------------------- /system/cpuutil.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * cpuutil.d sample and summarize zone and execname CPU usage. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | */ 29 | 30 | #pragma D option quiet 31 | 32 | profile:::profile-997 33 | /curthread->t_pri != -1/ 34 | { 35 | @[zonename, execname] = count(); 36 | } 37 | 38 | profile:::tick-1s, 39 | dtrace:::END 40 | { 41 | printf("\non-CPU samples by zone and process, @997 Hertz:\n"); 42 | printa(" %-16s %-16s %@4d\n", @); 43 | trunc(@); 44 | } 45 | -------------------------------------------------------------------------------- /system/rcapd_stat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * rcapd_stat.d show rcapd on-CPU rate 4 | * 5 | * Simple tool to be left running to watch for correlations. 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | dtrace:::BEGIN 33 | { 34 | /* workaround to trick printa() into always firing to start with */ 35 | @ = sum(0); 36 | } 37 | 38 | profile:::profile-99hz 39 | /execname == "rcapd"/ 40 | { 41 | @ = sum(1); 42 | } 43 | 44 | profile:::tick-1s 45 | { 46 | printa("rcapd CPU samples @99hz: %@d", @); 47 | clear(@); 48 | } 49 | -------------------------------------------------------------------------------- /disk/megasaslatency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * megasaslatency.d Latency from the mega_sas driver. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | * 29 | * This traces driver internals, and is likely to only work for some 30 | * versions of the driver. 31 | */ 32 | 33 | fbt:mega_sas:issue_cmd_ppc:entry 34 | { 35 | start[arg0] = timestamp; 36 | } 37 | 38 | fbt:mega_sas:return_mfi_pkt:entry 39 | /this->start = start[arg1]/ 40 | { 41 | @time["mega_sas cmd latency (ns)"] = quantize(timestamp - this->start); 42 | start[arg1] = 0; 43 | } 44 | -------------------------------------------------------------------------------- /zfs/ziowait.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * ziowait.d Measure time in zio_wait() by kernel stack trace. 4 | * 5 | * This won't identify all ZIO times, just those waited upon. You may 6 | * get lucky this way and find the latency you are after this way, or 7 | * maybe not. 8 | * 9 | * CDDL HEADER START 10 | * 11 | * The contents of this file are subject to the terms of the 12 | * Common Development and Distribution License, Version 1.0 only 13 | * (the "License"). You may not use this file except in compliance 14 | * with the License. 15 | * 16 | * You can obtain a copy of the license at http://smartos.org/CDDL 17 | * 18 | * See the License for the specific language governing permissions 19 | * and limitations under the License. 20 | * 21 | * When distributing Covered Code, include this CDDL HEADER in each 22 | * file. 23 | * 24 | * If applicable, add the following below this CDDL HEADER, with the 25 | * fields enclosed by brackets "[]" replaced with your own identifying 26 | * information: Portions Copyright [yyyy] [name of copyright owner] 27 | * 28 | * CDDL HEADER END 29 | * 30 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 31 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 32 | * 33 | * TESTED: this fbt provider based script may only work on some OS versions. 34 | * 121: ok 35 | */ 36 | 37 | fbt::zio_wait:entry 38 | { 39 | self->start = timestamp; 40 | } 41 | 42 | fbt::zio_wait:return 43 | /self->start/ 44 | { 45 | @[stack(), "time (ns)"] = quantize(timestamp - self->start); 46 | self->start = 0; 47 | } 48 | -------------------------------------------------------------------------------- /disk/ioslow.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * ioslow.d Trace disk I/O slower than specified ms. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | */ 29 | 30 | #pragma D option quiet 31 | 32 | inline int MIN_NS = 1000000000; 33 | 34 | dtrace:::BEGIN 35 | { 36 | printf("Tracing disk I/O longer than %d ms.\n\n", MIN_NS / 1000000); 37 | } 38 | 39 | io:::start 40 | { 41 | start[arg0] = timestamp; 42 | } 43 | 44 | io:::done 45 | /(this->start = start[arg0]) && (this->time = timestamp - this->start) > MIN_NS/ 46 | { 47 | printf("%Y: %s %d ms\n", walltimestamp, 48 | args[0]->b_flags & B_READ ? "read" : "write", this->time / 1000000); 49 | } 50 | 51 | io:::done 52 | { 53 | start[arg0] = 0; 54 | } 55 | -------------------------------------------------------------------------------- /go/go_mainflow.txt: -------------------------------------------------------------------------------- 1 | # ./go_mainflow.d -p 17649 2 | CPU PID DELTA(us) PACKAGE FUNCTION 3 | 14 36030 8 main -> .domorestuff 4 | 14 36030 971 main -> .dostuff 5 | 14 36030 194 main <- .dostuff 6 | 14 36030 23 main -> .dostuff 7 | 14 36030 162 main <- .dostuff 8 | 14 36030 14 main <- .domorestuff 9 | 14 36030 14 main -> .domorestuff 10 | 14 36030 783 main -> .dostuff 11 | 14 36030 173 main <- .dostuff 12 | 14 36030 14 main -> .dostuff 13 | 14 36030 163 main <- .dostuff 14 | 14 36030 14 main <- .domorestuff 15 | 14 36030 14 main -> .domorestuff 16 | 14 36030 765 main -> .dostuff 17 | 14 36030 196 main <- .dostuff 18 | 14 36030 14 main -> .dostuff 19 | 14 36030 234 main <- .dostuff 20 | 14 36030 15 main <- .domorestuff 21 | 14 36030 15 main -> .domorestuff 22 | 14 36030 918 main -> .dostuff 23 | 14 36030 158 main <- .dostuff 24 | 14 36030 12 main -> .dostuff 25 | 14 36030 160 main <- .dostuff 26 | 14 36030 13 main <- .domorestuff 27 | 14 36030 13 main -> .domorestuff 28 | 14 36030 757 main -> .dostuff 29 | 14 36030 158 main <- .dostuff 30 | [...] 31 | -------------------------------------------------------------------------------- /net/ipdropper.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * ipdropper.d - trace ip drop events with details 4 | * 5 | * This uses the fbt provider, so is unstable. 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2013 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2013 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | #pragma D option quiet 33 | 34 | dtrace:::BEGIN 35 | { 36 | printf("%-20s %-16s %-16s %s\n", "TIME", "SRC", "DST", "STR"); 37 | } 38 | 39 | /* 40 | * ip_drop*() funcs have a string pointer description as arg0. This is 41 | * almost too good to be true. 42 | */ 43 | fbt::ip_drop_input:entry, 44 | fbt::ip_drop_output:entry 45 | { 46 | this->iph = (ipha_t *)args[1]->b_rptr; 47 | printf("%-20Y %-16s %-16s %s\n", walltimestamp, 48 | inet_ntoa(&this->iph->ipha_src), inet_ntoa(&this->iph->ipha_dst), 49 | stringof(arg0)); 50 | } 51 | -------------------------------------------------------------------------------- /zfs/zilt10k.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zilt10k.d ZFS Latency Trace. 4 | * 5 | * This traces several types of user-level ZFS request, via the ZFS/VFS 6 | * interface. The output will be verbose, as it includes ARC hits. 7 | * 8 | * This emits basic details for consumption by other tools, and includes 9 | * the zonename. It ideally captures at least 10,000 I/O events. It has 10 | * a 15 minute timeout if that is not possible. 11 | * 12 | * 25-Jun-2013 Brendan Gregg Created this. 13 | */ 14 | 15 | #pragma D option quiet 16 | #pragma D option switchrate=5 17 | 18 | BEGIN 19 | { 20 | printf("ENDTIME(us) LATENCY(ns) TYPE SIZE(bytes) ZONENAME PROCESS\n"); 21 | start = timestamp; 22 | n = 0; 23 | } 24 | 25 | fbt::zfs_read:entry, fbt::zfs_write:entry 26 | /execname != "dtrace"/ 27 | { 28 | self->ts = timestamp; 29 | self->b = args[1]->uio_resid; 30 | } 31 | 32 | fbt::zfs_open:entry, fbt::zfs_close:entry, 33 | fbt::zfs_readdir:entry, fbt::zfs_getattr:entry 34 | /execname != "dtrace"/ 35 | { 36 | self->ts = timestamp; 37 | self->b = 0; 38 | } 39 | 40 | fbt::zfs_read:entry, fbt::zfs_write:entry, 41 | fbt::zfs_open:entry, fbt::zfs_close:entry, 42 | fbt::zfs_readdir:entry, fbt::zfs_getattr:entry 43 | /n++ > 10100/ 44 | { 45 | exit(0); 46 | } 47 | 48 | profile:::tick-15m { exit(0); } 49 | 50 | fbt::zfs_read:return, fbt::zfs_write:return, 51 | fbt::zfs_open:return, fbt::zfs_close:return, 52 | fbt::zfs_readdir:return, fbt::zfs_getattr:return 53 | /self->ts/ 54 | { 55 | printf("%d %d %s %d %s %s\n", 56 | (timestamp - start) / 1000, timestamp - self->ts, 57 | probefunc + 4, self->b, zonename, execname); 58 | self->ts = 0; 59 | self->b = 0; 60 | } 61 | -------------------------------------------------------------------------------- /go/go_mainflow.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * go_mainflow.d Trace function flow for main package functions. 4 | * 5 | * USAGE: goflow.d -p PID [interval] 6 | * 7 | * NOTE: The output may be shuffled slightly; see comment in script. 8 | * 9 | * An optional interval can be provided, which will print a summary 10 | * every interval seconds. 11 | */ 12 | 13 | #pragma D option defaultargs 14 | #pragma D option switchrate=10 15 | #pragma D option quiet 16 | 17 | /* 18 | * If your system supports it, add the following for correct ordering of output, 19 | * otherwise shuffles can occur (due to the dumping of 100ms per-CPU buffers): 20 | * #pragma D option temporal 21 | */ 22 | 23 | self int depth; 24 | 25 | dtrace:::BEGIN 26 | { 27 | printf("%3s %6s %10s %16s %s\n", "CPU", "PID", "DELTA(us)", 28 | "PACKAGE", "FUNCTION"); 29 | } 30 | 31 | pid$target::main.*:entry 32 | /self->last == 0 && strstr(probefunc, ".") != NULL/ 33 | { 34 | self->last = timestamp; 35 | } 36 | 37 | pid$target::main.*:entry 38 | /strstr(probefunc, ".") != NULL/ 39 | { 40 | this->delta = (timestamp - self->last) / 1000; 41 | printf("%3d %6d %10d %16s %*s-> %s\n", cpu, pid, this->delta, 42 | strtok(probefunc, "."), self->depth * 2, "", strchr(probefunc, 46)); 43 | self->depth++; 44 | self->last = timestamp; 45 | } 46 | 47 | pid$target::main.*:return 48 | /self->last && strstr(probefunc, ".") != NULL/ 49 | { 50 | this->delta = (timestamp - self->last) / 1000; 51 | self->depth -= self->depth > 0 ? 1 : 0; 52 | printf("%3d %6d %10d %16s %*s<- %s\n", cpu, pid, this->delta, 53 | strtok(probefunc, "."), self->depth * 2, "", strchr(probefunc, 46)); 54 | self->last = timestamp; 55 | } 56 | -------------------------------------------------------------------------------- /mysql/libmysql_pid_qtime.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -Zs 2 | /* 3 | * libmysql_pid_qtime.d Summarize MySQL client query latency. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | */ 29 | 30 | #pragma D option quiet 31 | 32 | dtrace:::BEGIN 33 | { 34 | printf("Tracing... Hit Ctrl-C for report.\n"); 35 | } 36 | 37 | pid$target::mysql_query:entry, 38 | pid$target::mysql_real_query:entry 39 | { 40 | self->start = timestamp; 41 | } 42 | 43 | pid$target::mysql_query:return, 44 | pid$target::mysql_real_query:return 45 | /self->start/ 46 | { 47 | this->time = timestamp - self->start; 48 | @["query time (ns)"] = quantize(this->time); 49 | @a["average (ms)"] = avg(this->time); 50 | self->start = 0; 51 | } 52 | 53 | dtrace:::END 54 | { 55 | normalize(@a, 1000000); 56 | printa(@); 57 | printa(@a); 58 | } 59 | -------------------------------------------------------------------------------- /system/capslat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * capslat.d CPU caps latency. 4 | * 5 | * This is the latency injected by cpu-caps; it acts like dispatcher 6 | * queue latency - leaving threads waiting while in the run state. 7 | * 8 | * SEE ALSO: displat.d, zonecapslat.d, zonedisplat.d 9 | * 10 | * CDDL HEADER START 11 | * 12 | * The contents of this file are subject to the terms of the 13 | * Common Development and Distribution License, Version 1.0 only 14 | * (the "License"). You may not use this file except in compliance 15 | * with the License. 16 | * 17 | * You can obtain a copy of the license at http://smartos.org/CDDL 18 | * 19 | * See the License for the specific language governing permissions 20 | * and limitations under the License. 21 | * 22 | * When distributing Covered Code, include this CDDL HEADER in each 23 | * file. 24 | * 25 | * If applicable, add the following below this CDDL HEADER, with the 26 | * fields enclosed by brackets "[]" replaced with your own identifying 27 | * information: Portions Copyright [yyyy] [name of copyright owner] 28 | * 29 | * CDDL HEADER END 30 | * 31 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 32 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 33 | */ 34 | 35 | #pragma D option quiet 36 | 37 | sched:::cpucaps-sleep 38 | { 39 | start[args[0]->pr_lwpid, args[1]->pr_pid] = timestamp; 40 | } 41 | 42 | sched:::cpucaps-wakeup 43 | /this->start = start[args[0]->pr_lwpid, args[1]->pr_pid]/ 44 | { 45 | this->time = timestamp - this->start; 46 | @ = quantize(this->time); 47 | start[args[0]->pr_lwpid, args[1]->pr_pid] = 0; 48 | } 49 | 50 | tick-1sec 51 | { 52 | printf("CPU caps latency (ns):"); 53 | printa(@); 54 | trunc(@); 55 | } 56 | -------------------------------------------------------------------------------- /net/tcpconnreqmaxq_sdc5.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpconnreqmaxq.d Summarize details for the TCP connection queue. 4 | * 5 | * This traces tcpListenDrop and the active value for tcp_conn_req_cnt_q, 6 | * to evaluate tuning of tcp_conn_req_max_q. 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | * 32 | * TESTED: this fbt provider based script may only work on some OS versions. 33 | * 121: ok 34 | */ 35 | 36 | #pragma D option quiet 37 | 38 | dtrace:::BEGIN 39 | { 40 | printf("Tracing... Hit Ctrl-C to end.\n"); 41 | } 42 | 43 | fbt::tcp_conn_request:entry 44 | { 45 | this->connp = (conn_t *)arg0; 46 | this->tcp = (tcp_t *)this->connp->conn_proto_priv.cp_tcp; 47 | @["tcp_conn_req_cnt_q"] = quantize(this->tcp->tcp_conn_req_cnt_q); 48 | } 49 | 50 | mib:::tcpListenDrop 51 | { 52 | @drops[probename] = count(); 53 | } 54 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_latency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_latency.d Print mysqld query latency distribution. 4 | * 5 | * USAGE: ./mysqld_pid_latency.d -p mysqld_PID 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: these pid-provider probes may only work on some mysqld versions. 32 | * 5.0.51a: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | 37 | dtrace:::BEGIN 38 | { 39 | printf("Tracing mysqld... Hit Ctrl-C for report.\n"); 40 | } 41 | 42 | pid$target::*dispatch_command*:entry 43 | { 44 | self->start = timestamp; 45 | } 46 | 47 | pid$target::*dispatch_command*:return 48 | /self->start/ 49 | { 50 | @time = quantize(timestamp - self->start); 51 | @num = count(); 52 | self->start = 0; 53 | } 54 | 55 | dtrace:::END 56 | { 57 | printa("MySQL queries: %@d; query latency (ns):", @num); 58 | printa(@time); 59 | } 60 | -------------------------------------------------------------------------------- /fs/solvfssnoop.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * solvfssnoop.d Solaris VFS operation snoop. 4 | * 5 | * As this traces VFS, this includes all file system types, including 6 | * socket. See the operations it traces below. 7 | * 8 | * This is from the DTrace book, chapter 5. See http://www.dtracebook.com. 9 | * 10 | * 18-Jun-2010 Brendan Gregg Created this. 11 | */ 12 | 13 | #pragma D option quiet 14 | #pragma D option defaultargs 15 | #pragma D option switchrate=10hz 16 | 17 | dtrace:::BEGIN 18 | { 19 | printf("%-12s %6s %6s %-12.12s %-12s %-4s %s\n", "TIME(ms)", "UID", 20 | "PID", "PROCESS", "CALL", "KB", "PATH"); 21 | } 22 | 23 | /* see /usr/include/sys/vnode.h */ 24 | 25 | fbt::fop_read:entry, fbt::fop_write:entry 26 | { 27 | self->path = args[0]->v_path; 28 | self->kb = args[1]->uio_resid / 1024; 29 | } 30 | 31 | fbt::fop_open:entry 32 | { 33 | self->path = (*args[0])->v_path; 34 | self->kb = 0; 35 | } 36 | 37 | fbt::fop_close:entry, fbt::fop_ioctl:entry, fbt::fop_getattr:entry, 38 | fbt::fop_readdir:entry 39 | { 40 | self->path = args[0]->v_path; 41 | self->kb = 0; 42 | } 43 | 44 | fbt::fop_read:entry, fbt::fop_write:entry, fbt::fop_open:entry, 45 | fbt::fop_close:entry, fbt::fop_ioctl:entry, fbt::fop_getattr:entry, 46 | fbt::fop_readdir:entry 47 | /execname != "dtrace" && ($$1 == NULL || $$1 == execname)/ 48 | { 49 | printf("%-12d %6d %6d %-12.12s %-12s %-4d %s\n", timestamp / 1000000, 50 | uid, pid, execname, probefunc, self->kb, 51 | self->path != NULL ? stringof(self->path) : ""); 52 | } 53 | 54 | fbt::fop_read:entry, fbt::fop_write:entry, fbt::fop_open:entry, 55 | fbt::fop_close:entry, fbt::fop_ioctl:entry, fbt::fop_getattr:entry, 56 | fbt::fop_readdir:entry 57 | { 58 | self->path = 0; self->kb = 0; 59 | } 60 | -------------------------------------------------------------------------------- /zfs/metaslab_free.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * metaslab_free.d Show ZFS metaslab percent free on allocations. 4 | * 5 | * ZFS switches to a slower allocation algorithm when the free size in a 6 | * metaslab (usually 16 Gbytes) is less than a percentage. The slower 7 | * algorithm is best-fit instead of fast-fit. 8 | * 9 | * CDDL HEADER START 10 | * 11 | * The contents of this file are subject to the terms of the 12 | * Common Development and Distribution License, Version 1.0 only 13 | * (the "License"). You may not use this file except in compliance 14 | * with the License. 15 | * 16 | * You can obtain a copy of the license at http://smartos.org/CDDL 17 | * 18 | * See the License for the specific language governing permissions 19 | * and limitations under the License. 20 | * 21 | * When distributing Covered Code, include this CDDL HEADER in each 22 | * file. 23 | * 24 | * If applicable, add the following below this CDDL HEADER, with the 25 | * fields enclosed by brackets "[]" replaced with your own identifying 26 | * information: Portions Copyright [yyyy] [name of copyright owner] 27 | * 28 | * CDDL HEADER END 29 | * 30 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 31 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 32 | */ 33 | 34 | #pragma D option quiet 35 | 36 | dtrace:::BEGIN 37 | { 38 | printf("Tracing ZFS metaslab alloc. metaslab_df_free_pct = %d %%\n", 39 | `metaslab_df_free_pct); 40 | } 41 | 42 | fbt::metaslab_df_alloc:entry 43 | { 44 | this->pct = args[0]->sm_space * 100 / args[0]->sm_size; 45 | @[this->pct] = count(); 46 | } 47 | 48 | profile:::tick-1s 49 | { 50 | printf("\n%Y free %%pct by allocations:", walltimestamp); 51 | printa(@); 52 | trunc(@); 53 | } 54 | -------------------------------------------------------------------------------- /zfs/zfsdist.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zfsdist.d Show ZFS/VFS latency distributions. 4 | * 5 | * Some common ZFS/VFS calls are traced (see below). 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: this fbt provider based script may only work on some OS versions. 32 | * 121: ok 33 | */ 34 | 35 | fbt::zfs_read:entry, 36 | fbt::zfs_write:entry, 37 | fbt::zfs_readdir:entry, 38 | fbt::zfs_getattr:entry, 39 | fbt::zfs_setattr:entry 40 | { 41 | self->start = timestamp; 42 | } 43 | 44 | fbt::zfs_read:return, 45 | fbt::zfs_write:return, 46 | fbt::zfs_readdir:return, 47 | fbt::zfs_getattr:return, 48 | fbt::zfs_setattr:return 49 | /self->start/ 50 | { 51 | this->time = timestamp - self->start; 52 | @[probefunc, "time (ns)"] = quantize(this->time); 53 | self->start = 0; 54 | } 55 | 56 | dtrace:::END 57 | { 58 | printa(@); 59 | trunc(@); 60 | } 61 | -------------------------------------------------------------------------------- /net/tcpconnreqmaxq_sdc6.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpconnreqmaxq.d Summarize details for the TCP connection queue. 4 | * 5 | * This traces tcpListenDrop and the active value for tcp_conn_req_cnt_q, 6 | * to evaluate tuning of tcp_conn_req_max_q. 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | * 32 | * TESTED: this fbt provider based script may only work on some OS versions. 33 | * SDC 6.5: ok (possibly illumos, nevada 148 and newer) 34 | */ 35 | 36 | #pragma D option quiet 37 | 38 | dtrace:::BEGIN 39 | { 40 | printf("Tracing... Hit Ctrl-C to end.\n"); 41 | } 42 | 43 | fbt::tcp_input_listener:entry 44 | { 45 | this->connp = (conn_t *)arg0; 46 | this->tcp = (tcp_t *)this->connp->conn_proto_priv.cp_tcp; 47 | @["tcp_conn_req_cnt_q"] = quantize(this->tcp->tcp_conn_req_cnt_q); 48 | } 49 | 50 | mib:::tcpListenDrop 51 | { 52 | @drops[probename] = count(); 53 | } 54 | -------------------------------------------------------------------------------- /system/gethostbyaddr.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * gethostbyaddr.d - snoop gethostbyaddr_r() calls with IP and latency. 4 | * 5 | * This can be used for the analysis of DNS latency, for apps that are 6 | * making this call. 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | */ 32 | 33 | #pragma D option defaultargs 34 | 35 | dtrace:::BEGIN 36 | { 37 | printf("Tracing gethostbyaddr_r() longer than %d ms...\n", $1); 38 | min_ns = $1 * 1000000; 39 | } 40 | 41 | pid$target::gethostbyaddr_r:entry 42 | { 43 | self->s = timestamp; 44 | self->n = inet_ntoa(copyin(arg0, arg1)); 45 | } 46 | 47 | pid$target::gethostbyaddr_r:return 48 | /self->s && (this->lat = (timestamp - self->s)) && this->lat > min_ns/ 49 | { 50 | printf("%d ms for \"%s\"", (this->lat) / 1000000, self->n); 51 | } 52 | 53 | pid$target::gethostbyaddr_r:return 54 | /self->s/ 55 | { 56 | self->s = 0; 57 | self->n = 0; 58 | } 59 | -------------------------------------------------------------------------------- /mysql/libmysql_pid_connect.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * libmysql_pid_connect.d Trace MySQL connect latency. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | */ 29 | 30 | #pragma D option quiet 31 | #pragma D option switchrate=10hz 32 | 33 | dtrace:::BEGIN 34 | { 35 | printf("%-20s %16s %12s %6s %8s\n", "TIME", "HOST", "DB", "PORT", "LAT"); 36 | } 37 | 38 | pid$target::mysql_real_connect:entry 39 | { 40 | self->host = arg1 ? copyinstr(arg1) : ""; 41 | self->db = arg4 ? copyinstr(arg4) : ""; 42 | self->port = arg5; 43 | self->start = timestamp; 44 | } 45 | 46 | pid$target::mysql_real_connect:return 47 | /self->start/ 48 | { 49 | this->delta = timestamp - self->start; 50 | printf("%-20Y %16s %12s %6d %8d ms\n", walltimestamp, 51 | self->host, self->db, self->port, this->delta / 1000000); 52 | self->host = 0; 53 | self->db = 0; 54 | self->port = 0; 55 | self->start = 0; 56 | } 57 | -------------------------------------------------------------------------------- /mysql/libmysql_pid_snoop.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -Zs 2 | /* 3 | * libmysql_pid_snoop.d Snoop MySQL queries. 4 | * 5 | * From the "DTrace" book, chapter 10. 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | #pragma D option quiet 33 | #pragma D option switchrate=10hz 34 | 35 | dtrace:::BEGIN 36 | { 37 | printf("%-8s %6s %3s %s\n", "TIME(ms)", "Q(ms)", "RET", "QUERY"); 38 | timezero = timestamp; 39 | } 40 | 41 | pid$target::mysql_query:entry, 42 | pid$target::mysql_real_query:entry 43 | { 44 | self->query = copyinstr(arg1); 45 | self->start = timestamp; 46 | } 47 | 48 | pid$target::mysql_query:return, 49 | pid$target::mysql_real_query:return 50 | /self->start/ 51 | { 52 | this->time = (timestamp - self->start) / 1000000; 53 | this->now = (timestamp - timezero) / 1000000; 54 | printf("%-8d %6d %3d %s\n", this->now, this->time, arg1, self->query); 55 | self->start = 0; self->query = 0; 56 | } 57 | -------------------------------------------------------------------------------- /go/go_flow.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * goflow.d Trace function flow of all go functions. 4 | * 5 | * USAGE: goflow.d -p PID [interval] 6 | * 7 | * WARNING: This traces every go function and prints details for each, and 8 | * as such is likely to cause significant overhead, slowing the target. 9 | * 10 | * NOTE: The output may be shuffled slightly; see comment in script. 11 | * 12 | * An optional interval can be provided, which will print a summary 13 | * every interval seconds. 14 | */ 15 | 16 | #pragma D option defaultargs 17 | #pragma D option switchrate=10 18 | #pragma D option quiet 19 | 20 | /* 21 | * If your system supports it, add the following for correct ordering of output, 22 | * otherwise shuffles can occur (due to the dumping of 100ms per-CPU buffers): 23 | * #pragma D option temporal 24 | */ 25 | 26 | self int depth; 27 | 28 | dtrace:::BEGIN 29 | { 30 | printf("%3s %6s %10s %16s %s\n", "CPU", "PID", "DELTA(us)", 31 | "PACKAGE", "FUNCTION"); 32 | } 33 | 34 | pid$target:a.out::entry 35 | /self->last == 0 && strstr(probefunc, ".") != NULL/ 36 | { 37 | self->last = timestamp; 38 | } 39 | 40 | pid$target:a.out::entry 41 | /strstr(probefunc, ".") != NULL/ 42 | { 43 | this->delta = (timestamp - self->last) / 1000; 44 | printf("%3d %6d %10d %16s %*s-> %s\n", cpu, pid, this->delta, 45 | strtok(probefunc, "."), self->depth * 2, "", strchr(probefunc, 46)); 46 | self->depth++; 47 | self->last = timestamp; 48 | } 49 | 50 | pid$target:a.out::return 51 | /self->last && strstr(probefunc, ".") != NULL/ 52 | { 53 | this->delta = (timestamp - self->last) / 1000; 54 | self->depth -= self->depth > 0 ? 1 : 0; 55 | printf("%3d %6d %10d %16s %*s<- %s\n", cpu, pid, this->delta, 56 | strtok(probefunc, "."), self->depth * 2, "", strchr(probefunc, 46)); 57 | self->last = timestamp; 58 | } 59 | -------------------------------------------------------------------------------- /mysql/mysqld_latency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_latency.d Print query latency distribution every second. 4 | * 5 | * USAGE: ./mysqld_latency.d 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: not yet! need a mysqld that has the query-start/done probes. 32 | */ 33 | 34 | #pragma D option quiet 35 | 36 | dtrace:::BEGIN 37 | { 38 | printf("Tracing all mysql probes... Hit Ctrl-C to end.\n"); 39 | } 40 | 41 | mysql*:::query-start 42 | { 43 | self->start = timestamp; 44 | } 45 | 46 | mysql*:::query-done 47 | /self->start/ 48 | { 49 | @time[pid, zonename] = quantize(timestamp - self->start); 50 | @num = count(); 51 | self->start = 0; 52 | } 53 | 54 | profile:::tick-1s 55 | { 56 | printf("\nMySQL queries/second total: "); 57 | printa("%@d; query latency (ns) by pid & zonename:", @num); 58 | printa(@time); 59 | clear(@time); clear(@num); 60 | } 61 | 62 | dtrace:::END 63 | { 64 | trunc(@time); trunc(@num); 65 | } 66 | -------------------------------------------------------------------------------- /net/tcpretranshosts.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpretranshosts.d Show TCP hosts for retransmitted segments. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | * 29 | * TESTED: this fbt provider based script may only work on some OS versions. 30 | * 121: ok 31 | */ 32 | 33 | #pragma D option quiet 34 | 35 | dtrace:::BEGIN 36 | { 37 | trace("Tracing... Hit Ctrl-C for report.\n"); 38 | } 39 | 40 | fbt::tcp_timer:entry { self->in_tcp_timer = 1; self->retrans = 0; } 41 | fbt::tcp_timer:return { self->in_tcp_timer = 0; self->retrans = 0; } 42 | 43 | mib:::tcpRetransSegs { self->retrans = 1; } 44 | 45 | fbt::tcp_send_data:entry 46 | /self->in_tcp_timer && self->retrans/ 47 | { 48 | this->iph = (ipha_t *)args[2]->b_rptr; 49 | @[inet_ntoa(&this->iph->ipha_src), inet_ntoa(&this->iph->ipha_dst)] = count(); 50 | } 51 | 52 | dtrace:::END 53 | { 54 | printf(" %-32s %-32s %8s\n", "SRC", "DST", "COUNT"); 55 | printa(" %-32s %-32s %@8d\n", @); 56 | } 57 | -------------------------------------------------------------------------------- /system/displat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * displat.d CPU dispatcher queue latency. 4 | * 5 | * SEE ALSO: zonedisplat.d, zonecapslat.d 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | #pragma D option quiet 33 | 34 | dtrace:::BEGIN 35 | { 36 | printf("Tracing...\n"); 37 | printf("Note: outliers (> 1 secs) may be artifacts due to the "); 38 | printf("use of scalar globals (sorry).\n\n"); 39 | } 40 | 41 | sched:::enqueue 42 | /!start[args[0]->pr_lwpid, args[1]->pr_pid]/ 43 | { 44 | /* scalar global (I don't think this can be thread local) */ 45 | start[args[0]->pr_lwpid, args[1]->pr_pid] = timestamp; 46 | } 47 | 48 | sched:::dequeue 49 | /this->start = start[args[0]->pr_lwpid, args[1]->pr_pid]/ 50 | { 51 | this->time = timestamp - this->start; 52 | @ = quantize(this->time); 53 | start[args[0]->pr_lwpid, args[1]->pr_pid] = 0; 54 | } 55 | 56 | tick-1sec 57 | { 58 | printf("CPU disp queue latency (ns):"); 59 | printa(@); 60 | trunc(@); 61 | } 62 | -------------------------------------------------------------------------------- /mysql/innodb_thread_concurrency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * innodb_thread_concurrency.d measure thread concurrency sleeps 4 | * 5 | * USAGE: ./innodb_thread_concurrency.d -p mysqld_PID 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: these pid-provider probes may only work on some mysqld versions. 32 | * 5.0.51a: ok 33 | */ 34 | 35 | pid$target::srv_conc_enter_innodb:entry 36 | { 37 | self->srv = 1; 38 | } 39 | 40 | pid$target::os_thread_sleep:entry 41 | /self->srv/ 42 | { 43 | @["innodb srv sleep (ns)"] = quantize(arg0 * 1000); 44 | } 45 | 46 | pid$target::srv_conc_enter_innodb:return 47 | { 48 | self->srv = 0; 49 | } 50 | 51 | pid$target::*dispatch_command*:entry 52 | { 53 | self->start = timestamp; 54 | } 55 | 56 | pid$target::*dispatch_command*:return 57 | /self->start/ 58 | { 59 | @["query time (ns)"] = quantize(timestamp - self->start); 60 | self->start = 0; 61 | } 62 | 63 | profile:::tick-1s 64 | { 65 | printa(@); 66 | trunc(@); 67 | } 68 | -------------------------------------------------------------------------------- /system/cv_wakeup_slow.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * cv_wakeup_slow.d Show slow CV sleep to wakeup times with stacks. 4 | * 5 | * USAGE: ./cv_wakeup_slow.d [min_ms] 6 | * 7 | * By default, a minimum time of 100 ms is used. 8 | * 9 | * CDDL HEADER START 10 | * 11 | * The contents of this file are subject to the terms of the 12 | * Common Development and Distribution License, Version 1.0 only 13 | * (the "License"). You may not use this file except in compliance 14 | * with the License. 15 | * 16 | * You can obtain a copy of the license at http://smartos.org/CDDL 17 | * 18 | * See the License for the specific language governing permissions 19 | * and limitations under the License. 20 | * 21 | * When distributing Covered Code, include this CDDL HEADER in each 22 | * file. 23 | * 24 | * If applicable, add the following below this CDDL HEADER, with the 25 | * fields enclosed by brackets "[]" replaced with your own identifying 26 | * information: Portions Copyright [yyyy] [name of copyright owner] 27 | * 28 | * CDDL HEADER END 29 | * 30 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 31 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 32 | */ 33 | 34 | #pragma D option defaultargs 35 | #pragma D option switchrate=10hz 36 | 37 | BEGIN 38 | { 39 | min_ns = $1 ? $1 * 1000000 : 100 * 1000000; 40 | } 41 | 42 | sched:::sleep 43 | /execname == "httpd" && curlwpsinfo->pr_stype == SOBJ_CV/ 44 | { 45 | bedtime[curlwpsinfo->pr_addr] = timestamp; 46 | } 47 | 48 | sched:::wakeup 49 | /bedtime[args[0]->pr_addr] && 50 | ((this->delta = timestamp - bedtime[args[0]->pr_addr]) > min_ns)/ 51 | { 52 | printf("%d %d %d %d %s... %d ms", 53 | args[1]->pr_pid, args[0]->pr_lwpid, pid, curlwpsinfo->pr_lwpid, execname, 54 | this->delta / 1000000); 55 | stack(); 56 | bedtime[args[0]->pr_addr] = 0; 57 | } 58 | 59 | sched:::wakeup 60 | /bedtime[args[0]->pr_addr]/ 61 | { 62 | bedtime[args[0]->pr_addr] = 0; 63 | } 64 | -------------------------------------------------------------------------------- /system/zonecapslat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zonecapslat.d CPU caps latency by zone. 4 | * 5 | * This is the latency injected by cpu-caps; it acts like dispatcher 6 | * queue latency - leaving threads waiting while in the run state. 7 | * If zones are hitting this, it means they are hitting their CPU caps. 8 | * 9 | * SEE ALSO: zonedisplat.d 10 | * 11 | * CDDL HEADER START 12 | * 13 | * The contents of this file are subject to the terms of the 14 | * Common Development and Distribution License, Version 1.0 only 15 | * (the "License"). You may not use this file except in compliance 16 | * with the License. 17 | * 18 | * You can obtain a copy of the license at http://smartos.org/CDDL 19 | * 20 | * See the License for the specific language governing permissions 21 | * and limitations under the License. 22 | * 23 | * When distributing Covered Code, include this CDDL HEADER in each 24 | * file. 25 | * 26 | * If applicable, add the following below this CDDL HEADER, with the 27 | * fields enclosed by brackets "[]" replaced with your own identifying 28 | * information: Portions Copyright [yyyy] [name of copyright owner] 29 | * 30 | * CDDL HEADER END 31 | * 32 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 33 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 34 | */ 35 | 36 | #pragma D option quiet 37 | 38 | sched:::cpucaps-sleep 39 | { 40 | start[args[0]->pr_lwpid, args[1]->pr_pid] = timestamp; 41 | } 42 | 43 | sched:::cpucaps-wakeup 44 | /this->start = start[args[0]->pr_lwpid, args[1]->pr_pid]/ 45 | { 46 | this->time = timestamp - this->start; 47 | /* workaround since zonename isn't a member of args[1]... */ 48 | this->zone = ((proc_t *)args[1]->pr_addr)->p_zone->zone_name; 49 | @[stringof(this->zone)] = quantize(this->time); 50 | start[args[0]->pr_lwpid, args[1]->pr_pid] = 0; 51 | } 52 | 53 | tick-1sec 54 | { 55 | printf("CPU caps latency by zone (ns):\n"); 56 | printa(@); 57 | trunc(@); 58 | } 59 | -------------------------------------------------------------------------------- /mysql/mysqld_command.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_command.d Commands with latency distributions. 4 | * 5 | * USAGE: ./mysqld_command.d 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: not yet! need a mysqld that has the command-start/done probes. 32 | * 33 | * 25-Jun-2013 Brendan Gregg Created this. 34 | */ 35 | 36 | #pragma D option quiet 37 | 38 | dtrace:::BEGIN 39 | { 40 | printf("Tracing mysqld commands... Hit Ctrl-C to end.\n"); 41 | } 42 | 43 | mysql*:::command-start 44 | { 45 | self->start = timestamp; 46 | self->cmd = arg1; 47 | } 48 | 49 | mysql*:::command-done 50 | /self->start/ 51 | { 52 | @time[pid, self->cmd] = quantize(timestamp - self->start); 53 | @num = count(); 54 | self->start = 0; 55 | self->cmd = 0; 56 | } 57 | 58 | profile:::tick-1s 59 | { 60 | printf("\nMySQL commands/second total: "); 61 | printa("%@d; commands latency (ns) by pid & cmd:", @num); 62 | printa(@time); 63 | clear(@time); 64 | clear(@num); 65 | } 66 | 67 | dtrace:::END 68 | { 69 | trunc(@time); 70 | trunc(@num); 71 | } 72 | -------------------------------------------------------------------------------- /net/tcp-fbt-accept_sdc5.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcp-fbt-accept.d Trace TCP inbound connections using the fbt provider. 4 | * 5 | * This is for use when the tcp provider is unavailable. Also, all inbound 6 | * connections are traced, whether they are dropped (listenDrop) or not. 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | * 32 | * TESTED: this fbt provider based script may only work on some OS versions. 33 | * 121: ok 34 | */ 35 | 36 | #pragma D option quiet 37 | #pragma D option switchrate=10 38 | 39 | dtrace:::BEGIN 40 | { 41 | printf("%-20s %-18s %-5s %-18s %-5s\n", "TIME", 42 | "SRC-IP", "PORT", "DST-IP", "PORT"); 43 | } 44 | 45 | fbt::tcp_conn_request:entry 46 | { 47 | this->iph = (ipha_t *)args[1]->b_rptr; 48 | this->tcph = (tcph_t *)(args[1]->b_rptr + 20); 49 | printf("%-20Y %-18s %-5d -> %-18s %-5d\n", walltimestamp, 50 | inet_ntoa(&this->iph->ipha_src), 51 | ntohs(*(uint16_t *)this->tcph->th_lport), 52 | inet_ntoa(&this->iph->ipha_dst), 53 | ntohs(*(uint16_t *)this->tcph->th_fport)); 54 | } 55 | -------------------------------------------------------------------------------- /postgres/postgres_slower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * postgres_slower.d Trace queries slower than specified ms. 4 | * 5 | * USAGE: ./postgres_slower.d min_ms 6 | * 7 | * Uses the postgres DTrace provider. 8 | * 9 | * CDDL HEADER START 10 | * 11 | * The contents of this file are subject to the terms of the 12 | * Common Development and Distribution License, Version 1.0 only 13 | * (the "License"). You may not use this file except in compliance 14 | * with the License. 15 | * 16 | * You can obtain a copy of the license at http://smartos.org/CDDL 17 | * 18 | * See the License for the specific language governing permissions 19 | * and limitations under the License. 20 | * 21 | * When distributing Covered Code, include this CDDL HEADER in each 22 | * file. 23 | * 24 | * If applicable, add the following below this CDDL HEADER, with the 25 | * fields enclosed by brackets "[]" replaced with your own identifying 26 | * information: Portions Copyright [yyyy] [name of copyright owner] 27 | * 28 | * CDDL HEADER END 29 | * 30 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 31 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 32 | */ 33 | 34 | #pragma D option quiet 35 | #pragma D option defaultargs 36 | #pragma D option switchrate=10hz 37 | 38 | dtrace:::BEGIN 39 | { 40 | min_ns = $1 * 1000000; 41 | printf("Tracing... Min query time: %d ms.\n\n", $1); 42 | printf(" %-8s %-8s %s\n", "TIME(ms)", "CPU(ms)", "QUERY"); 43 | } 44 | 45 | postgres*:::query-start 46 | { 47 | self->start = timestamp; 48 | self->vstart = vtimestamp; 49 | } 50 | 51 | postgres*:::query-done 52 | /self->start && (timestamp - self->start) > min_ns/ 53 | { 54 | this->time = (timestamp - self->start) / 1000000; 55 | this->vtime = (vtimestamp - self->vstart) / 1000000; 56 | printf(" %-8d %-8d %S\n", this->time, this->vtime, copyinstr(arg0)); 57 | } 58 | 59 | postgres*:::query-done 60 | { 61 | self->query = 0; 62 | self->start = 0; 63 | self->vstart = 0; 64 | } 65 | -------------------------------------------------------------------------------- /system/zonecalls.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zonecalls.d show top 25 syscalls by zone and process. 4 | * 5 | * USAGE: ./zonecalls.d [interval] # default 1 sec 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | #pragma D option quiet 33 | #pragma D option defaultargs 34 | #pragma D option bufsize=512k 35 | 36 | inline int TOP = 25; 37 | 38 | dtrace:::BEGIN 39 | { 40 | interval = $1 ? $1 : 1; 41 | } 42 | 43 | dtrace:::BEGIN 44 | { 45 | printf("Top %d syscalls by zone and process. Output every %d secs.\n", 46 | TOP, interval); 47 | secs = interval; 48 | } 49 | 50 | syscall:::entry 51 | { 52 | @[zonename, execname, probefunc] = count(); 53 | @["", "", "TOTAL"] = count(); 54 | } 55 | 56 | profile:::tick-1sec 57 | { 58 | secs--; 59 | } 60 | 61 | profile:::tick-1sec 62 | /secs == 0/ 63 | { 64 | trunc(@, TOP + 1); 65 | printf("\n %-20s %-20s %-20s %s\n", "ZONE", "PROCESS", "SYSCALL", 66 | "COUNT"); 67 | printa(" %-20s %-20s %-20s %@d\n", @); 68 | secs = interval; 69 | trunc(@); 70 | } 71 | 72 | dtrace:::END 73 | { 74 | trunc(@); 75 | } 76 | -------------------------------------------------------------------------------- /system/zonedisplat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zonedisplat.d CPU dispatcher queue latency by zone. 4 | * 5 | * SEE ALSO: displat.d, zonecapslat.d 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | #pragma D option quiet 33 | 34 | dtrace:::BEGIN 35 | { 36 | printf("Tracing...\n"); 37 | printf("Note: outliers (> 1 secs) may be artifacts due to the "); 38 | printf("use of scalar globals (sorry).\n\n"); 39 | } 40 | 41 | sched:::enqueue 42 | { 43 | /* scalar global (I don't think this can be thread local) */ 44 | start[args[0]->pr_lwpid, args[1]->pr_pid] = timestamp; 45 | } 46 | 47 | sched:::dequeue 48 | /this->start = start[args[0]->pr_lwpid, args[1]->pr_pid]/ 49 | { 50 | this->time = timestamp - this->start; 51 | /* workaround since zonename isn't a member of args[1]... */ 52 | this->zone = ((proc_t *)args[1]->pr_addr)->p_zone->zone_name; 53 | @[stringof(this->zone)] = quantize(this->time); 54 | start[args[0]->pr_lwpid, args[1]->pr_pid] = 0; 55 | } 56 | 57 | tick-1sec 58 | { 59 | printf("CPU disp queue latency by zone (ns):\n"); 60 | printa(@); 61 | trunc(@); 62 | } 63 | -------------------------------------------------------------------------------- /net/tcp-fbt-accept_sdc6.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcp-fbt-accept.d Trace TCP inbound connections using the fbt provider. 4 | * 5 | * This is for use when the tcp provider is unavailable. Also, all inbound 6 | * connections are traced, whether they are dropped (listenDrop) or not. 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | * 32 | * TESTED: this fbt provider based script may only work on some OS versions. 33 | * SDC 6.5: ok (possibly illumos, nevada 148 and newer) 34 | */ 35 | 36 | #pragma D option quiet 37 | #pragma D option switchrate=10 38 | 39 | dtrace:::BEGIN 40 | { 41 | printf("%-20s %-18s %-5s %-18s %-5s\n", "TIME", 42 | "SRC-IP", "PORT", "DST-IP", "PORT"); 43 | } 44 | 45 | fbt::tcp_input_listener:entry 46 | { 47 | this->iph = (ipha_t *)args[1]->b_rptr; 48 | this->tcph = (tcph_t *)(args[1]->b_rptr + 20); 49 | printf("%-20Y %-18s %-5d -> %-18s %-5d\n", walltimestamp, 50 | inet_ntoa(&this->iph->ipha_src), 51 | ntohs(*(uint16_t *)this->tcph->th_lport), 52 | inet_ntoa(&this->iph->ipha_dst), 53 | ntohs(*(uint16_t *)this->tcph->th_fport)); 54 | } 55 | -------------------------------------------------------------------------------- /zfs/spasync.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * spasync.d Trace ZFS spa_sync() with details. 4 | * 5 | * From Chap 5 in the DTrace book, and based on spasync.d from Ben, Roch, Matt. 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | #pragma D option quiet 33 | 34 | inline int MIN_MS = 1; 35 | 36 | dtrace:::BEGIN 37 | { 38 | printf("Tracing ZFS spa_sync() slower than %d ms...\n", MIN_MS); 39 | @bytes = sum(0); 40 | } 41 | 42 | fbt::spa_sync:entry 43 | /!self->start/ 44 | { 45 | in_spa_sync = 1; 46 | self->start = timestamp; 47 | self->spa = args[0]; 48 | } 49 | 50 | io:::start 51 | /in_spa_sync/ 52 | { 53 | @io = count(); 54 | @bytes = sum(args[0]->b_bcount); 55 | } 56 | 57 | fbt::spa_sync:return 58 | /self->start && (this->ms = (timestamp - self->start) / 1000000) > MIN_MS/ 59 | { 60 | normalize(@bytes, 1048576); 61 | printf("%-20Y %-10s %6d ms, ", walltimestamp, 62 | stringof(self->spa->spa_name), this->ms); 63 | printa("%@d MB %@d I/O\n", @bytes, @io); 64 | } 65 | 66 | fbt::spa_sync:return 67 | { 68 | self->start = 0; self->spa = 0; in_spa_sync = 0; 69 | clear(@bytes); clear(@io); 70 | } 71 | 72 | -------------------------------------------------------------------------------- /go/lib/go.d: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright (c) 2013, Joyent, Inc. All rights reserved. 23 | */ 24 | 25 | inline uintptr_t goarg0 = *(uintptr_t *)copyin(uregs[R_SP] + 1 * sizeof (uintptr_t), sizeof (uintptr_t)); 26 | inline uintptr_t goarg1 = *(uintptr_t *)copyin(uregs[R_SP] + 2 * sizeof (uintptr_t), sizeof (uintptr_t)); 27 | inline uintptr_t goarg2 = *(uintptr_t *)copyin(uregs[R_SP] + 3 * sizeof (uintptr_t), sizeof (uintptr_t)); 28 | inline uintptr_t goarg3 = *(uintptr_t *)copyin(uregs[R_SP] + 4 * sizeof (uintptr_t), sizeof (uintptr_t)); 29 | inline uintptr_t goarg4 = *(uintptr_t *)copyin(uregs[R_SP] + 5 * sizeof (uintptr_t), sizeof (uintptr_t)); 30 | inline uintptr_t goarg5 = *(uintptr_t *)copyin(uregs[R_SP] + 6 * sizeof (uintptr_t), sizeof (uintptr_t)); 31 | inline uintptr_t goarg6 = *(uintptr_t *)copyin(uregs[R_SP] + 7 * sizeof (uintptr_t), sizeof (uintptr_t)); 32 | inline uintptr_t goarg7 = *(uintptr_t *)copyin(uregs[R_SP] + 8 * sizeof (uintptr_t), sizeof (uintptr_t)); 33 | inline uintptr_t goarg8 = *(uintptr_t *)copyin(uregs[R_SP] + 9 * sizeof (uintptr_t), sizeof (uintptr_t)); 34 | inline uintptr_t goarg9 = *(uintptr_t *)copyin(uregs[R_SP] + 10 * sizeof (uintptr_t), sizeof (uintptr_t)); 35 | -------------------------------------------------------------------------------- /net/tcplistendrop_sdc5.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcplistendrop.d Trace tcpListenDrop events. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | * 29 | * TESTED: this fbt provider based script may only work on some OS versions. 30 | * 121: ok 31 | */ 32 | 33 | #pragma D option quiet 34 | #pragma D option switchrate=10 35 | 36 | dtrace:::BEGIN 37 | { 38 | printf("%-20s %-18s %-5s %-18s %-5s\n", "TIME", 39 | "SRC-IP", "PORT", "DST-IP", "PORT"); 40 | } 41 | 42 | fbt::tcp_conn_request:entry { self->mp = args[1]; } 43 | fbt::tcp_conn_request:return { self->mp = 0; } 44 | 45 | mib:::tcpListenDrop 46 | /self->mp/ 47 | { 48 | this->iph = (ipha_t *)self->mp->b_rptr; 49 | this->tcph = (tcph_t *)(self->mp->b_rptr + 20); 50 | printf("%-20Y %-18s %-5d -> %-18s %-5d\n", walltimestamp, 51 | inet_ntoa(&this->iph->ipha_src), 52 | ntohs(*(uint16_t *)this->tcph->th_lport), 53 | inet_ntoa(&this->iph->ipha_dst), 54 | ntohs(*(uint16_t *)this->tcph->th_fport)); 55 | } 56 | 57 | mib:::tcpListenDrop 58 | /!self->mp/ 59 | { 60 | /* shouldn't be here */ 61 | printf("--- missing mblk_t; no tcp_conn_request()? ---\n"); 62 | stack(); 63 | } 64 | -------------------------------------------------------------------------------- /system/zonetop.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zonetop.d Lightweight zone CPU usage. 4 | * 5 | * USAGE: zonetop.d zonename 6 | * 7 | * For use when "prstat -z" is too slow/heavyweight/laggy. 8 | * 9 | * SEE ALSO: zonecpu.d 10 | * 11 | * CDDL HEADER START 12 | * 13 | * The contents of this file are subject to the terms of the 14 | * Common Development and Distribution License, Version 1.0 only 15 | * (the "License"). You may not use this file except in compliance 16 | * with the License. 17 | * 18 | * You can obtain a copy of the license at http://smartos.org/CDDL 19 | * 20 | * See the License for the specific language governing permissions 21 | * and limitations under the License. 22 | * 23 | * When distributing Covered Code, include this CDDL HEADER in each 24 | * file. 25 | * 26 | * If applicable, add the following below this CDDL HEADER, with the 27 | * fields enclosed by brackets "[]" replaced with your own identifying 28 | * information: Portions Copyright [yyyy] [name of copyright owner] 29 | * 30 | * CDDL HEADER END 31 | * 32 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 33 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 34 | */ 35 | 36 | #pragma D option quiet 37 | #pragma D option bufsize=32k 38 | #pragma D option aggsize=32k 39 | #pragma D option dynvarsize=32k 40 | #pragma D option defaultargs 41 | 42 | dtrace:::BEGIN 43 | /$$1 == ""/ 44 | { 45 | printf("USAGE: zonetop.d zonename\n"); 46 | exit(1); 47 | } 48 | 49 | dtrace:::BEGIN 50 | { 51 | printf("Sampling zone %s at 97 Hertz...\n", $$1); 52 | } 53 | 54 | profile:::profile-97 55 | /arg0 && zonename == $$1/ 56 | { 57 | @app_sys[execname] = count(); 58 | } 59 | 60 | profile:::profile-97 61 | /arg1 && zonename == $$1/ 62 | { 63 | @app_usr[execname] = count(); 64 | } 65 | 66 | profile:::tick-1s 67 | { 68 | printf("\n%Y: processes @97 Hz (usr, sys):\n", 69 | walltimestamp); 70 | printa(" %-44s %@8d %@8d\n", @app_usr, @app_sys); 71 | } 72 | 73 | profile:::tick-1s, 74 | dtrace:::END 75 | { 76 | trunc(@app_usr); trunc(@app_sys); 77 | } 78 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_querys.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_querys.d Print query count per interval. 4 | * 5 | * USAGE: ./mysqld_pid_querys.d mysqld_PID [interval] 6 | * 7 | * This delibrately avoids using -p and $target so that it can be run 8 | * while other DTrace is used. 9 | * 10 | * CDDL HEADER START 11 | * 12 | * The contents of this file are subject to the terms of the 13 | * Common Development and Distribution License, Version 1.0 only 14 | * (the "License"). You may not use this file except in compliance 15 | * with the License. 16 | * 17 | * You can obtain a copy of the license at http://smartos.org/CDDL 18 | * 19 | * See the License for the specific language governing permissions 20 | * and limitations under the License. 21 | * 22 | * When distributing Covered Code, include this CDDL HEADER in each 23 | * file. 24 | * 25 | * If applicable, add the following below this CDDL HEADER, with the 26 | * fields enclosed by brackets "[]" replaced with your own identifying 27 | * information: Portions Copyright [yyyy] [name of copyright owner] 28 | * 29 | * CDDL HEADER END 30 | * 31 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 32 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 33 | * 34 | * TESTED: these pid-provider probes may only work on some mysqld versions. 35 | * 5.0.51a: ok 36 | */ 37 | 38 | #pragma D option quiet 39 | #pragma D option defaultargs 40 | 41 | dtrace:::BEGIN 42 | { 43 | interval = $2 ? $2 : 600; 44 | printf("Tracing PID %d... Report every %d secs, or hit Ctrl-C.\n\n", 45 | $1, interval); 46 | secs = 0; 47 | } 48 | 49 | dtrace:::BEGIN 50 | /$1 == 0/ 51 | { 52 | printf("USAGE: ./mysqld_pid_querys.d PID [interval]\n"); 53 | exit(0); 54 | } 55 | 56 | pid$1::*dispatch_command*:entry 57 | { 58 | @num = count(); 59 | } 60 | 61 | profile:::tick-1s { secs++; } 62 | 63 | profile:::tick-1s, 64 | dtrace:::END 65 | /secs == interval || probename == "END"/ 66 | { 67 | normalize(@num, secs); 68 | printf("%Y ", walltimestamp); 69 | printa("MySQL queries/second: %@d\n", @num); 70 | clear(@num); 71 | secs = 0; 72 | } 73 | -------------------------------------------------------------------------------- /net/tcplistendrop_sdc6.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcplistendrop.d Trace tcpListenDrop events. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | * 29 | * TESTED: this fbt provider based script may only work on some OS versions. 30 | * SDC6.5: ok (possibly illumos, nevada 148 and newer) 31 | */ 32 | 33 | #pragma D option quiet 34 | #pragma D option switchrate=10 35 | 36 | dtrace:::BEGIN 37 | { 38 | printf("%-20s %-18s %-5s %-18s %-5s\n", "TIME", 39 | "SRC-IP", "PORT", "DST-IP", "PORT"); 40 | } 41 | 42 | fbt::tcp_input_listener:entry { self->mp = args[1]; } 43 | fbt::tcp_input_listener:return { self->mp = 0; } 44 | 45 | mib:::tcpListenDrop 46 | /self->mp/ 47 | { 48 | this->iph = (ipha_t *)self->mp->b_rptr; 49 | this->tcph = (tcph_t *)(self->mp->b_rptr + 20); 50 | printf("%-20Y %-18s %-5d -> %-18s %-5d\n", walltimestamp, 51 | inet_ntoa(&this->iph->ipha_src), 52 | ntohs(*(uint16_t *)this->tcph->th_lport), 53 | inet_ntoa(&this->iph->ipha_dst), 54 | ntohs(*(uint16_t *)this->tcph->th_fport)); 55 | } 56 | 57 | mib:::tcpListenDrop 58 | /!self->mp/ 59 | { 60 | /* shouldn't be here */ 61 | printf("--- missing mblk_t; no tcp_conn_request()? ---\n"); 62 | stack(); 63 | } 64 | -------------------------------------------------------------------------------- /go/oneliners.txt: -------------------------------------------------------------------------------- 1 | # function counts: 2 | dtrace -n 'pid$target:a.out::entry { @[probefunc] = count(); }' -p PID 3 | 4 | # function counts, main package only: 5 | dtrace -n 'pid$target::main.*:entry { @[probefunc] = count(); }' -p PID 6 | 7 | # package function counts by called package name: 8 | dtrace -n 'pid$target:a.out::entry /strstr(probefunc, ".") != NULL/ { @[strtok(probefunc, ".")] = count(); }' -p PID 9 | 10 | # function timing, main package functions only: 11 | dtrace -n 'pid$target::main.*:entry { self->ts = timestamp; } pid$target::main.*:return /self->ts/ { @[probefunc, "ns"] = quantize(timestamp - self->ts); }' -p PID 12 | 13 | # profiling on-CPU user level function at 99 Hertz: 14 | dtrace -n 'profile-99 /arg1 && pid == $target/ { @[ufunc(arg1)] = count(); }' -p PID 15 | 16 | # syscall counts, for one PID: 17 | dtrace -n 'syscall:::entry /pid == $target/ { @[probefunc] = count(); }' -p PID 18 | 19 | # syscall counts, all go processes (needs kernel access): 20 | dtrace -n 'syscall:::entry /curthread->t_procp->p_parent->p_user.u_comm == "go"/ { @[probefunc] = count(); }' 21 | 22 | # go's runtime notion of syscalls, counts: 23 | dtrace -n 'pid$target:a.out:syscall.*:entry { @[probefunc] = count(); }' -p PID 24 | 25 | # runtime call counts: 26 | dtrace -n 'pid$target:a.out:runtime.*:entry { @[probefunc] = count(); }' -p PID 27 | 28 | # counting arg0 for function foo(): 29 | dtrace -n 'pid$target::main.foo:entry { @[*(uintptr_t *)copyin(uregs[R_SP] + 1 * sizeof (uintptr_t), sizeof (uintptr_t))] = count(); }' -p PID 30 | 31 | # tracing function flow for all go functions: 32 | dtrace -Fn 'pid$target:a.out::entry,pid$target:a.out::return' -p PID 33 | 34 | # tracing function flow for all main package functions: 35 | dtrace -Fn 'pid$target::main.*:entry,pid$target::main.*:return' -p PID 36 | 37 | # tracing function flow for all go functions, correct output ordering: 38 | dtrace -x temporal -Fn 'pid$target:a.out::entry,pid$target:a.out::return' -p PID 39 | 40 | # tracing function flow for all main package functions, correct output ordering: 41 | dtrace -x temporal -Fn 'pid$target::main.*:entry,pid$target::main.*:return' -p PID 42 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_latency_stat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_latency_stat.d Print query latency distribution per interval. 4 | * 5 | * USAGE: ./mysqld_pid_latency_stat.d -p mysqld_PID [interval] 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: these pid-provider probes may only work on some mysqld versions. 32 | * 5.0.51a: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | #pragma D option defaultargs 37 | 38 | dtrace:::BEGIN 39 | { 40 | interval = $1 ? $1 : 600; 41 | printf("Tracing PID %d... Report every %d secs, or hit Ctrl-C.\n\n", 42 | $target, interval); 43 | secs = 0; 44 | } 45 | 46 | pid$target::*dispatch_command*:entry 47 | { 48 | self->start = timestamp; 49 | } 50 | 51 | pid$target::*dispatch_command*:return 52 | /self->start/ 53 | { 54 | @time = quantize(timestamp - self->start); 55 | @num = count(); 56 | self->start = 0; 57 | } 58 | 59 | profile:::tick-1s { secs++; } 60 | 61 | profile:::tick-1s, 62 | dtrace:::END 63 | /secs == interval || probename == "END"/ 64 | { 65 | normalize(@num, secs); 66 | printf("%Y ", walltimestamp); 67 | printa("MySQL queries/second: %@d; query latency (ns):", @num); 68 | printa(@time); 69 | clear(@time); clear(@num); 70 | secs = 0; 71 | } 72 | -------------------------------------------------------------------------------- /go/go_pkgcounts.txt: -------------------------------------------------------------------------------- 1 | # ./go_pkgcounts.d -p 40148 1 2 | Tracing PID 40148; output every 1 secs. 3 | 4 | 2013 Nov 14 23:22:16: 5 | 6 | main 46 7 | os 6855 8 | syscall 6855 9 | sync 9140 10 | fmt 20565 11 | sync/atomic 22850 12 | runtime 33072 13 | 14 | 2013 Nov 14 23:22:17: 15 | 16 | main 42 17 | syscall 6386 18 | os 6387 19 | sync 8516 20 | fmt 19161 21 | sync/atomic 21290 22 | runtime 30860 23 | 24 | 2013 Nov 14 23:22:18: 25 | 26 | main 48 27 | os 7203 28 | syscall 7204 29 | sync 9604 30 | fmt 21609 31 | sync/atomic 24010 32 | runtime 34702 33 | 34 | 2013 Nov 14 23:22:19: 35 | 36 | main 48 37 | syscall 7194 38 | os 7195 39 | sync 9592 40 | fmt 21582 41 | sync/atomic 23982 42 | 43 | [...] 44 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_filesort.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_filesort.d Print filesort latency distribution. 4 | * 5 | * USAGE: ./mysqld_pid_filesort.d -p mysqld_PID 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: these pid-provider probes may only work on some mysqld versions. 32 | * 5.0.51a: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | 37 | dtrace:::BEGIN 38 | { 39 | printf("Tracing MySQL PID %d... Hit Ctrl-C to end.\n", $target); 40 | start = timestamp; 41 | } 42 | 43 | pid$target::*dispatch_command*:entry 44 | { 45 | @queries = count(); 46 | } 47 | 48 | pid$target::*filesort[A-Z]*:entry 49 | { 50 | self->start = timestamp; 51 | self->vstart = vtimestamp; 52 | } 53 | 54 | pid$target::*filesort[A-Z]*:return 55 | /self->start/ 56 | { 57 | @dist["time"] = quantize(timestamp - self->start); 58 | @dist["on-CPU"] = quantize(vtimestamp - self->vstart); 59 | @total["on-CPU (ms)"] = sum(vtimestamp - self->vstart); 60 | @num = count(); 61 | self->start = 0; 62 | self->vstart = 0; 63 | } 64 | 65 | dtrace:::END 66 | { 67 | @total["tracing duration (ms)"] = sum(timestamp - start); 68 | normalize(@total, 1000000); 69 | printa("MySQL filesort: %@d, from queries: %@d; latency dist (ns):\n", 70 | @num, @queries); 71 | printa(@dist); 72 | printf("Total times:\n"); 73 | printa(@total); 74 | } 75 | -------------------------------------------------------------------------------- /net/tcpretransstate.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpretransstate.d Show TCP state for retransmitted segments. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | * 29 | * TESTED: this fbt provider based script may only work on some OS versions. 30 | * 121: ok 31 | */ 32 | 33 | #pragma D option quiet 34 | 35 | dtrace:::BEGIN 36 | { 37 | /* from /usr/include/inet/tcp.h */ 38 | tcpstate[-6] = "TCPS_CLOSED"; 39 | tcpstate[-5] = "TCPS_IDLE"; 40 | tcpstate[-4] = "TCPS_BOUND"; 41 | tcpstate[-3] = "TCPS_LISTEN"; 42 | tcpstate[-2] = "TCPS_SYN_SENT"; 43 | tcpstate[-1] = "TCPS_SYN_RCVD"; 44 | tcpstate[0] = "TCPS_ESTABLISHED"; 45 | tcpstate[1] = "TCPS_CLOSE_WAIT"; 46 | tcpstate[2] = "TCPS_FIN_WAIT_1"; 47 | tcpstate[3] = "TCPS_CLOSING"; 48 | tcpstate[4] = "TCPS_LAST_ACK"; 49 | tcpstate[5] = "TCPS_FIN_WAIT_2"; 50 | tcpstate[6] = "TCPS_TIME_WAIT"; 51 | trace("Tracing... Hit Ctrl-C for summary.\n"); 52 | } 53 | 54 | fbt::tcp_timer:entry { self->in_tcp_timer = 1; self->retrans = 0; } 55 | fbt::tcp_timer:return { self->in_tcp_timer = 0; self->retrans = 0; } 56 | 57 | mib:::tcpRetransSegs { self->retrans = 1; } 58 | 59 | fbt::tcp_send_data:entry 60 | /self->in_tcp_timer && self->retrans/ 61 | { 62 | this->state = tcpstate[args[0]->tcp_state] != NULL ? 63 | tcpstate[args[0]->tcp_state] : ""; 64 | @[this->state] = count(); 65 | self->retrans = 0; 66 | } 67 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_slow.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_slow.d Trace queries slower than specified ms. 4 | * 5 | * USAGE: ./mysqld_pid_slow.d -p mysqld_PID min_ms 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: these pid-provider probes may only work on some mysqld versions. 32 | * 5.0.51a: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | #pragma D option defaultargs 37 | #pragma D option switchrate=10hz 38 | 39 | dtrace:::BEGIN 40 | /$1 == 0/ 41 | { 42 | printf("USAGE: %s -p PID min_ms\n\n", $$0); 43 | printf("\teg: %s -p 12345 100\n", $$0); 44 | exit(1); 45 | } 46 | 47 | dtrace:::BEGIN 48 | { 49 | min_ns = $1 * 1000000; 50 | printf("Tracing... Min query time: %d ns.\n\n", min_ns); 51 | printf(" %-8s %-8s %s\n", "TIME(ms)", "CPU(ms)", "QUERY"); 52 | } 53 | 54 | pid$target::*dispatch_command*:entry 55 | { 56 | self->query = copyinstr(arg2); 57 | self->start = timestamp; 58 | self->vstart = vtimestamp; 59 | } 60 | 61 | pid$target::*dispatch_command*:return 62 | /self->start && (timestamp - self->start) > min_ns/ 63 | { 64 | this->time = (timestamp - self->start) / 1000000; 65 | this->vtime = (vtimestamp - self->vstart) / 1000000; 66 | printf(" %-8d %-8d %S\n", this->time, this->vtime, self->query); 67 | } 68 | 69 | pid$target::*dispatch_command*:return 70 | { 71 | self->query = 0; 72 | self->start = 0; 73 | self->vstart = 0; 74 | } 75 | -------------------------------------------------------------------------------- /redis/redislat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * redislat.d - summarize redis request latency 4 | * 5 | * This measures redis request latency as the time from a read() return to a 6 | * write() entry on the same file descriptor. The intent is to measure the 7 | * time between readQueryFromClient() to sendReplyToClient(), but by using 8 | * the syscall provider to minimize overhead. If this strategy turns out to 9 | * be invalid, switch this to the pid provider. 10 | * 11 | * CDDL HEADER START 12 | * 13 | * The contents of this file are subject to the terms of the 14 | * Common Development and Distribution License, Version 1.0 only 15 | * (the "License"). You may not use this file except in compliance 16 | * with the License. 17 | * 18 | * You can obtain a copy of the license at http://smartos.org/CDDL 19 | * 20 | * See the License for the specific language governing permissions 21 | * and limitations under the License. 22 | * 23 | * When distributing Covered Code, include this CDDL HEADER in each 24 | * file. 25 | * 26 | * If applicable, add the following below this CDDL HEADER, with the 27 | * fields enclosed by brackets "[]" replaced with your own identifying 28 | * information: Portions Copyright [yyyy] [name of copyright owner] 29 | * 30 | * CDDL HEADER END 31 | * 32 | * Copyright (c) 2013 Joyent Inc., All rights reserved. 33 | * Copyright (c) 2013 Brendan Gregg, All rights reserved. 34 | */ 35 | 36 | syscall::read:entry 37 | /execname == "redis-server"/ 38 | { 39 | self->fd = arg0; 40 | self->ok = 1; 41 | } 42 | 43 | syscall::read:return 44 | /self->ok/ 45 | { 46 | self->start[self->fd] = timestamp; 47 | self->fd = 0; 48 | self->ok = 0; 49 | } 50 | 51 | syscall::write:entry 52 | /(this->start = self->start[arg0]) > 0/ 53 | { 54 | @d["read->write dist (ns), for pid:", pid] = 55 | quantize(timestamp - this->start); 56 | @s[pid, tid] = sum(timestamp - this->start); 57 | self->start[arg0] = 0; 58 | } 59 | 60 | syscall::close:entry 61 | /self->start[arg0]/ 62 | { 63 | self->start[arg0] = 0; 64 | } 65 | 66 | profile:::tick-1s 67 | { 68 | normalize(@s, 1000000); 69 | printf("\nread->write sum by pid, tid (ms):\n"); 70 | printa(@s); 71 | trunc(@s); 72 | } 73 | 74 | dtrace:::END 75 | { 76 | printa(@d); 77 | trunc(@d); 78 | trunc(@s); 79 | } 80 | -------------------------------------------------------------------------------- /zfs/zfswhozone.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zfswhozone.d Show ZFS/VFS calls by zone and process. 4 | * 5 | * Most common ZFS/VFS operations are included. Customize as needed. 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: this fbt provider based script may only work on some OS versions. 32 | * 121: ok 33 | */ 34 | 35 | #pragma D option defaultargs 36 | #pragma D option quiet 37 | 38 | inline int TOP = 25; 39 | 40 | dtrace:::BEGIN 41 | { 42 | interval = $1 ? $1 : 1; 43 | } 44 | 45 | dtrace:::BEGIN 46 | { 47 | printf("Top %d ZFS/VFS calls by zone and process. Output every %d secs.\n", 48 | TOP, interval); 49 | secs = interval; 50 | } 51 | 52 | fbt::zfs_read:entry, 53 | fbt::zfs_write:entry, 54 | fbt::zfs_ioctl:entry, 55 | fbt::zfs_fsync:entry, 56 | fbt::zfs_open:entry, 57 | fbt::zfs_close:entry, 58 | fbt::zfs_getattr:entry, 59 | fbt::zfs_setattr:entry, 60 | fbt::zfs_readdir:entry, 61 | fbt::zfs_create:entry, 62 | fbt::zfs_remove:entry, 63 | fbt::zfs_mkdir:entry, 64 | fbt::zfs_rmdir:entry 65 | { 66 | @[zonename, execname, probefunc] = count(); 67 | } 68 | 69 | profile:::tick-1sec 70 | { 71 | secs--; 72 | } 73 | 74 | profile:::tick-1sec 75 | /secs == 0/ 76 | { 77 | trunc(@, TOP); 78 | printf("\n %20s %18s %12s %8s\n", "ZONE", "EXEC", "VFS", "COUNT"); 79 | printa(" %20s %18s %12s %@8d\n", @); 80 | secs = interval; 81 | trunc(@); 82 | } 83 | 84 | dtrace:::END 85 | { 86 | trunc(@); 87 | } 88 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_avg.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_avg.d Print average query latency every second, plus more. 4 | * 5 | * USAGE: ./mysqld_pid_avg.d -p mysqld_PID 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: these pid-provider probes may only work on some mysqld versions. 32 | * 5.0.51a: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | 37 | dtrace:::BEGIN 38 | { 39 | printf("Tracing PID %d...\n\n", $target); 40 | printf("%-20s %10s %8s %8s %8s\n", "TIME", "QUERIES", "1+sec_Qs", 41 | "AVG(ms)", "MAX(ms)"); 42 | } 43 | 44 | pid$target::*dispatch_command*:entry 45 | { 46 | self->start = timestamp; 47 | } 48 | 49 | pid$target::*dispatch_command*:return 50 | /self->start && (this->time = (timestamp - self->start))/ 51 | { 52 | @avg = avg(this->time); 53 | @max = max(this->time); 54 | @num = count(); 55 | } 56 | 57 | pid$target::*dispatch_command*:return 58 | /self->start && (this->time > 1000000000)/ 59 | { 60 | @slow = count(); 61 | } 62 | 63 | pid$target::*dispatch_command*:return 64 | { 65 | self->start = 0; 66 | } 67 | 68 | profile:::tick-1s 69 | { 70 | normalize(@avg, 1000000); 71 | normalize(@max, 1000000); 72 | printf("%Y ", walltimestamp); 73 | printa("%@10d %@8d %@8d %@8d", @num, @slow, @avg, @max); 74 | printf("\n"); 75 | clear(@num); clear(@slow); clear(@avg); clear(@max); 76 | } 77 | 78 | dtrace:::END 79 | { 80 | trunc(@num); trunc(@slow); trunc(@avg); trunc(@max); 81 | } 82 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_fslatency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_fslatency.d Print file system latency distribution. 4 | * 5 | * USAGE: ./mysqld_pid_fslatency.d -p mysqld_PID 6 | * 7 | * NOTE: This is designed to be runable from a zone. From the global zone, 8 | * you can use mysqld_zfs_latency.d 9 | * 10 | * CDDL HEADER START 11 | * 12 | * The contents of this file are subject to the terms of the 13 | * Common Development and Distribution License, Version 1.0 only 14 | * (the "License"). You may not use this file except in compliance 15 | * with the License. 16 | * 17 | * You can obtain a copy of the license at http://smartos.org/CDDL 18 | * 19 | * See the License for the specific language governing permissions 20 | * and limitations under the License. 21 | * 22 | * When distributing Covered Code, include this CDDL HEADER in each 23 | * file. 24 | * 25 | * If applicable, add the following below this CDDL HEADER, with the 26 | * fields enclosed by brackets "[]" replaced with your own identifying 27 | * information: Portions Copyright [yyyy] [name of copyright owner] 28 | * 29 | * CDDL HEADER END 30 | * 31 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 32 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 33 | * 34 | * TESTED: these pid-provider probes may only work on some mysqld versions. 35 | * 5.0.51a: ok 36 | */ 37 | 38 | #pragma D option quiet 39 | 40 | dtrace:::BEGIN 41 | { 42 | printf("Tracing PID %d... Hit Ctrl-C to end.\n", $target); 43 | } 44 | 45 | pid$target::os_file_read:entry, 46 | pid$target::os_file_write:entry, 47 | pid$target::my_read:entry, 48 | pid$target::my_write:entry 49 | { 50 | self->start = timestamp; 51 | } 52 | 53 | pid$target::os_file_read:return { this->dir = "read"; } 54 | pid$target::os_file_write:return { this->dir = "write"; } 55 | pid$target::my_read:return { this->dir = "read"; } 56 | pid$target::my_write:return { this->dir = "write"; } 57 | 58 | pid$target::os_file_read:return, 59 | pid$target::os_file_write:return, 60 | pid$target::my_read:return, 61 | pid$target::my_write:return 62 | /self->start/ 63 | { 64 | @time[this->dir] = quantize(timestamp - self->start); 65 | @num = count(); 66 | self->start = 0; 67 | } 68 | 69 | dtrace:::END 70 | { 71 | printa("MySQL filesystem I/O: %@d; latency (ns):\n", @num); 72 | printa(@time); 73 | clear(@time); clear(@num); 74 | } 75 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_offcpu.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_offcpu.d Trace off-CPU time during queries, showing stacks. 4 | * 5 | * USAGE: ./mysqld_pid_offcpu.d -p mysqld_PID 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: these pid-provider probes may only work on some mysqld versions. 32 | * 5.0.51a: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | 37 | dtrace:::BEGIN 38 | { 39 | min_ns = 10000000; 40 | printf("Tracing PID %d for queries longer than %d ms\n", 41 | $target, min_ns / 1000000); 42 | printf("Hit Ctrl-C when ready for off-CPU report.\n\n"); 43 | } 44 | 45 | pid$target::*dispatch_command*:entry 46 | { 47 | self->start = timestamp; 48 | } 49 | 50 | sched:::off-cpu 51 | /self->start/ 52 | { 53 | self->off = timestamp; 54 | } 55 | 56 | sched:::on-cpu 57 | /self->off && (timestamp - self->off) > min_ns/ 58 | { 59 | @offcpu[stack(), ustack()] = quantize(timestamp - self->off); 60 | self->off = 0; 61 | } 62 | 63 | pid$target::*dispatch_command*:return 64 | /self->start && (timestamp - self->start) > min_ns/ 65 | { 66 | @time = quantize(timestamp - self->start); 67 | } 68 | 69 | pid$target::*dispatch_command*:return 70 | { 71 | self->start = 0; 72 | self->off = 0; 73 | } 74 | 75 | tick-1s, 76 | dtrace:::END 77 | { 78 | printf("MySQL query latency (ns):"); 79 | printa(@time); 80 | clear(@time); 81 | } 82 | 83 | dtrace:::END 84 | { 85 | printf("Top 10 off-CPU user & kernel stacks, by wait latency (ns):"); 86 | trunc(@offcpu, 10); 87 | } 88 | -------------------------------------------------------------------------------- /node.js/nodeslower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * nodeslower.d Show node.js HTTP server requests slower than threshold. 4 | * 5 | * USAGE: nodeslower.d [min_ms] 6 | * eg, 7 | * nodeslower.d 10 # show requests slower than 10 ms 8 | * nodeslower.d # show all requests 9 | * 10 | * Requires the node DTrace provider, and a working version of the node 11 | * translator (/usr/lib/dtrace/node.d). 12 | * 13 | * Copyright (c) 2013 Joyent Inc., All rights reserved. 14 | * Copyright (c) 2013 Brendan Gregg, All rights reserved. 15 | * 16 | * CDDL HEADER START 17 | * 18 | * The contents of this file are subject to the terms of the 19 | * Common Development and Distribution License, Version 1.0 only 20 | * (the "License"). You may not use this file except in compliance 21 | * with the License. 22 | * 23 | * You can obtain a copy of the license at http://smartos.org/CDDL 24 | * 25 | * See the License for the specific language governing permissions 26 | * and limitations under the License. 27 | * 28 | * When distributing Covered Code, include this CDDL HEADER in each 29 | * file. 30 | * 31 | * If applicable, add the following below this CDDL HEADER, with the 32 | * fields enclosed by brackets "[]" replaced with your own identifying 33 | * information: Portions Copyright [yyyy] [name of copyright owner] 34 | * 35 | * CDDL HEADER END 36 | * 37 | * 26-Jun-2013 Brendan Gregg Created this. 38 | */ 39 | 40 | #pragma D option quiet 41 | #pragma D option defaultargs 42 | #pragma D option dynvarsize=8m 43 | #pragma D option switchrate=10 44 | 45 | dtrace:::BEGIN 46 | { 47 | min_ns = $1 * 1000000; 48 | printf("Tracing node.js HTTP server ops slower than %d ms\n", $1); 49 | printf("%-20s %-6s %6s %s\n", "TIME", "PID", "ms", "URL"); 50 | } 51 | 52 | node*:::http-server-request 53 | { 54 | this->fd = args[1]->fd; 55 | url[pid, this->fd] = args[0]->url; 56 | ts[pid, this->fd] = timestamp; 57 | } 58 | 59 | node*:::http-server-response 60 | { 61 | this->fd = args[0]->fd; 62 | /* FALLTHRU */ 63 | } 64 | 65 | node*:::http-server-response 66 | /(this->start = ts[pid, this->fd]) && 67 | (this->delta = timestamp - this->start) > min_ns/ 68 | { 69 | printf("%-20Y %-6d %6d %s\n", walltimestamp, pid, 70 | this->delta / 1000000, url[pid, this->fd]); 71 | } 72 | 73 | node*:::http-server-response 74 | /this->start/ 75 | { 76 | ts[pid, this->fd] = 0; 77 | url[pid, this->fd] = 0; 78 | } 79 | -------------------------------------------------------------------------------- /redis/redisslower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * redislat.d - summarize redis request latency 4 | * 5 | * This measures redis request latency as the time from a read() return to a 6 | * write() entry on the same file descriptor. The intent is to measure the 7 | * time between readQueryFromClient() to sendReplyToClient(), but by using 8 | * the syscall provider to minimize overhead. If this strategy turns out to 9 | * be invalid, switch this to the pid provider. 10 | * 11 | * CDDL HEADER START 12 | * 13 | * The contents of this file are subject to the terms of the 14 | * Common Development and Distribution License, Version 1.0 only 15 | * (the "License"). You may not use this file except in compliance 16 | * with the License. 17 | * 18 | * You can obtain a copy of the license at http://smartos.org/CDDL 19 | * 20 | * See the License for the specific language governing permissions 21 | * and limitations under the License. 22 | * 23 | * When distributing Covered Code, include this CDDL HEADER in each 24 | * file. 25 | * 26 | * If applicable, add the following below this CDDL HEADER, with the 27 | * fields enclosed by brackets "[]" replaced with your own identifying 28 | * information: Portions Copyright [yyyy] [name of copyright owner] 29 | * 30 | * CDDL HEADER END 31 | * 32 | * Copyright (c) 2013 Joyent Inc., All rights reserved. 33 | * Copyright (c) 2013 Brendan Gregg, All rights reserved. 34 | */ 35 | 36 | #pragma D option quiet 37 | #pragma D option dynvarsize=4m 38 | #pragma D option switchrate=5 39 | 40 | dtrace:::BEGIN 41 | { 42 | min_ns = 50 * 1000000; 43 | trace("Tracing redis-server syscalls...\n"); 44 | } 45 | 46 | syscall::read:entry 47 | /execname == "redis-server"/ 48 | { 49 | self->fd = arg0; 50 | self->buf = arg1; 51 | } 52 | 53 | syscall::read:return 54 | /self->buf/ 55 | { 56 | self->start[self->fd] = timestamp; 57 | self->query[self->fd] = copyinstr(self->buf); 58 | self->fd = 0; 59 | self->buf = 0; 60 | } 61 | 62 | syscall::write:entry 63 | /(this->start = self->start[arg0]) > 0 && (this->lat = timestamp - this->start) > min_ns/ 64 | { 65 | printf("\nredis query latency (PID %d): %d ms,\n%s\n", pid, 66 | this->lat / 1000000, self->query[arg0]); 67 | } 68 | 69 | syscall::write:entry 70 | /self->start[arg0]/ 71 | { 72 | self->start[arg0] = 0; 73 | self->query[arg0] = 0; 74 | } 75 | 76 | syscall::close:entry 77 | /self->start[arg0]/ 78 | { 79 | self->start[arg0] = 0; 80 | } 81 | -------------------------------------------------------------------------------- /mysql/mysqld_zfs_iolatency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_zfs_iolatency.d Print zfs latency distribution per second. 4 | * 5 | * USAGE: ./mysqld_zfs_iolatency.d -p mysqld_PID [interval] 6 | * 7 | * This traces all back-end I/O, including query and log. This traces ZFS, 8 | * and so only works if storage is ZFS. You also need privilege to trace 9 | * the fbt provider (dtrace_kernel). 10 | * 11 | * CDDL HEADER START 12 | * 13 | * The contents of this file are subject to the terms of the 14 | * Common Development and Distribution License, Version 1.0 only 15 | * (the "License"). You may not use this file except in compliance 16 | * with the License. 17 | * 18 | * You can obtain a copy of the license at http://smartos.org/CDDL 19 | * 20 | * See the License for the specific language governing permissions 21 | * and limitations under the License. 22 | * 23 | * When distributing Covered Code, include this CDDL HEADER in each 24 | * file. 25 | * 26 | * If applicable, add the following below this CDDL HEADER, with the 27 | * fields enclosed by brackets "[]" replaced with your own identifying 28 | * information: Portions Copyright [yyyy] [name of copyright owner] 29 | * 30 | * CDDL HEADER END 31 | * 32 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 33 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 34 | * 35 | * SEE ALSO: mysqld_pid_iolatency.d 36 | */ 37 | 38 | #pragma D option quiet 39 | #pragma D option defaultargs 40 | #pragma D option bufsize=32k 41 | 42 | dtrace:::BEGIN 43 | { 44 | interval = $1 ? $1 : 600; 45 | printf("Tracing PID %d... Report every %d secs, or hit Ctrl-C.\n\n", 46 | $target, interval); 47 | secs = 0; 48 | } 49 | 50 | fbt::zfs_read:entry, 51 | fbt::zfs_write:entry 52 | /pid == $target/ 53 | { 54 | self->start = timestamp; 55 | } 56 | 57 | fbt::zfs_read:return { this->dir = "read"; } 58 | fbt::zfs_write:return { this->dir = "write"; } 59 | 60 | fbt::zfs_read:return, 61 | fbt::zfs_write:return 62 | /self->start/ 63 | { 64 | @time[this->dir] = quantize(timestamp - self->start); 65 | @num = count(); 66 | self->start = 0; 67 | } 68 | 69 | profile:::tick-1s { secs++; } 70 | 71 | profile:::tick-1s, 72 | dtrace:::END 73 | /secs == interval || probename == "END"/ 74 | { 75 | normalize(@num, secs); 76 | printf("%Y ", walltimestamp); 77 | printa("MySQL IOPS: %@d; ZFS latency by dir (ns):\n", @num); 78 | printa(@time); 79 | clear(@time); clear(@num); 80 | secs = 0; 81 | } 82 | -------------------------------------------------------------------------------- /net/tcptimewaited.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcptimewaited.d Summarize TCP time waited ms. 4 | * 5 | * This traces the tcp_t->tcp_ms_we_have_waited value during tcp_timer(), 6 | * which TCP must track for the max rexmit interval. 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | * 32 | * TESTED: this fbt provider based script may only work on some OS versions. 33 | * 121: ok 34 | */ 35 | 36 | #pragma D option quiet 37 | 38 | dtrace:::BEGIN 39 | { 40 | /* from /usr/include/inet/tcp.h */ 41 | tcpstate[-6] = "TCPS_CLOSED"; 42 | tcpstate[-5] = "TCPS_IDLE"; 43 | tcpstate[-4] = "TCPS_BOUND"; 44 | tcpstate[-3] = "TCPS_LISTEN"; 45 | tcpstate[-2] = "TCPS_SYN_SENT"; 46 | tcpstate[-1] = "TCPS_SYN_RCVD"; 47 | tcpstate[0] = "TCPS_ESTABLISHED"; 48 | tcpstate[1] = "TCPS_CLOSE_WAIT"; 49 | tcpstate[2] = "TCPS_FIN_WAIT_1"; 50 | tcpstate[3] = "TCPS_CLOSING"; 51 | tcpstate[4] = "TCPS_LAST_ACK"; 52 | tcpstate[5] = "TCPS_FIN_WAIT_2"; 53 | tcpstate[6] = "TCPS_TIME_WAIT"; 54 | 55 | printf("Tracing... Hit Ctrl-C to end.\n"); 56 | } 57 | 58 | fbt::tcp_timer:entry 59 | { 60 | this->connp = (conn_t *)arg0; 61 | this->tcp = (tcp_t *)this->connp->conn_proto_priv.cp_tcp; 62 | this->waited = this->tcp->tcp_ms_we_have_waited; 63 | } 64 | 65 | fbt::tcp_timer:entry 66 | /this->waited/ 67 | { 68 | this->fport = ntohs(this->tcp->tcp_connp->u_port.tcpu_ports.tcpu_fport); 69 | this->state = tcpstate[this->tcp->tcp_state] != NULL ? 70 | tcpstate[this->tcp->tcp_state] : ""; 71 | @[this->state, this->fport] = lquantize(this->waited, 0, 20000, 100); 72 | } 73 | -------------------------------------------------------------------------------- /node.js/nodecslower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * nodecslower.d Show node.js HTTP client requests slower than threshold. 4 | * 5 | * USAGE: nodecslower.d [min_ms] 6 | * eg, 7 | * nodecslower.d 10 # show requests slower than 10 ms 8 | * nodecslower.d # show all requests 9 | * 10 | * Requires the node DTrace provider, and a working version of the node 11 | * translator (/usr/lib/dtrace/node.d). 12 | * 13 | * Copyright (c) 2013 Joyent Inc., All rights reserved. 14 | * Copyright (c) 2013 Brendan Gregg, All rights reserved. 15 | * 16 | * CDDL HEADER START 17 | * 18 | * The contents of this file are subject to the terms of the 19 | * Common Development and Distribution License, Version 1.0 only 20 | * (the "License"). You may not use this file except in compliance 21 | * with the License. 22 | * 23 | * You can obtain a copy of the license at http://smartos.org/CDDL 24 | * 25 | * See the License for the specific language governing permissions 26 | * and limitations under the License. 27 | * 28 | * When distributing Covered Code, include this CDDL HEADER in each 29 | * file. 30 | * 31 | * If applicable, add the following below this CDDL HEADER, with the 32 | * fields enclosed by brackets "[]" replaced with your own identifying 33 | * information: Portions Copyright [yyyy] [name of copyright owner] 34 | * 35 | * CDDL HEADER END 36 | * 37 | * 26-Jun-2013 Brendan Gregg Created this. 38 | */ 39 | 40 | #pragma D option quiet 41 | #pragma D option defaultargs 42 | #pragma D option dynvarsize=8m 43 | #pragma D option switchrate=10 44 | 45 | dtrace:::BEGIN 46 | { 47 | min_ns = $1 * 1000000; 48 | printf("Tracing node.js HTTP clients ops slower than %d ms\n", $1); 49 | printf("%-20s %-6s %6s %s %s\n", "TIME", "PID", "ms", "RADDR", "URL"); 50 | } 51 | 52 | node*:::http-client-request 53 | { 54 | this->fd = args[1]->fd; 55 | url[pid, this->fd] = args[0]->url; 56 | ts[pid, this->fd] = timestamp; 57 | } 58 | 59 | node*:::http-client-response 60 | { 61 | this->fd = args[0]->fd; 62 | /* FALLTHRU */ 63 | } 64 | 65 | node*:::http-client-response 66 | /(this->start = ts[pid, this->fd]) && 67 | (this->delta = timestamp - this->start) > min_ns/ 68 | { 69 | printf("%-20Y %-6d %6d %s %s\n", walltimestamp, pid, 70 | this->delta / 1000000, args[0]->remoteAddress, 71 | url[pid, this->fd]); 72 | } 73 | 74 | node*:::http-client-response 75 | /this->start/ 76 | { 77 | ts[pid, this->fd] = 0; 78 | url[pid, this->fd] = 0; 79 | } 80 | -------------------------------------------------------------------------------- /net/tcptimewait.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcptimewait.d Show TCP TIME-WAIT arrival by hosts and ports. 4 | * 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at http://smartos.org/CDDL 13 | * 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file. 19 | * 20 | * If applicable, add the following below this CDDL HEADER, with the 21 | * fields enclosed by brackets "[]" replaced with your own identifying 22 | * information: Portions Copyright [yyyy] [name of copyright owner] 23 | * 24 | * CDDL HEADER END 25 | * 26 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 27 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 28 | * 29 | * TESTED: this fbt provider based script may only work on some OS versions. 30 | * 121: ok 31 | */ 32 | 33 | #pragma D option quiet 34 | #pragma D option switchrate=10 35 | 36 | dtrace:::BEGIN 37 | { 38 | /* from /usr/include/inet/tcp.h */ 39 | tcpstate[-6] = "TCPS_CLOSED"; 40 | tcpstate[-5] = "TCPS_IDLE"; 41 | tcpstate[-4] = "TCPS_BOUND"; 42 | tcpstate[-3] = "TCPS_LISTEN"; 43 | tcpstate[-2] = "TCPS_SYN_SENT"; 44 | tcpstate[-1] = "TCPS_SYN_RCVD"; 45 | tcpstate[0] = "TCPS_ESTABLISHED"; 46 | tcpstate[1] = "TCPS_CLOSE_WAIT"; 47 | tcpstate[2] = "TCPS_FIN_WAIT_1"; 48 | tcpstate[3] = "TCPS_CLOSING"; 49 | tcpstate[4] = "TCPS_LAST_ACK"; 50 | tcpstate[5] = "TCPS_FIN_WAIT_2"; 51 | tcpstate[6] = "TCPS_TIME_WAIT"; 52 | 53 | printf("%-20s %-17s %-16s %-5s %-16s %-5s %s\n", "TIME", "TCP_STATE", 54 | "SRC-IP", "PORT", "DST-IP", "PORT", "FLAGS"); 55 | } 56 | 57 | fbt::tcp_time_wait_processing:entry 58 | { 59 | this->iph = (ipha_t *)args[1]->b_rptr; 60 | this->tcph = (tcph_t *)(args[1]->b_rptr + 20); 61 | this->state = tcpstate[args[0]->tcp_state] != NULL ? 62 | tcpstate[args[0]->tcp_state] : ""; 63 | printf("%-20Y %-17s %-16s %-5d %-16s %-5d %x\n", walltimestamp, 64 | this->state, 65 | inet_ntoa(&this->iph->ipha_src), 66 | ntohs(*(uint16_t *)this->tcph->th_lport), 67 | inet_ntoa(&this->iph->ipha_dst), 68 | ntohs(*(uint16_t *)this->tcph->th_fport), 69 | this->tcph->th_flags[0]); 70 | } 71 | -------------------------------------------------------------------------------- /net/tcpconnreqmaxq-pid_sdc5.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpconnreqmaxq-pid.d Show details for the TCP connection queue, with pid. 4 | * 5 | * This traces tcpListenDrop and the active value for tcp_conn_req_cnt_q, 6 | * to evaluate tuning of tcp_conn_req_max_q. The pid shown is the cached pid 7 | * in TCP; the actual process that created the socket may have dissapeared. 8 | * 9 | * CDDL HEADER START 10 | * 11 | * The contents of this file are subject to the terms of the 12 | * Common Development and Distribution License, Version 1.0 only 13 | * (the "License"). You may not use this file except in compliance 14 | * with the License. 15 | * 16 | * You can obtain a copy of the license at http://smartos.org/CDDL 17 | * 18 | * See the License for the specific language governing permissions 19 | * and limitations under the License. 20 | * 21 | * When distributing Covered Code, include this CDDL HEADER in each 22 | * file. 23 | * 24 | * If applicable, add the following below this CDDL HEADER, with the 25 | * fields enclosed by brackets "[]" replaced with your own identifying 26 | * information: Portions Copyright [yyyy] [name of copyright owner] 27 | * 28 | * CDDL HEADER END 29 | * 30 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 31 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 32 | * 33 | * TESTED: this fbt provider based script may only work on some OS versions. 34 | * 121: ok 35 | */ 36 | 37 | #pragma D option quiet 38 | #pragma D option switchrate=4hz 39 | 40 | dtrace:::BEGIN 41 | { 42 | printf("Tracing... Hit Ctrl-C to end.\n"); 43 | } 44 | 45 | fbt::tcp_conn_request:entry 46 | { 47 | this->connp = (conn_t *)arg0; 48 | this->tcp = (tcp_t *)this->connp->conn_proto_priv.cp_tcp; 49 | self->max = strjoin("max_q:", lltostr(this->tcp->tcp_conn_req_max)); 50 | self->pid = strjoin("cpid:", lltostr(this->tcp->tcp_cpid)); 51 | @[self->pid, self->max] = quantize(this->tcp->tcp_conn_req_cnt_q); 52 | } 53 | 54 | mib:::tcpListenDrop 55 | { 56 | this->max = self->max; 57 | this->pid = self->pid; 58 | this->max != NULL ? this->max : ""; 59 | this->pid != NULL ? this->pid : ""; 60 | @drops[this->pid, this->max] = count(); 61 | printf("%Y %s:%s %s\n", walltimestamp, probefunc, probename, this->pid); 62 | } 63 | 64 | fbt::tcp_conn_request:return 65 | { 66 | self->max = 0; 67 | self->pid = 0; 68 | } 69 | 70 | dtrace:::END 71 | { 72 | printf("tcp_conn_req_cnt_q distributions:\n"); 73 | printa(@); 74 | printf("tcpListenDrops:\n"); 75 | printa(" %-32s %-32s %@8d\n", @drops); 76 | } 77 | -------------------------------------------------------------------------------- /mysql/innodb_pid_iolatency.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * innodb_pid_iolatency.d Show storage latency distribution. 4 | * 5 | * USAGE: ./innodb_pid_iolatency.d -p mysqld_PID [interval] 6 | * 7 | * This traces innodb at the OS interface: os_file_read() and os_file_write(). 8 | * This includes back-end query I/O, but not other types including log I/O. 9 | * 10 | * CDDL HEADER START 11 | * 12 | * The contents of this file are subject to the terms of the 13 | * Common Development and Distribution License, Version 1.0 only 14 | * (the "License"). You may not use this file except in compliance 15 | * with the License. 16 | * 17 | * You can obtain a copy of the license at http://smartos.org/CDDL 18 | * 19 | * See the License for the specific language governing permissions 20 | * and limitations under the License. 21 | * 22 | * When distributing Covered Code, include this CDDL HEADER in each 23 | * file. 24 | * 25 | * If applicable, add the following below this CDDL HEADER, with the 26 | * fields enclosed by brackets "[]" replaced with your own identifying 27 | * information: Portions Copyright [yyyy] [name of copyright owner] 28 | * 29 | * CDDL HEADER END 30 | * 31 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 32 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 33 | * 34 | * TESTED: these pid-provider probes may only work on some mysqld versions. 35 | * 5.0.51a: ok 36 | * 37 | * SEE ALSO: innodb_pid_ioslow.d 38 | */ 39 | 40 | #pragma D option quiet 41 | #pragma D option defaultargs 42 | #pragma D option bufsize=32k 43 | 44 | dtrace:::BEGIN 45 | { 46 | printf("Tracing PID %d... Hit Ctrl-C to end.\n", $target); 47 | interval = $1 ? $1 : 1; 48 | secs = interval; 49 | } 50 | 51 | pid$target::*os_file_read*:entry, 52 | pid$target::*os_file_write*:entry 53 | { 54 | self->start = timestamp; 55 | } 56 | 57 | pid$target::*os_file_read*:return { this->dir = "read"; } 58 | pid$target::*os_file_write*:return { this->dir = "write"; } 59 | 60 | pid$target::*os_file_read*:return, 61 | pid$target::*os_file_write*:return 62 | /self->start/ 63 | { 64 | @time[this->dir] = quantize(timestamp - self->start); 65 | @num = count(); 66 | self->start = 0; 67 | } 68 | 69 | profile:::tick-1s 70 | { 71 | secs--; 72 | } 73 | 74 | profile:::tick-1s 75 | /secs == 0/ 76 | { 77 | normalize(@num, interval); 78 | printa("\ninnodb IOPS: %@d; storage latency by direction (ns):", 79 | @num); 80 | printa(@time); 81 | clear(@time); clear(@num); 82 | secs = interval; 83 | } 84 | 85 | dtrace:::END 86 | { 87 | trunc(@time); trunc(@num); 88 | } 89 | -------------------------------------------------------------------------------- /net/tcpconnreqmaxq-pid_sdc6.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpconnreqmaxq-pid.d Show details for the TCP connection queue, with pid. 4 | * 5 | * This traces tcpListenDrop and the active value for tcp_conn_req_cnt_q, 6 | * to evaluate tuning of tcp_conn_req_max_q. The pid shown is the cached pid 7 | * in TCP; the actual process that created the socket may have dissapeared. 8 | * 9 | * CDDL HEADER START 10 | * 11 | * The contents of this file are subject to the terms of the 12 | * Common Development and Distribution License, Version 1.0 only 13 | * (the "License"). You may not use this file except in compliance 14 | * with the License. 15 | * 16 | * You can obtain a copy of the license at http://smartos.org/CDDL 17 | * 18 | * See the License for the specific language governing permissions 19 | * and limitations under the License. 20 | * 21 | * When distributing Covered Code, include this CDDL HEADER in each 22 | * file. 23 | * 24 | * If applicable, add the following below this CDDL HEADER, with the 25 | * fields enclosed by brackets "[]" replaced with your own identifying 26 | * information: Portions Copyright [yyyy] [name of copyright owner] 27 | * 28 | * CDDL HEADER END 29 | * 30 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 31 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 32 | * 33 | * TESTED: this fbt provider based script may only work on some OS versions. 34 | * SDC 6.5: ok (possibly illumos, nevada 148 and newer) 35 | */ 36 | 37 | #pragma D option quiet 38 | #pragma D option switchrate=4hz 39 | 40 | dtrace:::BEGIN 41 | { 42 | printf("Tracing... Hit Ctrl-C to end.\n"); 43 | } 44 | 45 | fbt::tcp_input_listener:entry 46 | { 47 | this->connp = (conn_t *)arg0; 48 | this->tcp = (tcp_t *)this->connp->conn_proto_priv.cp_tcp; 49 | self->max = strjoin("max_q:", lltostr(this->tcp->tcp_conn_req_max)); 50 | self->pid = strjoin("cpid:", lltostr(this->connp->conn_cpid)); 51 | @[self->pid, self->max] = quantize(this->tcp->tcp_conn_req_cnt_q); 52 | } 53 | 54 | mib:::tcpListenDrop 55 | { 56 | this->max = self->max; 57 | this->pid = self->pid; 58 | this->max != NULL ? this->max : ""; 59 | this->pid != NULL ? this->pid : ""; 60 | @drops[this->pid, this->max] = count(); 61 | printf("%Y %s:%s %s\n", walltimestamp, probefunc, probename, this->pid); 62 | } 63 | 64 | fbt::tcp_input_listener:return 65 | { 66 | self->max = 0; 67 | self->pid = 0; 68 | } 69 | 70 | dtrace:::END 71 | { 72 | printf("tcp_conn_req_cnt_q distributions:\n"); 73 | printa(@); 74 | printf("tcpListenDrops:\n"); 75 | printa(" %-32s %-32s %@8d\n", @drops); 76 | } 77 | -------------------------------------------------------------------------------- /zfs/zfsslowzone.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zfsslowzone.d Trace slow ZFS/VFS reads and writes. 4 | * 5 | * USAGE: zfsslowzone.d min_ms 6 | * eg, 7 | * zfsslowzone.d 50 # show I/O longer than 50 ms 8 | * 9 | * This traces at the VFS layer, so the latency shown is directly suffered 10 | * by the application. The output is wide (sorry). This script is based 11 | * on zfsslower.d from the DTrace book. 12 | * 13 | * CDDL HEADER START 14 | * 15 | * The contents of this file are subject to the terms of the 16 | * Common Development and Distribution License, Version 1.0 only 17 | * (the "License"). You may not use this file except in compliance 18 | * with the License. 19 | * 20 | * You can obtain a copy of the license at http://smartos.org/CDDL 21 | * 22 | * See the License for the specific language governing permissions 23 | * and limitations under the License. 24 | * 25 | * When distributing Covered Code, include this CDDL HEADER in each 26 | * file. 27 | * 28 | * If applicable, add the following below this CDDL HEADER, with the 29 | * fields enclosed by brackets "[]" replaced with your own identifying 30 | * information: Portions Copyright [yyyy] [name of copyright owner] 31 | * 32 | * CDDL HEADER END 33 | * 34 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 35 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 36 | * 37 | * TESTED: this fbt provider based script may only work on some OS versions. 38 | * 121: ok 39 | */ 40 | 41 | #pragma D option quiet 42 | #pragma D option defaultargs 43 | #pragma D option switchrate=10hz 44 | 45 | dtrace:::BEGIN 46 | { 47 | printf("%-20s %-16s %-12s %1s %4s %6s %s\n", "TIME", "PROCESS", 48 | "ZONE", "D", "KB", "ms", "FILE"); 49 | min_ns = $1 * 1000000; 50 | } 51 | 52 | /* see uts/common/fs/zfs/zfs_vnops.c */ 53 | 54 | fbt::zfs_read:entry, fbt::zfs_write:entry 55 | { 56 | self->path = args[0]->v_path; 57 | self->kb = args[1]->uio_resid / 1024; 58 | self->start = timestamp; 59 | } 60 | 61 | fbt::zfs_read:return, fbt::zfs_write:return 62 | /self->start && (timestamp - self->start) >= min_ns/ 63 | { 64 | this->iotime = (timestamp - self->start) / 1000000; 65 | this->dir = probefunc == "zfs_read" ? "R" : "W"; 66 | printf("%-20Y %-16s %-12s %1s %4d %6d %s\n", walltimestamp, 67 | execname, zonename, this->dir, self->kb, this->iotime, 68 | self->path != NULL ? stringof(self->path) : ""); 69 | } 70 | 71 | fbt::zfs_read:return, fbt::zfs_write:return 72 | { 73 | self->path = 0; self->kb = 0; self->start = 0; 74 | } 75 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_syscall_offcpu.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_syscall_offcpu.d Off-CPU time during query syscalls + stacks. 4 | * 5 | * USAGE: ./mysqld_pid_syscall_offcpu.d -p mysqld_PID 6 | * 7 | * This was written as a version of mysqld_pid_offcpu.d which doesn't use 8 | * the sched provider (which isn't available in the smartmachine). 9 | * 10 | * CDDL HEADER START 11 | * 12 | * The contents of this file are subject to the terms of the 13 | * Common Development and Distribution License, Version 1.0 only 14 | * (the "License"). You may not use this file except in compliance 15 | * with the License. 16 | * 17 | * You can obtain a copy of the license at http://smartos.org/CDDL 18 | * 19 | * See the License for the specific language governing permissions 20 | * and limitations under the License. 21 | * 22 | * When distributing Covered Code, include this CDDL HEADER in each 23 | * file. 24 | * 25 | * If applicable, add the following below this CDDL HEADER, with the 26 | * fields enclosed by brackets "[]" replaced with your own identifying 27 | * information: Portions Copyright [yyyy] [name of copyright owner] 28 | * 29 | * CDDL HEADER END 30 | * 31 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 32 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 33 | * 34 | * TESTED: these pid-provider probes may only work on some mysqld versions. 35 | * 5.0.51a: ok 36 | */ 37 | 38 | #pragma D option quiet 39 | #pragma D option switchrate=5hz 40 | 41 | dtrace:::BEGIN 42 | { 43 | min_ns = 10000000; 44 | printf("Tracing PID %d for queries longer than %d ms\n", 45 | $target, min_ns / 1000000); 46 | printf("Hit Ctrl-C when ready for off-CPU report.\n\n"); 47 | } 48 | 49 | pid$target::*dispatch_command*:entry 50 | { 51 | self->start = timestamp; 52 | } 53 | 54 | syscall:::entry 55 | /self->start/ 56 | { 57 | self->off_ts = timestamp; 58 | self->off_vts = vtimestamp; 59 | } 60 | 61 | syscall:::return 62 | /self->off_ts/ 63 | { 64 | this->cpu_time = vtimestamp - self->off_vts; 65 | this->off_time = timestamp - self->off_ts - this->cpu_time; 66 | } 67 | 68 | syscall:::return 69 | /self->off_ts && this->off_time > min_ns/ 70 | { 71 | @offcpu[ustack()] = quantize(this->off_time); 72 | printf("%Y captured stack @ %d ms off-CPU\n", walltimestamp, 73 | this->off_time / 1000000); 74 | } 75 | 76 | syscall:::return 77 | { 78 | self->off_ts = 0; 79 | self->off_vts = 0; 80 | } 81 | 82 | pid$target::*dispatch_command*:return 83 | { 84 | self->start = 0; 85 | } 86 | 87 | dtrace:::END 88 | { 89 | printf("Top 10 off-CPU user stacks, by wait latency (ns):"); 90 | trunc(@offcpu, 10); 91 | } 92 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_fslatency_slowlog0.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_fslatency_slowlog0.d Print slow filesystem I/O events. 4 | * 5 | * USAGE: ./mysql_pid_fslatency_slowlog0.d mysqld_PID 6 | * 7 | * This traces all mysqld filesystem I/O (including some that may be 8 | * asynchronous to queries and not causing query latency), and prints 9 | * those individual I/O taking longer than the MIN_FS_LATENCY_MS tunable. 10 | * 11 | * This is a monitoring tool (if Cloud Analytics is not available). 12 | * 13 | * CDDL HEADER START 14 | * 15 | * The contents of this file are subject to the terms of the 16 | * Common Development and Distribution License, Version 1.0 only 17 | * (the "License"). You may not use this file except in compliance 18 | * with the License. 19 | * 20 | * You can obtain a copy of the license at http://smartos.org/CDDL 21 | * 22 | * See the License for the specific language governing permissions 23 | * and limitations under the License. 24 | * 25 | * When distributing Covered Code, include this CDDL HEADER in each 26 | * file. 27 | * 28 | * If applicable, add the following below this CDDL HEADER, with the 29 | * fields enclosed by brackets "[]" replaced with your own identifying 30 | * information: Portions Copyright [yyyy] [name of copyright owner] 31 | * 32 | * CDDL HEADER END 33 | * 34 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 35 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 36 | * 37 | * TESTED: these pid-provider probes may only work on some mysqld versions. 38 | * 5.0.51a: ok 39 | */ 40 | 41 | #pragma D option quiet 42 | 43 | inline int MIN_FS_LATENCY_MS = 1000; 44 | 45 | dtrace:::BEGIN 46 | { 47 | min_ns = MIN_FS_LATENCY_MS * 1000000; 48 | } 49 | 50 | pid$1::os_file_read:entry, 51 | pid$1::os_file_write:entry, 52 | pid$1::my_read:entry, 53 | pid$1::my_write:entry 54 | { 55 | self->start = timestamp; 56 | } 57 | 58 | pid$1::os_file_read:return, 59 | pid$1::my_read:return 60 | /self->start && (timestamp - self->start) > min_ns/ 61 | { 62 | this->ms = (timestamp - self->start) / 1000000; 63 | printf("%Y filesystem read > %d ms: %d ms\n", walltimestamp, 64 | MIN_FS_LATENCY_MS, this->ms); 65 | } 66 | 67 | pid$1::os_file_write:return, 68 | pid$1::my_write:return 69 | /self->start && (timestamp - self->start) > min_ns/ 70 | { 71 | this->ms = (timestamp - self->start) / 1000000; 72 | printf("%Y filesystem write > %d ms: %d ms\n", walltimestamp, 73 | MIN_FS_LATENCY_MS, this->ms); 74 | } 75 | 76 | pid$1::os_file_read:return, 77 | pid$1::os_file_write:return, 78 | pid$1::my_read:return, 79 | pid$1::my_write:return 80 | { 81 | self->start = 0; 82 | } 83 | -------------------------------------------------------------------------------- /net/tcpsackretrans.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpsackretrans.d Trace TCP SACK fast retransmits with details. 4 | * 5 | * SEE ALSO: tcpretranssnoop*.d 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: this fbt provider based script may only work on some OS versions. 32 | * sdc6: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | #pragma D option switchrate=10hz 37 | self string retrans; 38 | 39 | dtrace:::BEGIN 40 | { 41 | /* from /usr/include/inet/tcp.h */ 42 | tcpstate[-6] = "TCPS_CLOSED"; 43 | tcpstate[-5] = "TCPS_IDLE"; 44 | tcpstate[-4] = "TCPS_BOUND"; 45 | tcpstate[-3] = "TCPS_LISTEN"; 46 | tcpstate[-2] = "TCPS_SYN_SENT"; 47 | tcpstate[-1] = "TCPS_SYN_RCVD"; 48 | tcpstate[0] = "TCPS_ESTABLISHED"; 49 | tcpstate[1] = "TCPS_CLOSE_WAIT"; 50 | tcpstate[2] = "TCPS_FIN_WAIT_1"; 51 | tcpstate[3] = "TCPS_CLOSING"; 52 | tcpstate[4] = "TCPS_LAST_ACK"; 53 | tcpstate[5] = "TCPS_FIN_WAIT_2"; 54 | tcpstate[6] = "TCPS_TIME_WAIT"; 55 | 56 | printf("%-20s %-17s %-16s %-16s %-6s\n", "TIME", 57 | "TCP_STATE", "SRC", "DST", "PORT"); 58 | } 59 | 60 | /* SACK fast retrinsmits */ 61 | fbt::tcp_sack_rexmit:entry { self->tcp = args[0]; } 62 | fbt::tcp_sack_rexmit:return { self->tcp = 0; } 63 | 64 | mib:::tcpOutSackRetransSegs 65 | /self->tcp/ 66 | { 67 | this->state = tcpstate[self->tcp->tcp_state] != NULL ? 68 | tcpstate[self->tcp->tcp_state] : ""; 69 | printf("%-20Y %-17s %-16s %-16s %-6d\n", walltimestamp, 70 | this->state, 71 | /* just look at it. LOOK at it. */ 72 | inet_ntoa(&self->tcp->tcp_connp->connua_v6addr.connua_laddr._S6_un._S6_u32[3]), 73 | inet_ntoa(&self->tcp->tcp_connp->connua_v6addr.connua_faddr._S6_un._S6_u32[3]), 74 | ntohs(self->tcp->tcp_connp->u_port.connu_ports.connu_fport)); 75 | self->tcp = 0; 76 | } 77 | -------------------------------------------------------------------------------- /net/tcptimretransdropsnoop_sdc6.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcptimeretransdropsnoop.d Snoop TCP timer retrans drops. 4 | * 5 | * This traces the tcpTimRetransDrop events from netstat -s (aka the 6 | * timRetransDrop events from kstat). 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | * 32 | * TESTED: this fbt provider based script may only work on some OS versions. 33 | */ 34 | 35 | #pragma D option quiet 36 | #pragma D option switchrate=2 37 | 38 | dtrace:::BEGIN 39 | { 40 | /* from /usr/include/inet/tcp.h */ 41 | tcpstate[-6] = "TCPS_CLOSED"; 42 | tcpstate[-5] = "TCPS_IDLE"; 43 | tcpstate[-4] = "TCPS_BOUND"; 44 | tcpstate[-3] = "TCPS_LISTEN"; 45 | tcpstate[-2] = "TCPS_SYN_SENT"; 46 | tcpstate[-1] = "TCPS_SYN_RCVD"; 47 | tcpstate[0] = "TCPS_ESTABLISHED"; 48 | tcpstate[1] = "TCPS_CLOSE_WAIT"; 49 | tcpstate[2] = "TCPS_FIN_WAIT_1"; 50 | tcpstate[3] = "TCPS_CLOSING"; 51 | tcpstate[4] = "TCPS_LAST_ACK"; 52 | tcpstate[5] = "TCPS_FIN_WAIT_2"; 53 | tcpstate[6] = "TCPS_TIME_WAIT"; 54 | 55 | printf("%-21s %-18s %-6s %-6s %7s\n", "TIME", "TCP_STATE", 56 | "PID", "LPORT", "WAIT(s)"); 57 | } 58 | 59 | fbt::tcp_timer:entry 60 | { 61 | this->connp = (conn_t *)arg0; 62 | self->tcp = (tcp_t *)this->connp->conn_proto_priv.cp_tcp; 63 | } 64 | 65 | mib:::tcpTimRetransDrop 66 | /self->tcp/ 67 | { 68 | this->waited = self->tcp->tcp_ms_we_have_waited / 1000; 69 | this->lport = ntohs(self->tcp->tcp_connp->u_port.connu_ports.connu_lport); 70 | this->pid = self->tcp->tcp_connp->conn_cpid; 71 | this->state = tcpstate[self->tcp->tcp_state] != NULL ? 72 | tcpstate[self->tcp->tcp_state] : ""; 73 | printf("%-21Y %-18s %-6d %-6d %7d\n", walltimestamp, this->state, 74 | this->pid, this->lport, this->waited); 75 | } 76 | 77 | fbt::tcp_timer:return 78 | { 79 | self->tcp = 0; 80 | } 81 | -------------------------------------------------------------------------------- /net/tcpretranssnoop_sdc5.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpretranssnoop_sdc5.d Trace TCP retransmitted segments with details. 4 | * 5 | * This only traces timer-based retransmits, and not fast retransmits. 6 | * See tcpsackretrans.d. 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | * 32 | * TESTED: this fbt provider based script may only work on some OS versions. 33 | * 121: ok 34 | */ 35 | 36 | #pragma D option quiet 37 | #pragma D option switchrate=10hz 38 | 39 | dtrace:::BEGIN 40 | { 41 | /* from /usr/include/inet/tcp.h */ 42 | tcpstate[-6] = "TCPS_CLOSED"; 43 | tcpstate[-5] = "TCPS_IDLE"; 44 | tcpstate[-4] = "TCPS_BOUND"; 45 | tcpstate[-3] = "TCPS_LISTEN"; 46 | tcpstate[-2] = "TCPS_SYN_SENT"; 47 | tcpstate[-1] = "TCPS_SYN_RCVD"; 48 | tcpstate[0] = "TCPS_ESTABLISHED"; 49 | tcpstate[1] = "TCPS_CLOSE_WAIT"; 50 | tcpstate[2] = "TCPS_FIN_WAIT_1"; 51 | tcpstate[3] = "TCPS_CLOSING"; 52 | tcpstate[4] = "TCPS_LAST_ACK"; 53 | tcpstate[5] = "TCPS_FIN_WAIT_2"; 54 | tcpstate[6] = "TCPS_TIME_WAIT"; 55 | 56 | printf("%-20s %-17s %-16s %-16s %-6s\n", "TIME", "TCP_STATE", 57 | "SRC", "DST", "PORT"); 58 | } 59 | 60 | fbt::tcp_timer:entry { self->in_tcp_timer = 1; self->retrans = 0; } 61 | fbt::tcp_timer:return { self->in_tcp_timer = 0; self->retrans = 0; } 62 | 63 | mib:::tcpRetransSegs { self->retrans = 1; } 64 | 65 | fbt::tcp_send_data:entry 66 | /self->in_tcp_timer && self->retrans/ 67 | { 68 | this->iph = (ipha_t *)args[2]->b_rptr; 69 | this->state = tcpstate[args[0]->tcp_state] != NULL ? 70 | tcpstate[args[0]->tcp_state] : ""; 71 | printf("%-20Y %-17s %-16s %-16s %-6d\n", walltimestamp, this->state, 72 | inet_ntoa(&this->iph->ipha_src), inet_ntoa(&this->iph->ipha_dst), 73 | ntohs(args[0]->tcp_connp->u_port.tcpu_ports.tcpu_fport)); 74 | self->retrans = 0; 75 | } 76 | -------------------------------------------------------------------------------- /net/tcpretranssnoop_sdc6.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpretranssnoop.d Trace TCP retransmitted segments with details. 4 | * 5 | * This only traces timer-based retransmits, and not fast retransmits. 6 | * See tcpsackretrans.d. 7 | * 8 | * CDDL HEADER START 9 | * 10 | * The contents of this file are subject to the terms of the 11 | * Common Development and Distribution License, Version 1.0 only 12 | * (the "License"). You may not use this file except in compliance 13 | * with the License. 14 | * 15 | * You can obtain a copy of the license at http://smartos.org/CDDL 16 | * 17 | * See the License for the specific language governing permissions 18 | * and limitations under the License. 19 | * 20 | * When distributing Covered Code, include this CDDL HEADER in each 21 | * file. 22 | * 23 | * If applicable, add the following below this CDDL HEADER, with the 24 | * fields enclosed by brackets "[]" replaced with your own identifying 25 | * information: Portions Copyright [yyyy] [name of copyright owner] 26 | * 27 | * CDDL HEADER END 28 | * 29 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 30 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 31 | * 32 | * TESTED: this fbt provider based script may only work on some OS versions. 33 | * sdc6: ok 34 | */ 35 | 36 | #pragma D option quiet 37 | #pragma D option switchrate=10hz 38 | 39 | dtrace:::BEGIN 40 | { 41 | /* from /usr/include/inet/tcp.h */ 42 | tcpstate[-6] = "TCPS_CLOSED"; 43 | tcpstate[-5] = "TCPS_IDLE"; 44 | tcpstate[-4] = "TCPS_BOUND"; 45 | tcpstate[-3] = "TCPS_LISTEN"; 46 | tcpstate[-2] = "TCPS_SYN_SENT"; 47 | tcpstate[-1] = "TCPS_SYN_RCVD"; 48 | tcpstate[0] = "TCPS_ESTABLISHED"; 49 | tcpstate[1] = "TCPS_CLOSE_WAIT"; 50 | tcpstate[2] = "TCPS_FIN_WAIT_1"; 51 | tcpstate[3] = "TCPS_CLOSING"; 52 | tcpstate[4] = "TCPS_LAST_ACK"; 53 | tcpstate[5] = "TCPS_FIN_WAIT_2"; 54 | tcpstate[6] = "TCPS_TIME_WAIT"; 55 | 56 | printf("%-20s %-17s %-16s %-16s %-6s\n", "TIME", "TCP_STATE", 57 | "SRC", "DST", "PORT"); 58 | } 59 | 60 | fbt::tcp_timer:entry { self->in_tcp_timer = 1; self->retrans = 0; } 61 | fbt::tcp_timer:return { self->in_tcp_timer = 0; self->retrans = 0; } 62 | 63 | mib:::tcpRetransSegs { self->retrans = 1; } 64 | 65 | fbt::tcp_send_data:entry 66 | /self->in_tcp_timer && self->retrans/ 67 | { 68 | this->iph = (ipha_t *)args[1]->b_rptr; 69 | this->state = tcpstate[args[0]->tcp_state] != NULL ? 70 | tcpstate[args[0]->tcp_state] : ""; 71 | printf("%-20Y %-17s %-16s %-16s %-6d\n", walltimestamp, this->state, 72 | inet_ntoa(&this->iph->ipha_src), inet_ntoa(&this->iph->ipha_dst), 73 | ntohs(args[0]->tcp_connp->u_port.connu_ports.connu_fport)); 74 | self->retrans = 0; 75 | } 76 | -------------------------------------------------------------------------------- /disk/scsilatencydist.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * scsilatencydist.d show SCSI I/O latency distribution. 4 | * 5 | * This is based on scsilatency.d from the DTrace book, chapter 4. 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: this fbt provider based script may only work on some OS versions. 32 | * 121: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | 37 | string scsi_cmd[uchar_t]; 38 | 39 | dtrace:::BEGIN 40 | { 41 | /* See /usr/include/sys/scsi/generic/commands.h for the full list. */ 42 | scsi_cmd[0x00] = "test_unit_ready"; 43 | scsi_cmd[0x08] = "read"; 44 | scsi_cmd[0x0a] = "write"; 45 | scsi_cmd[0x12] = "inquiry"; 46 | scsi_cmd[0x17] = "release"; 47 | scsi_cmd[0x1a] = "mode_sense"; 48 | scsi_cmd[0x1b] = "load/start/stop"; 49 | scsi_cmd[0x1c] = "get_diagnostic_results"; 50 | scsi_cmd[0x1d] = "send_diagnostic_command"; 51 | scsi_cmd[0x25] = "read_capacity"; 52 | scsi_cmd[0x28] = "read(10)"; 53 | scsi_cmd[0x2a] = "write(10)"; 54 | scsi_cmd[0x35] = "synchronize_cache"; 55 | scsi_cmd[0x4d] = "log_sense"; 56 | scsi_cmd[0x5e] = "persistent_reserve_in"; 57 | scsi_cmd[0xa0] = "report_luns"; 58 | 59 | printf("Tracing... Hit Ctrl-C to end.\n\n"); 60 | } 61 | 62 | fbt::scsi_transport:entry 63 | { 64 | start[arg0] = timestamp; 65 | } 66 | 67 | fbt::scsi_destroy_pkt:entry 68 | /start[arg0]/ 69 | { 70 | this->delta = timestamp - start[arg0]; 71 | this->code = *args[0]->pkt_cdbp; 72 | this->cmd = scsi_cmd[this->code] != NULL ? 73 | scsi_cmd[this->code] : lltostr(this->code); 74 | this->reason = args[0]->pkt_reason == 0 ? "Success" : 75 | strjoin("Fail:", lltostr(args[0]->pkt_reason)); 76 | 77 | @[this->cmd, this->reason, "time (ns)"] = quantize(this->delta); 78 | 79 | start[arg0] = 0; 80 | } 81 | 82 | dtrace:::END 83 | { 84 | printa(" %-25s %-26s %s%@d\n", @); 85 | } 86 | -------------------------------------------------------------------------------- /system/zonecpu.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zonecpu.d Lightweight CPU usage sample by-zone and by-app. 4 | * 5 | * USAGE: zonecpu.d [interval] 6 | * 7 | * For use when "prstat -Z" is too slow/heavyweight/laggy. 8 | * 9 | * SEE ALSO: zonetop.d 10 | * 11 | * CDDL HEADER START 12 | * 13 | * The contents of this file are subject to the terms of the 14 | * Common Development and Distribution License, Version 1.0 only 15 | * (the "License"). You may not use this file except in compliance 16 | * with the License. 17 | * 18 | * You can obtain a copy of the license at http://smartos.org/CDDL 19 | * 20 | * See the License for the specific language governing permissions 21 | * and limitations under the License. 22 | * 23 | * When distributing Covered Code, include this CDDL HEADER in each 24 | * file. 25 | * 26 | * If applicable, add the following below this CDDL HEADER, with the 27 | * fields enclosed by brackets "[]" replaced with your own identifying 28 | * information: Portions Copyright [yyyy] [name of copyright owner] 29 | * 30 | * CDDL HEADER END 31 | * 32 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 33 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 34 | */ 35 | 36 | #pragma D option quiet 37 | #pragma D option bufsize=32k 38 | #pragma D option aggsize=32k 39 | #pragma D option dynvarsize=32k 40 | #pragma D option defaultargs 41 | 42 | dtrace:::BEGIN 43 | { 44 | interval = $1 ? $1 : 1; 45 | printf("Sampling CPU users @97 Hertz, output each %d sec...\n", 46 | interval); 47 | secs = interval; 48 | } 49 | 50 | profile:::profile-97 51 | /arg0/ 52 | { 53 | @zone_sys[zonename] = count(); 54 | @app_sys[execname] = count(); 55 | @sys = count(); 56 | } 57 | 58 | profile:::profile-97 59 | /arg1/ 60 | { 61 | @zone_usr[zonename] = count(); 62 | @app_usr[execname] = count(); 63 | @usr = count(); 64 | } 65 | 66 | profile:::tick-1s 67 | { 68 | secs--; 69 | } 70 | 71 | profile:::tick-1s 72 | /secs == 0/ 73 | { 74 | normalize(@usr, interval); 75 | normalize(@sys, interval); 76 | normalize(@zone_usr, interval); 77 | normalize(@zone_sys, interval); 78 | normalize(@app_usr, interval); 79 | normalize(@app_sys, interval); 80 | printf("\n\n%Y (total usr, sys): ", walltimestamp); 81 | printa("%@8d %@8d\n", @usr, @sys); 82 | printf("\nZones @97 Hertz (usr, sys):\n"); 83 | printa(" %-35s %@8d %@8d\n", @zone_usr, @zone_sys); 84 | printf("\nProcesses @97 Hertz (usr, sys):\n"); 85 | printa(" %-35s %@8d %@8d\n", @app_usr, @app_sys); 86 | trunc(@usr); trunc(@sys); 87 | trunc(@zone_usr); trunc(@zone_sys); 88 | trunc(@app_usr); trunc(@app_sys); 89 | secs = interval; 90 | } 91 | 92 | dtrace:::END 93 | { 94 | trunc(@usr); trunc(@sys); 95 | trunc(@zone_usr); trunc(@zone_sys); 96 | trunc(@app_usr); trunc(@app_sys); 97 | } 98 | -------------------------------------------------------------------------------- /zfs/zfsslower.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * zfsslower.d show ZFS I/O taking longer than given ms. 4 | * 5 | * USAGE: zfsslower.d min_ms 6 | * eg, 7 | * zfsslower.d 100 # show I/O at least 100 ms 8 | * 9 | * This is from the DTrace book, chapter 5. It has been enhanced to include 10 | * zfs_readdir() as well, which is shown in the "D" (direction) field as "D". 11 | * 12 | * CDDL HEADER START 13 | * 14 | * The contents of this file are subject to the terms of the 15 | * Common Development and Distribution License, Version 1.0 only 16 | * (the "License"). You may not use this file except in compliance 17 | * with the License. 18 | * 19 | * You can obtain a copy of the license at http://smartos.org/CDDL 20 | * 21 | * See the License for the specific language governing permissions 22 | * and limitations under the License. 23 | * 24 | * When distributing Covered Code, include this CDDL HEADER in each 25 | * file. 26 | * 27 | * If applicable, add the following below this CDDL HEADER, with the 28 | * fields enclosed by brackets "[]" replaced with your own identifying 29 | * information: Portions Copyright [yyyy] [name of copyright owner] 30 | * 31 | * CDDL HEADER END 32 | * 33 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 34 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 35 | * 36 | * TESTED: this fbt provider based script may only work on some OS versions. 37 | * 121: ok 38 | */ 39 | 40 | #pragma D option quiet 41 | #pragma D option defaultargs 42 | #pragma D option switchrate=10hz 43 | 44 | dtrace:::BEGIN 45 | { 46 | printf("%-20s %-16s %1s %4s %6s %s\n", "TIME", "PROCESS", 47 | "D", "KB", "ms", "FILE"); 48 | min_ns = $1 * 1000000; 49 | } 50 | 51 | /* see uts/common/fs/zfs/zfs_vnops.c */ 52 | 53 | fbt::zfs_read:entry, fbt::zfs_write:entry 54 | { 55 | self->path = args[0]->v_path; 56 | self->kb = args[1]->uio_resid / 1024; 57 | self->start = timestamp; 58 | } 59 | 60 | fbt::zfs_readdir:entry 61 | { 62 | self->path = args[0]->v_path; 63 | self->kb = 0; 64 | self->start = timestamp; 65 | } 66 | 67 | fbt::zfs_read:return, fbt::zfs_write:return, fbt::zfs_readdir:return 68 | /self->start && (timestamp - self->start) >= min_ns/ 69 | { 70 | this->iotime = (timestamp - self->start) / 1000000; 71 | this->dir = probefunc == "zfs_read" ? "R" : 72 | probefunc == "zfs_write" ? "W" : "D"; 73 | printf("%-20Y %-16s %1s %4d %6d %s\n", walltimestamp, 74 | execname, this->dir, self->kb, this->iotime, 75 | self->path != NULL ? stringof(self->path) : ""); 76 | } 77 | 78 | fbt::zfs_read:return, fbt::zfs_write:return, fbt::zfs_readdir:return 79 | { 80 | self->path = 0; self->kb = 0; self->start = 0; 81 | } 82 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_fslatency_slowlog1.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_fslatency_slowlog1.d Print slow filesystem I/O events. 4 | * 5 | * USAGE: ./mysql_pid_fslatency_slowlog1.d mysqld_PID 6 | * 7 | * This traces mysqld filesystem I/O during queries, and prints output when 8 | * the total I/O time during a query was longer than the MIN_FS_LATENCY_MS 9 | * tunable. This requires tracing every query, whether it performs FS I/O 10 | * or not, which may add a noticable overhead. 11 | * 12 | * This is a monitoring tool (if Cloud Analytics is not available). 13 | * 14 | * CDDL HEADER START 15 | * 16 | * The contents of this file are subject to the terms of the 17 | * Common Development and Distribution License, Version 1.0 only 18 | * (the "License"). You may not use this file except in compliance 19 | * with the License. 20 | * 21 | * You can obtain a copy of the license at http://smartos.org/CDDL 22 | * 23 | * See the License for the specific language governing permissions 24 | * and limitations under the License. 25 | * 26 | * When distributing Covered Code, include this CDDL HEADER in each 27 | * file. 28 | * 29 | * If applicable, add the following below this CDDL HEADER, with the 30 | * fields enclosed by brackets "[]" replaced with your own identifying 31 | * information: Portions Copyright [yyyy] [name of copyright owner] 32 | * 33 | * CDDL HEADER END 34 | * 35 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 36 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 37 | * 38 | * TESTED: these pid-provider probes may only work on some mysqld versions. 39 | * 5.0.51a: ok 40 | */ 41 | 42 | #pragma D option quiet 43 | 44 | inline int MIN_FS_LATENCY_MS = 1000; 45 | 46 | dtrace:::BEGIN 47 | { 48 | min_ns = MIN_FS_LATENCY_MS * 1000000; 49 | } 50 | 51 | pid$1::*dispatch_command*:entry 52 | { 53 | self->in_query = 1; 54 | self->io_count = 0; 55 | self->total_ns = 0; 56 | } 57 | 58 | pid$1::os_file_read:entry, 59 | pid$1::os_file_write:entry, 60 | pid$1::my_read:entry, 61 | pid$1::my_write:entry 62 | /self->in_query/ 63 | { 64 | self->start = timestamp; 65 | } 66 | 67 | pid$1::os_file_read:return, 68 | pid$1::os_file_write:return, 69 | pid$1::my_read:return, 70 | pid$1::my_write:return 71 | /self->start/ 72 | { 73 | self->total_ns += timestamp - self->start; 74 | self->io_count++; 75 | self->start = 0; 76 | } 77 | 78 | pid$1::*dispatch_command*:return 79 | /self->in_query && (self->total_ns > min_ns)/ 80 | { 81 | printf("%Y filesystem total I/O during query > %d ms: %d ms, %d I/O\n", 82 | walltimestamp, MIN_FS_LATENCY_MS, self->total_ns / 1000000, 83 | self->io_count); 84 | } 85 | 86 | pid$1::*dispatch_command*:return 87 | /self->in_query/ 88 | { 89 | self->in_query = 0; 90 | self->io_count = 0; 91 | self->total_ns = 0; 92 | } 93 | -------------------------------------------------------------------------------- /net/tcpretransport.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * tcpretransport.d Trace TCP rexmits to a specified port. 4 | * 5 | * USAGE: ./tcpretransport.d [port] 6 | * 7 | * Uses port 3306 (mysqld) by default. 8 | * 9 | * CDDL HEADER START 10 | * 11 | * The contents of this file are subject to the terms of the 12 | * Common Development and Distribution License, Version 1.0 only 13 | * (the "License"). You may not use this file except in compliance 14 | * with the License. 15 | * 16 | * You can obtain a copy of the license at http://smartos.org/CDDL 17 | * 18 | * See the License for the specific language governing permissions 19 | * and limitations under the License. 20 | * 21 | * When distributing Covered Code, include this CDDL HEADER in each 22 | * file. 23 | * 24 | * If applicable, add the following below this CDDL HEADER, with the 25 | * fields enclosed by brackets "[]" replaced with your own identifying 26 | * information: Portions Copyright [yyyy] [name of copyright owner] 27 | * 28 | * CDDL HEADER END 29 | * 30 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 31 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 32 | * 33 | * TESTED: this fbt provider based script may only work on some OS versions. 34 | * 121: ok 35 | */ 36 | 37 | #pragma D option quiet 38 | #pragma D option defaultargs 39 | #pragma D option switchrate=10hz 40 | 41 | dtrace:::BEGIN 42 | { 43 | /* from /usr/include/inet/tcp.h */ 44 | tcpstate[-6] = "TCPS_CLOSED"; 45 | tcpstate[-5] = "TCPS_IDLE"; 46 | tcpstate[-4] = "TCPS_BOUND"; 47 | tcpstate[-3] = "TCPS_LISTEN"; 48 | tcpstate[-2] = "TCPS_SYN_SENT"; 49 | tcpstate[-1] = "TCPS_SYN_RCVD"; 50 | tcpstate[0] = "TCPS_ESTABLISHED"; 51 | tcpstate[1] = "TCPS_CLOSE_WAIT"; 52 | tcpstate[2] = "TCPS_FIN_WAIT_1"; 53 | tcpstate[3] = "TCPS_CLOSING"; 54 | tcpstate[4] = "TCPS_LAST_ACK"; 55 | tcpstate[5] = "TCPS_FIN_WAIT_2"; 56 | tcpstate[6] = "TCPS_TIME_WAIT"; 57 | 58 | port = $1 ? $1 : 3306; 59 | printf("Tracing TCP retransmits to remote port: %d\n\n", port); 60 | 61 | printf("%-20s %-17s %-15s %-15s %-5s\n", "TIME", "TCP_STATE", 62 | "SRC", "DST", "LPORT"); 63 | } 64 | 65 | fbt::tcp_timer:entry { self->in_tcp_timer = 1; self->retrans = 0; } 66 | fbt::tcp_timer:return { self->in_tcp_timer = 0; self->retrans = 0; } 67 | 68 | mib:::tcpRetransSegs { self->retrans = 1; } 69 | 70 | fbt::tcp_send_data:entry 71 | /self->in_tcp_timer && self->retrans && 72 | (this->port = ntohs(args[0]->tcp_connp->u_port.tcpu_ports.tcpu_fport)) && 73 | this->port == port/ 74 | { 75 | this->iph = (ipha_t *)args[2]->b_rptr; 76 | this->state = tcpstate[args[0]->tcp_state] != NULL ? 77 | tcpstate[args[0]->tcp_state] : ""; 78 | printf("%-20Y %-17s %-15s %-15s %-5d\n", walltimestamp, this->state, 79 | inet_ntoa(&this->iph->ipha_src), inet_ntoa(&this->iph->ipha_dst), 80 | ntohs(args[0]->tcp_connp->u_port.tcpu_ports.tcpu_lport)); 81 | self->retrans = 0; 82 | } 83 | -------------------------------------------------------------------------------- /mysql/innodb_pid_ioslow.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * innodb_pid_ioslow.d Trace slow innodb storage I/O. 4 | * 5 | * USAGE: ./innodb_pid_ioslow.d -p mysqld_PID [interval] 6 | * 7 | * This traces innodb at the OS interface: os_file_read() and os_file_write(). 8 | * This includes back-end query I/O, but not other types including log I/O. 9 | * 10 | * This may be easier (albiet more inclusive) to measure at the VFS/ZFS 11 | * interface. That would require the fbt provider, which isn't available 12 | * in zones. 13 | * 14 | * CDDL HEADER START 15 | * 16 | * The contents of this file are subject to the terms of the 17 | * Common Development and Distribution License, Version 1.0 only 18 | * (the "License"). You may not use this file except in compliance 19 | * with the License. 20 | * 21 | * You can obtain a copy of the license at http://smartos.org/CDDL 22 | * 23 | * See the License for the specific language governing permissions 24 | * and limitations under the License. 25 | * 26 | * When distributing Covered Code, include this CDDL HEADER in each 27 | * file. 28 | * 29 | * If applicable, add the following below this CDDL HEADER, with the 30 | * fields enclosed by brackets "[]" replaced with your own identifying 31 | * information: Portions Copyright [yyyy] [name of copyright owner] 32 | * 33 | * CDDL HEADER END 34 | * 35 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 36 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 37 | * 38 | * TESTED: these pid-provider probes may only work on some mysqld versions. 39 | * 5.0.51a: ok 40 | * 41 | * SEE ALSO: innodb_pid_latency.d 42 | */ 43 | 44 | #pragma D option quiet 45 | #pragma D option defaultargs 46 | #pragma D option bufsize=128k 47 | 48 | dtrace:::BEGIN 49 | /$1 == 0/ 50 | { 51 | printf("USAGE: %s -p PID min_ms\n\n", $$0); 52 | printf("\teg: %s -p 12345 100\n", $$0); 53 | exit(1); 54 | } 55 | 56 | dtrace:::BEGIN 57 | { 58 | min_ns = $1 * 1000000; 59 | printf("Tracing... Min query time: %d ms. ", $1); 60 | printf("TIME & CPU are in ms.\n\n"); 61 | printf(" %-4s %-4s %-7s %s\n", "TIME", "CPU", "SIZE(b)", "PATH"); 62 | } 63 | 64 | pid$target::*os_file_read*:entry, 65 | pid$target::*os_file_write*:entry 66 | { 67 | self->start = timestamp; 68 | self->vstart = vtimestamp; 69 | } 70 | 71 | syscall::*read*:entry,syscall::*write*:entry 72 | /self->start/ 73 | { 74 | /* easier to fetch them now than from the C++ args */ 75 | self->fd = arg0 + 1; 76 | self->bytes = arg2; 77 | } 78 | 79 | pid$target::*os_file_read*:return { this->dir = "R"; } 80 | pid$target::*os_file_write*:return { this->dir = "W"; } 81 | 82 | pid$target::*os_file_read*:return, 83 | pid$target::*os_file_write*:return 84 | /self->start && (timestamp - self->start) > min_ns/ 85 | { 86 | this->time = (timestamp - self->start) / 1000000; 87 | this->vtime = (vtimestamp - self->vstart) / 1000000; 88 | printf(" %-4d %-4d %-7d %s\n", this->time, this->vtime, 89 | self->bytes, self->fd ? fds[self->fd - 1].fi_pathname : ""); 90 | } 91 | 92 | pid$target::*os_file_read*:return, 93 | pid$target::*os_file_write*:return 94 | /self->start/ 95 | { 96 | self->start = 0; 97 | self->vstart = 0; 98 | self->fd = 0; 99 | self->bytes = 0; 100 | } 101 | -------------------------------------------------------------------------------- /mysql/mysqld_pid_rowerrors.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * mysqld_pid_rowerrors.d Print row_mysql_handle_errors() latency dist. 4 | * 5 | * USAGE: ./mysqld_pid_rowerrors.d -p mysqld_PID 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | * 31 | * TESTED: these pid-provider probes may only work on some mysqld versions. 32 | * 5.0.51a: ok 33 | */ 34 | 35 | #pragma D option quiet 36 | 37 | dtrace:::BEGIN 38 | { 39 | /* from innobase/include/db0err.h: */ 40 | dberr2str[10] = "DB_SUCCESS"; 41 | dberr2str[11] = "DB_ERROR"; 42 | dberr2str[12] = "DB_OUT_OF_MEMORY"; 43 | dberr2str[13] = "DB_OUT_OF_FILE_SPACE"; 44 | dberr2str[14] = "DB_LOCK_WAIT"; 45 | dberr2str[15] = "DB_DEADLOCK"; 46 | dberr2str[16] = "DB_ROLLBACK"; 47 | dberr2str[17] = "DB_DUPLICATE_KEY"; 48 | dberr2str[18] = "DB_QUE_THR_SUSPENDED"; 49 | dberr2str[19] = "DB_MISSING_HISTORY"; 50 | dberr2str[30] = "DB_CLUSTER_NOT_FOUND"; 51 | dberr2str[31] = "DB_TABLE_NOT_FOUND"; 52 | dberr2str[32] = "DB_MUST_GET_MORE_FILE_SPACE"; 53 | dberr2str[33] = "DB_TABLE_IS_BEING_USED"; 54 | dberr2str[34] = "DB_TOO_BIG_RECORD"; 55 | dberr2str[35] = "DB_LOCK_WAIT_TIMEOUT"; 56 | dberr2str[36] = "DB_NO_REFERENCED_ROW"; 57 | dberr2str[37] = "DB_ROW_IS_REFERENCED"; 58 | dberr2str[38] = "DB_CANNOT_ADD_CONSTRAINT"; 59 | dberr2str[39] = "DB_CORRUPTION"; 60 | dberr2str[40] = "DB_COL_APPEARS_TWICE_IN_INDEX"; 61 | dberr2str[41] = "DB_CANNOT_DROP_CONSTRAINT"; 62 | dberr2str[42] = "DB_NO_SAVEPOINT"; 63 | dberr2str[43] = "DB_TABLESPACE_ALREADY_EXISTS"; 64 | dberr2str[44] = "DB_TABLESPACE_DELETED"; 65 | dberr2str[45] = "DB_LOCK_TABLE_FULL"; 66 | dberr2str[1000] = "DB_FAIL"; 67 | dberr2str[1001] = "DB_OVERFLOW"; 68 | dberr2str[1002] = "DB_UNDERFLOW"; 69 | dberr2str[1003] = "DB_STRONG_FAIL"; 70 | dberr2str[1500] = "DB_RECORD_NOT_FOUND"; 71 | dberr2str[1501] = "DB_END_OF_INDEX"; 72 | dberr2str[0] = ""; 73 | 74 | printf("Tracing MySQL PID %d... Hit Ctrl-C to end.\n", $target); 75 | } 76 | 77 | pid$target::*dispatch_command*:entry 78 | { 79 | @queries = count(); 80 | } 81 | 82 | pid$target::row_mysql_handle_errors:entry 83 | { 84 | self->err = *(int *)copyin(arg0, 4); 85 | self->start = timestamp; 86 | } 87 | 88 | pid$target::row_mysql_handle_errors:return 89 | /self->start/ 90 | { 91 | @dist[dberr2str[self->err]] = quantize(timestamp - self->start); 92 | @num = count(); 93 | self->start = 0; 94 | } 95 | 96 | dtrace:::END 97 | { 98 | printa("MySQL filesort: %@d, from queries: %@d; latency dist (ns):\n", 99 | @num, @queries); 100 | printa(@dist); 101 | } 102 | -------------------------------------------------------------------------------- /net/dnsconnect.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | /* 3 | * dnsconnect.d - snoop DNS connect details system wide. 4 | * 5 | * This is based on soconnect.d from Chapter 6 of the DTrace book. 6 | * 7 | * CDDL HEADER START 8 | * 9 | * The contents of this file are subject to the terms of the 10 | * Common Development and Distribution License, Version 1.0 only 11 | * (the "License"). You may not use this file except in compliance 12 | * with the License. 13 | * 14 | * You can obtain a copy of the license at http://smartos.org/CDDL 15 | * 16 | * See the License for the specific language governing permissions 17 | * and limitations under the License. 18 | * 19 | * When distributing Covered Code, include this CDDL HEADER in each 20 | * file. 21 | * 22 | * If applicable, add the following below this CDDL HEADER, with the 23 | * fields enclosed by brackets "[]" replaced with your own identifying 24 | * information: Portions Copyright [yyyy] [name of copyright owner] 25 | * 26 | * CDDL HEADER END 27 | * 28 | * Copyright (c) 2012 Joyent Inc., All rights reserved. 29 | * Copyright (c) 2012 Brendan Gregg, All rights reserved. 30 | */ 31 | 32 | #pragma D option quiet 33 | #pragma D option switchrate=10hz 34 | 35 | /* If AF_INET and AF_INET6 are "Unknown" to DTrace, replace with numbers: */ 36 | inline int af_inet = AF_INET; 37 | inline int af_inet6 = AF_INET6; 38 | 39 | dtrace:::BEGIN 40 | { 41 | /* Add translations as desired from /usr/include/sys/errno.h */ 42 | err[0] = "Success"; 43 | err[EINTR] = "Interrupted syscall"; 44 | err[EIO] = "I/O error"; 45 | err[EACCES] = "Permission denied"; 46 | err[ENETDOWN] = "Network is down"; 47 | err[ENETUNREACH] = "Network unreachable"; 48 | err[ECONNRESET] = "Connection reset"; 49 | err[ECONNREFUSED] = "Connection refused"; 50 | err[ETIMEDOUT] = "Timed out"; 51 | err[EHOSTDOWN] = "Host down"; 52 | err[EHOSTUNREACH] = "No route to host"; 53 | err[EINPROGRESS] = "In progress"; 54 | 55 | printf("%-6s %-12s %-16s %-3s %-16s %-5s %8s %s\n", "PID", "ZONE", 56 | "PROCESS", "FAM", "ADDRESS", "PORT", "LAT(us)", "RESULT"); 57 | } 58 | 59 | syscall::connect*:entry 60 | { 61 | /* assume this is sockaddr_in until we can examine family */ 62 | this->s = (struct sockaddr_in *)copyin(arg1, sizeof (struct sockaddr)); 63 | this->f = this->s->sin_family; 64 | } 65 | 66 | syscall::connect*:entry 67 | /this->f == af_inet/ 68 | { 69 | self->family = this->f; 70 | self->port = ntohs(this->s->sin_port); 71 | self->address = inet_ntop(self->family, (void *)&this->s->sin_addr); 72 | self->start = timestamp; 73 | } 74 | 75 | syscall::connect*:entry 76 | /this->f == af_inet6/ 77 | { 78 | /* refetch for sockaddr_in6 */ 79 | this->s6 = (struct sockaddr_in6 *)copyin(arg1, 80 | sizeof (struct sockaddr_in6)); 81 | self->family = this->f; 82 | self->port = ntohs(this->s6->sin6_port); 83 | self->address = inet_ntoa6((in6_addr_t *)&this->s6->sin6_addr); 84 | self->start = timestamp; 85 | } 86 | 87 | syscall::connect*:return 88 | /self->start && self->port == 53/ 89 | { 90 | this->delta = (timestamp - self->start) / 1000; 91 | this->errstr = err[errno] != NULL ? err[errno] : lltostr(errno); 92 | printf("%-6d %-12s %-16s %-3d %-16s %-5d %8d %s\n", pid, zonename, execname, 93 | self->family, self->address, self->port, this->delta, this->errstr); 94 | } 95 | 96 | syscall::connect*:return 97 | /self->start/ 98 | { 99 | self->family = 0; 100 | self->address = 0; 101 | self->port = 0; 102 | self->start = 0; 103 | } 104 | -------------------------------------------------------------------------------- /go/go_funccounts.txt: -------------------------------------------------------------------------------- 1 | # ./go_funccounts.d -p 40148 2 | Tracing PID 40148; Ctrl-C to stop. 3 | ^C 4 | 5 | main.processreq 215 6 | retake 236 7 | runtime.atomicload64 236 8 | runtime.nanotime 236 9 | runtime.nanotime1 236 10 | runtime.usleep 236 11 | runtime.sysvicall6 472 12 | assertE2Tret 10741 13 | copyout 10741 14 | fmt.(*fmt).clearflags 10741 15 | fmt.(*fmt).init 10741 16 | fmt.(*pp).doPrintf 10741 17 | gosave 10741 18 | lockOSThread 10741 19 | os.(*File).Write 10741 20 | os.(*File).write 10741 21 | runtime.assertE2T 10741 22 | runtime.atomicstore 10741 23 | runtime.cgocall 10741 24 | runtime.entersyscall 10741 25 | runtime.getcallerpc 10741 26 | runtime.getcallersp 10741 27 | runtime.lockOSThread 10741 28 | runtime.memcopy64 10741 29 | save 10741 30 | syscall.Syscall 10741 31 | syscall.Write 10741 32 | syscall.write 10741 33 | endcgo 10742 34 | exitsyscallfast 10742 35 | fmt.(*cache).get 10742 36 | fmt.(*cache).put 10742 37 | fmt.(*pp).free 10742 38 | fmt.Fprintf 10742 39 | fmt.Printf 10742 40 | fmt.newPrinter 10742 41 | os.epipecheck 10742 42 | runtime.cas 10742 43 | runtime.exitsyscall 10742 44 | runtime.unlockOSThread 10742 45 | sync/atomic.StoreInt32 10742 46 | sync/atomic.StoreUint32 10742 47 | unlockOSThread 10742 48 | runtime.atomicload 10977 49 | runtime.asmcgocall 11213 50 | runtime.asmsysvicall6 11213 51 | sync/atomic.AddInt32 21483 52 | sync/atomic.AddUint32 21483 53 | sync.(*Mutex).Lock 21484 54 | sync.(*Mutex).Unlock 21484 55 | sync/atomic.CompareAndSwapInt32 21484 56 | sync/atomic.CompareAndSwapUint32 21484 57 | -------------------------------------------------------------------------------- /go/go_mainlatency.txt: -------------------------------------------------------------------------------- 1 | # ./go_mainlatency.d -p 40148 1 2 | Tracing PID 40148; output every 1 secs. 3 | 2013 Nov 14 23:03:53: 4 | 5 | main.processreq ns 6 | value ------------- Distribution ------------- count 7 | 32768 | 0 8 | 65536 |@ 105 9 | 131072 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6070 10 | 262144 |@ 107 11 | 524288 | 2 12 | 1048576 | 0 13 | 2097152 | 0 14 | 4194304 | 1 15 | 8388608 | 0 16 | 17 | 2013 Nov 14 23:03:54: 18 | 19 | main.processreq ns 20 | value ------------- Distribution ------------- count 21 | 65536 | 0 22 | 131072 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6115 23 | 262144 | 35 24 | 524288 | 4 25 | 1048576 | 0 26 | 27 | 2013 Nov 14 23:03:55: 28 | 29 | main.processreq ns 30 | value ------------- Distribution ------------- count 31 | 65536 | 0 32 | 131072 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 5335 33 | 262144 |@ 130 34 | 524288 | 13 35 | 1048576 | 4 36 | 2097152 | 4 37 | 4194304 | 1 38 | 8388608 | 0 39 | 40 | 2013 Nov 14 23:03:56: 41 | 42 | main.processreq ns 43 | value ------------- Distribution ------------- count 44 | 65536 | 0 45 | 131072 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6854 46 | 262144 | 13 47 | 524288 | 0 48 | 49 | 2013 Nov 14 23:03:57: 50 | 51 | main.processreq ns 52 | value ------------- Distribution ------------- count 53 | 65536 | 0 54 | 131072 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6573 55 | 262144 | 48 56 | 524288 | 0 57 | 58 | 2013 Nov 14 23:03:58: 59 | 60 | main.processreq ns 61 | value ------------- Distribution ------------- count 62 | 65536 | 0 63 | 131072 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 6313 64 | 262144 | 33 65 | 524288 | 1 66 | 1048576 | 2 67 | 2097152 | 1 68 | 4194304 | 0 69 | 70 | [...] 71 | -------------------------------------------------------------------------------- /kvm/kvmexitstat.d: -------------------------------------------------------------------------------- 1 | #!/usr/sbin/dtrace -s 2 | 3 | /* 4 | * This D file provides translation from all of the reasons we return from the 5 | * VMRUN/VMRESUME instruction. This is meant to be similar to 6 | * /usr/lib/dtrace/errno.d 7 | */ 8 | 9 | #pragma D option quiet 10 | 11 | inline int EXIT_REASON_EXCEPTION_NMI = 0; 12 | inline int EXIT_REASON_EXTERNAL_INTERRUPT = 1; 13 | inline int EXIT_REASON_TRIPLE_FAULT = 2; 14 | 15 | inline int EXIT_REASON_PENDING_INTERRUPT = 7; 16 | inline int EXIT_REASON_NMI_WINDOW = 8; 17 | inline int EXIT_REASON_TASK_SWITCH = 9; 18 | inline int EXIT_REASON_CPUID = 10; 19 | inline int EXIT_REASON_HLT = 12; 20 | inline int EXIT_REASON_INVLPG = 14; 21 | inline int EXIT_REASON_RDPMC = 15; 22 | inline int EXIT_REASON_RDTSC = 16; 23 | inline int EXIT_REASON_VMCALL = 18; 24 | inline int EXIT_REASON_VMCLEAR = 19; 25 | inline int EXIT_REASON_VMLAUNCH = 20; 26 | inline int EXIT_REASON_VMPTRLD = 21; 27 | inline int EXIT_REASON_VMPTRST = 22; 28 | inline int EXIT_REASON_VMREAD = 23; 29 | inline int EXIT_REASON_VMRESUME = 24; 30 | inline int EXIT_REASON_VMWRITE = 25; 31 | inline int EXIT_REASON_VMOFF = 26; 32 | inline int EXIT_REASON_VMON = 27; 33 | inline int EXIT_REASON_CR_ACCESS = 28; 34 | inline int EXIT_REASON_DR_ACCESS = 29; 35 | inline int EXIT_REASON_IO_INSTRUCTION = 30; 36 | inline int EXIT_REASON_MSR_READ = 31; 37 | inline int EXIT_REASON_MSR_WRITE = 32; 38 | inline int EXIT_REASON_MWAIT_INSTRUCTION = 36; 39 | inline int EXIT_REASON_MONITOR_INSTRUCTION = 39; 40 | inline int EXIT_REASON_PAUSE_INSTRUCTION = 40; 41 | inline int EXIT_REASON_MCE_DURING_VMENTRY = 41; 42 | inline int EXIT_REASON_TPR_BELOW_THRESHOLD = 43; 43 | inline int EXIT_REASON_APIC_ACCESS = 44; 44 | inline int EXIT_REASON_EPT_VIOLATION = 48; 45 | inline int EXIT_REASON_EPT_MISCONFIG = 49; 46 | inline int EXIT_REASON_WBINVD = 54; 47 | 48 | 49 | inline string strexitno[int32_t r] = 50 | r == EXIT_REASON_EXCEPTION_NMI ? "EXIT_REASON_EXCEPTION_NMI" : 51 | r == EXIT_REASON_EXTERNAL_INTERRUPT ? "EXIT_REASON_EXTERNAL_INTERRUPT" : 52 | r == EXIT_REASON_TRIPLE_FAULT ? "EXIT_REASON_TRIPLE_FAULT" : 53 | r == EXIT_REASON_PENDING_INTERRUPT ? "EXIT_REASON_PENDING_INTERRUPT" : 54 | r == EXIT_REASON_NMI_WINDOW ? "EXIT_REASON_NMI_WINDOW" : 55 | r == EXIT_REASON_TASK_SWITCH ? "EXIT_REASON_TASK_SWITCH" : 56 | r == EXIT_REASON_CPUID ? "EXIT_REASON_CPUID" : 57 | r == EXIT_REASON_HLT ? "EXIT_REASON_HLT" : 58 | r == EXIT_REASON_INVLPG ? "EXIT_REASON_INVLPG" : 59 | r == EXIT_REASON_RDPMC ? "EXIT_REASON_RDPMC" : 60 | r == EXIT_REASON_RDTSC ? "EXIT_REASON_RDTSC" : 61 | r == EXIT_REASON_VMCALL ? "EXIT_REASON_VMCALL" : 62 | r == EXIT_REASON_VMCLEAR ? "EXIT_REASON_VMCLEAR" : 63 | r == EXIT_REASON_VMLAUNCH ? "EXIT_REASON_VMLAUNCH" : 64 | r == EXIT_REASON_VMPTRLD ? "EXIT_REASON_VMPTRLD" : 65 | r == EXIT_REASON_VMPTRST ? "EXIT_REASON_VMPTRST" : 66 | r == EXIT_REASON_VMREAD ? "EXIT_REASON_VMREAD" : 67 | r == EXIT_REASON_VMRESUME ? "EXIT_REASON_VMRESUME" : 68 | r == EXIT_REASON_VMWRITE ? "EXIT_REASON_VMWRITE" : 69 | r == EXIT_REASON_VMOFF ? "EXIT_REASON_VMOFF" : 70 | r == EXIT_REASON_VMON ? "EXIT_REASON_VMON" : 71 | r == EXIT_REASON_CR_ACCESS ? "EXIT_REASON_CR_ACCESS" : 72 | r == EXIT_REASON_DR_ACCESS ? "EXIT_REASON_DR_ACCESS" : 73 | r == EXIT_REASON_IO_INSTRUCTION ? "EXIT_REASON_IO_INSTRUCTION" : 74 | r == EXIT_REASON_MSR_READ ? "EXIT_REASON_MSR_READ" : 75 | r == EXIT_REASON_MSR_WRITE ? "EXIT_REASON_MSR_WRITE" : 76 | r == EXIT_REASON_MWAIT_INSTRUCTION ? "EXIT_REASON_MWAIT_INSTRUCTION" : 77 | r == EXIT_REASON_MONITOR_INSTRUCTION ? "EXIT_REASON_MONITOR_INSTRUCTION" : 78 | r == EXIT_REASON_PAUSE_INSTRUCTION ? "EXIT_REASON_PAUSE_INSTRUCTION" : 79 | r == EXIT_REASON_MCE_DURING_VMENTRY ? "EXIT_REASON_MCE_DURING_VMENTRY" : 80 | r == EXIT_REASON_TPR_BELOW_THRESHOLD ? "EXIT_REASON_TPR_BELOW_THRESHOLD" : 81 | r == EXIT_REASON_APIC_ACCESS ? "EXIT_REASON_APIC_ACCESS" : 82 | r == EXIT_REASON_EPT_VIOLATION ? "EXIT_REASON_EPT_VIOLATION" : 83 | r == EXIT_REASON_EPT_MISCONFIG ? "EXIT_REASON_EPT_MISCONFIG" : 84 | r == EXIT_REASON_WBINVD ? "EXIT_REASON_WBINVD" : 85 | ""; 86 | 87 | kvm-vexit 88 | { 89 | @[strexitno[arg1]] = count(); 90 | } 91 | 92 | tick-1sec 93 | { 94 | printf("%-60s %s\n", "REASON", "COUNT"); 95 | printa("%-60s %@d\n", @); 96 | printf("\n"); 97 | clear(@); 98 | } 99 | --------------------------------------------------------------------------------