[
  {
    "path": "Chap1/chpt1_exec.d",
    "content": "dtrace -n 'proc:::exec-success { trace(curpsinfo->pr_psargs); }'\n"
  },
  {
    "path": "Chap1/read-syscall.d",
    "content": "dtrace -n 'syscall::read:entry /execname != \"dtrace\"/ { @reads[execname, fds[arg0].fi_pathname] = count(); }'\n"
  },
  {
    "path": "Chap10/cpudispqlen.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cpudispqlen.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Sampling at 1001 Hertz... Hit Ctrl-C to end.\\n\");\n}\n\nprofile:::profile-1001hz\n{\n\t@[\"Per-CPU disp queue length:\"] =\n\t    lquantize(curthread->t_cpu->cpu_disp->disp_nrunnable, 0, 64, 1);\n}\n"
  },
  {
    "path": "Chap10/libmysql_snoop.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * libmysql_snoop.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-8s %6s %3s %s\\n\", \"TIME(ms)\", \"Q(ms)\", \"RET\", \"QUERY\");\n\ttimezero = timestamp;\n}\n\npid$target::mysql_query:entry,\npid$target::mysql_real_query:entry\n{\n\tself->query = copyinstr(arg1);\n\tself->start = timestamp;\n}\n\npid$target::mysql_query:return,\npid$target::mysql_real_query:return\n/self->start/\n{\n\tthis->time = (timestamp - self->start) / 1000000;\n\tthis->now = (timestamp - timezero) / 1000000;\n\tprintf(\"%-8d %6d %3d %s\\n\", this->now, this->time, arg1, self->query);\n\tself->start = 0; self->query = 0;\n}\n"
  },
  {
    "path": "Chap10/mysqld_pid_qtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * mysqld_pid_qtime.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\npid$target::*dispatch_command*:entry\n{\n\tself->query = copyinstr(arg2);\n\tself->start = timestamp;\n}\n\npid$target::*dispatch_command*:return\n/self->start/\n{\n\t@time[self->query] = quantize(timestamp - self->start);\n\tself->query = 0; self->start = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"MySQL query execution latency (ns):\\n\");\n\tprinta(@time);\n}\n"
  },
  {
    "path": "Chap10/mysqld_qchit.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * mysqld_qchit.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n\thits = 0; misses = 0;\n}\n\nmysql*:::query-cache-hit,\nmysql*:::query-cache-miss\n{\n\tthis->query = copyinstr(arg0);\n}\n\nmysql*:::query-cache-hit,\nmysql*:::query-cache-miss\n/strlen(this->query) > 60/\n{\n\tthis->query[57] = '.';\n\tthis->query[58] = '.';\n\tthis->query[59] = '.';\n\tthis->query[60] = 0;\n}\n\nmysql*:::query-cache-hit\n{\n\t@cache[this->query, \"hit\"] = count();\n\thits++;\n}\n\nmysql*:::query-cache-miss\n{\n\t@cache[this->query, \"miss\"] = count();\n\tmisses++;\n}\n\ndtrace:::END\n{\n\tprintf(\"   %-60s %6s %6s\\n\", \"QUERY\", \"RESULT\", \"COUNT\");\n\tprinta(\"   %-60s %6s %@6d\\n\", @cache);\n\ttotal = hits + misses;\n\tprintf(\"\\nHits     : %d\\n\", hits);\n\tprintf(\"Misses   : %d\\n\", misses);\n\tprintf(\"Hit Rate : %d%%\\n\", total ? (hits * 100) / total : 0);\n}\n"
  },
  {
    "path": "Chap10/mysqld_qslower.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * mysqld_qslower.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%5s %5s %5s %5s %s\\n\", \"QRYms\", \"EXCms\", \"CPUms\",\n\t    \"CACHE\", \"QUERY\");\n\tmin_ns = $1 * 1000000;\n}\n\nmysql*:::query-start\n{\n\tself->query = copyinstr(arg0);\n\tself->start = timestamp;\n\tself->vstart = vtimestamp;\n}\n\nmysql*:::query-cache-hit,\nmysql*:::query-cache-miss\n{\n\tself->cache = probename == \"query-cache-hit\" ? \"hit\" : \"miss\";\n}\n\nmysql*:::query-exec-start\n{\n\tself->estart = timestamp;\n}\n\nmysql*:::query-exec-done\n/self->estart/\n{\n\tself->exec = timestamp - self->estart;\n\tself->estart = 0;\n}\n\nmysql*:::query-done\n/self->start && (timestamp - self->start) >= min_ns/\n{\n\tthis->time = (timestamp - self->start) / 1000000;\n\tthis->vtime = (vtimestamp - self->vstart) / 1000000;\n\tthis->etime = self->exec / 1000000;\n\tprintf(\"%5d %5d %5d %5s %s\\n\", this->time, this->etime, this->vtime,\n\t    self->cache, self->query);\n}\n\nmysql*:::query-done\n{\n\tself->start = 0; self->vstart = 0; self->exec = 0;\n\tself->cache = 0; self->query = 0;\n}\n"
  },
  {
    "path": "Chap10/mysqld_qsnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * mysqld_qsnoop.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-8s %-16s %-18s %5s %3s %s\\n\", \"TIME(ms)\", \"DATABASE\",\n\t    \"USER@HOST\", \"ms\", \"RET\", \"QUERY\");\n\ttimezero = timestamp;\n}\n\nmysql*:::query-start\n{\n\tself->query = copyinstr(arg0);\n\tself->db = copyinstr(arg2);\n\tself->who = strjoin(copyinstr(arg3), strjoin(\"@\", copyinstr(arg4)));\n\tself->start = timestamp;\n}\n\nmysql*:::query-done\n/self->start/\n{\n\tthis->now = (timestamp - timezero) / 1000000;\n\tthis->time = (timestamp - self->start) / 1000000;\n\tprintf(\"%-8d %-16.16s %-18.18s %5d %3d %s\\n\", this->now, self->db,\n\t    self->who, this->time, (int)arg0, self->query);\n\tself->start = 0; self->query = 0; self->db = 0; self->who = 0;\n}\n"
  },
  {
    "path": "Chap10/pg_pid_qtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * pg_pid_qtime.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\npid$target::exec_simple_query:entry\n{\n\tself->query = copyinstr(arg0);\n\tself->start = timestamp;\n}\n\npid$target::exec_simple_query:return\n/self->start/\n{\n\t@time[self->query] = quantize(timestamp - self->start);\n\tself->start = 0; self->query = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"PostgreSQL simple query execution latency (ns):\\n\");\n\tprinta(@time);\n}\n"
  },
  {
    "path": "Chap10/pg_qslower.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * pg_qslower.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-8s %5s %5s %5s %s\\n\", \"TIMEms\", \"QRYms\", \"EXCms\", \"CPUms\",\n\t    \"QUERY\");\n\tmin_ns = $1 * 1000000;\n\ttimezero = timestamp;\n}\n\npostgresql*:::query-start\n{\n\tself->start = timestamp;\n\tself->vstart = vtimestamp;\n}\n\npostgresql*:::query-execute-start\n{\n\tself->estart = timestamp;\n}\n\npostgresql*:::query-execute-done\n/self->estart/\n{\n\tself->exec = timestamp - self->estart;\n\tself->estart = 0;\n}\n\npostgresql*:::query-done\n/self->start && (timestamp - self->start) >= min_ns/\n{\n\tthis->now = (timestamp - timezero) / 1000000;\n\tthis->time = (timestamp - self->start) / 1000000;\n\tthis->vtime = (vtimestamp - self->vstart) / 1000000;\n\tthis->etime = self->exec / 1000000;\n\tprintf(\"%-8d %5d %5d %5d %s\\n\", this->now, this->time, this->etime,\n\t    this->vtime, copyinstr(arg0));\n}\n\npostgresql*:::query-done\n{\n\tself->start = 0; self->vstart = 0; self->exec = 0;\n}\n"
  },
  {
    "path": "Chap10/qtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * qtime.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nsched:::enqueue\n{\n\ta[args[0]->pr_lwpid, args[1]->pr_pid, args[2]->cpu_id] =\n\t    timestamp;\n}\n\nsched:::dequeue\n/a[args[0]->pr_lwpid, args[1]->pr_pid, args[2]->cpu_id]/\n{\n\t@[args[2]->cpu_id] = quantize(timestamp -\n\t    a[args[0]->pr_lwpid, args[1]->pr_pid, args[2]->cpu_id]);\n\ta[args[0]->pr_lwpid, args[1]->pr_pid, args[2]->cpu_id] = 0;\n}\n"
  },
  {
    "path": "Chap10/ssdlatency.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ssdlatency.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nfbt:ssd:ssdstrategy:entry\n{\n\tstart[arg0] = timestamp;\n}\n\nfbt:ssd:ssd_buf_iodone:entry\n/start[arg2]/\n{\n\t@time[\"ssd I/O latency (ns)\"] = quantize(timestamp - start[arg2]);\n\tstart[arg2] = 0;\n}\n"
  },
  {
    "path": "Chap10/sysdispqlen.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sysdispqlen.d\n *\n * Example script from Chapter 10 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Sampling at 1001 Hertz... Hit Ctrl-C to end.\\n\");\n}\n\nprofile:::profile-1001hz\n{\n\t@[\"System wide disp queue length:\"] =\n\t    sum(curthread->t_cpu->cpu_disp->disp_nrunnable);\n}\n\nprofile:::tick-1sec\n{\n\tnormalize(@, 1001);\n\tprinta(@);\n\ttrunc(@);\n}\n"
  },
  {
    "path": "Chap11/cuckoo.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cuckoo.d\n *\n * Example script from Chapter 11 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %6s %6s %6s %s\\n\", \"TIME\", \"PID\", \"PPID\", \"UID\", \"TEXT\");\n}\n\nfbt::cnwrite:entry\n{\n\tthis->iov = args[1]->uio_iov;\n\tthis->len = this->iov->iov_len;\n\tthis->text = stringof((char *)copyin((uintptr_t)this->iov->iov_base,\n\t    this->len));\n\tthis->text[this->len] = '\\0';\n\n\tprintf(\"%-20Y %6d %6d %6d %s\\n\", walltimestamp, pid, ppid, uid,\n\t    this->text);\n}\n"
  },
  {
    "path": "Chap11/keylatency.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * keylatency.d\n *\n * Example script from Chapter 11 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\n/* process name to monitor */\ninline string TARGET = \"bash\";\n\nself string lastkey;\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing %s keystrokes...  Hit Ctrl-C to end.\\n\", TARGET);\n}\n\nsyscall::read:entry\n/execname == TARGET && arg0 == 0/\n{\n\tself->buf = arg1;\n\tself->start = timestamp;\n}\n\nsyscall::read:return\n/self->buf && arg0 == 1/\n{\n\tthis->latency = timestamp - self->start;\n\tthis->key = stringof((char *)copyin(self->buf, arg0));\n\tthis->key = this->key == \"\\r\" ? \"NL\" : this->key;\t/* return */\n\tthis->key = this->key == \"\\t\" ? \"TAB\" : this->key;\t/* tab */\n\tthis->key = this->key == \"\\177\" ? \"BS\" : this->key;\t/* backspace */\n\t@a[self->lastkey != NULL ? self->lastkey : \" \", this->key] =\n\t    avg(this->latency);\n\t@c[self->lastkey != NULL ? self->lastkey : \" \", this->key] = count();\n\tself->lastkey = this->key;\n\tself->start = 0;\n}\n\nsyscall::read:return /self->buf/ { self->buf = 0; self->start = 0; }\n\ndtrace:::END\n{\n\tnormalize(@a, 1000000);\n\tprintf(\"Average Keystroke Latency for %s processes (ms):\\n\\n\", TARGET);\n\tprintf(\"%34s %8s\\n\", \"LATENCY\", \"COUNT\");\n\tprinta(\"%16s -> %3s %10@d %@8d\\n\", @a, @c);\n}\n"
  },
  {
    "path": "Chap11/networkwho.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * networkwho.d\n *\n * Example script from Chapter 11 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n/$1 == 0/\n{\n\tprintf(\"USAGE: networkwho.d PID\\n\");\n\texit(1);\n}\n\nsyscall::connect:entry,\nsyscall::listen:entry\n/pid == $1/\n{\n\tustack();\n}\n\nsyscall::write*:entry,\nsyscall::send*:entry\n/pid == $1/\n{\n\ttrace(fds[arg0].fi_fs);\n\tustack();\n}\n"
  },
  {
    "path": "Chap11/nosetuid.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nosetuid.d\n *\n * Example script from Chapter 11 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option destructive\n\ninline int ALLOWED_UID = 517;\n\ndtrace:::BEGIN\n{\n\tprintf(\"Watching setuid(), allowing only uid %d...\\n\", ALLOWED_UID);\n}\n\n/*\n * Kill setuid() processes who are becomming root, from non-root, and who\n * are not the allowed UID.\n */\nsyscall::setuid:entry\n/arg0 == 0 && curpsinfo->pr_uid != 0 && curpsinfo->pr_uid != ALLOWED_UID/\n{\n\tprintf(\"%Y KILLED %s %d -> %d\\n\", walltimestamp, execname,\n\t    curpsinfo->pr_uid, arg0);\n\traise(9);\n}\n"
  },
  {
    "path": "Chap11/nosnoopforyou.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * nosnoopforyou.d\n *\n * Example script from Chapter 11 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option destructive\n\n/* /usr/include/sys/dlpi.h: */\n#define\tDL_PROMISCON_REQ\t0x1f\n\ndtrace:::BEGIN\n{\n\ttrace(\"Preventing promiscuity...\\n\");\n}\n\nfbt::dld_wput_nondata:entry\n{\n\tthis->mp = args[1];\n\tthis->prim = ((union DL_primitives *)this->mp->b_rptr)->dl_primitive;\n}\n\nfbt::dld_wput_nondata:entry\n/this->prim == DL_PROMISCON_REQ/\n{\n\tprintf(\"%Y KILLED %s PID:%d PPID:%d\\n\", walltimestamp, execname,\n\t    pid, ppid);\n\t/* raise(9); */\n}\n"
  },
  {
    "path": "Chap11/reporter.sh",
    "content": "#!/bin/sh\n\necho \"$*\" >> /var/log/execlog.txt\n"
  },
  {
    "path": "Chap11/sshkeysnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sshkeysnoop.d - A program to print keystroke details from ssh.\n *                 Written in DTrace (Solaris 10 build 63).\n *\n * Example script from Chapter 11 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n *\n * WARNING: This is a demonstration program, please do not use this for\n * illegal purposes in your country such as breeching privacy.\n */\n\n#pragma D option quiet\n\n/*\n * Print header\n */\ndtrace:::BEGIN\n{\n\t/* print header */\n\tprintf(\"%5s %5s %5s %5s  %s\\n\", \"UID\", \"PID\", \"PPID\", \"TYPE\", \"TEXT\");\n}\n\n/*\n * Print ssh execution\n */\nsyscall::exec*:return\n/execname == \"ssh\"/\n{\n\t/* print output line */\n\tprintf(\"%5d %5d %5d %5s  %s\\n\\n\", curpsinfo->pr_euid, pid,\n\t    curpsinfo->pr_ppid, \"cmd\", stringof(curpsinfo->pr_psargs));\n}\n\n/*\n * Determine which fd is /dev/tty\n */\nsyscall::open*:entry\n/execname == \"ssh\"/\n{\n\tself->path = arg0;\n}\n\nsyscall::open*:return\n/self->path && copyinstr(self->path) == \"/dev/tty\"/\n{\n\t/* track this syscall */\n\tself->ok = 1;\n}\n\nsyscall::open*:return { self->path = 0; }\n\nsyscall::open*:return\n/self->ok/\n{\n\t/* save fd number */\n\tself->fd = arg0;\n}\n\n/*\n * Print ssh keystrokes\n */\nsyscall::read*:entry\n/execname == \"ssh\" && arg0 == self->fd/\n{\n\t/* remember buffer address */\n\tself->buf = arg1;\n}\n\nsyscall::read*:return\n/self->buf != NULL && arg0 < 2/\n{\n\tthis->text = (char *)copyin(self->buf, arg0);\n\n\t/* print output line */\n\tprintf(\"%5d %5d %5d %5s  %s\\n\", curpsinfo->pr_euid, pid,\n\t    curpsinfo->pr_ppid, \"key\", stringof(this->text));\n\tself->buf = NULL;\n}\n"
  },
  {
    "path": "Chap11/watchexec.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * watchexec.d\n *\n * Example script from Chapter 11 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option destructive\n#pragma D option quiet\n\ninline string REPORT_CMD = \"/usr/local/bin/reporter.sh\";\n\ndtrace:::BEGIN\n{\n\t/*\n\t * Ensure this contains all the reporting commands,\n\t * otherwise this script will be a feedback loop:\n\t */\n\tALLOWED[REPORT_CMD] = 1;\n\tALLOWED[\"/bin/sh\"] = 1;\n\n\t/*\n\t * Commands to allow.\n\t * Example list (from Solaris) in alphabetical order:\n\t */\n\tALLOWED[\"/bin/bash\"] = 1;\n\tALLOWED[\"/lib/svc/bin/svcio\"] = 1;\n\tALLOWED[\"/sbin/sh\"] = 1;\n\tALLOWED[\"/usr/apache2/current/bin/httpd\"] = 1;\n\tALLOWED[\"/usr/bin/basename\"] = 1;\n\tALLOWED[\"/usr/bin/cat\"] = 1;\n\tALLOWED[\"/usr/bin/chmod\"] = 1;\n\tALLOWED[\"/usr/bin/chown\"] = 1;\n\tALLOWED[\"/usr/bin/grep\"] = 1;\n\tALLOWED[\"/usr/bin/head\"] = 1;\n\tALLOWED[\"/usr/bin/ls\"] = 1;\n\tALLOWED[\"/usr/bin/pgrep\"] = 1;\n\tALLOWED[\"/usr/bin/pkill\"] = 1;\n\tALLOWED[\"/usr/bin/ssh\"] = 1;\n\tALLOWED[\"/usr/bin/svcprop\"] = 1;\n\tALLOWED[\"/usr/bin/tput\"] = 1;\n\tALLOWED[\"/usr/bin/tr\"] = 1;\n\tALLOWED[\"/usr/bin/uname\"] = 1;\n\tALLOWED[\"/usr/lib/nfs/mountd\"] = 1;\n\tALLOWED[\"/usr/lib/nfs/nfsd\"] = 1;\n\tALLOWED[\"/usr/sfw/bin/openssl\"] = 1;\n\tALLOWED[\"/usr/xpg4/bin/sh\"] = 1;\n\n\tprintf(\"Reporting unknown exec()s to %s...\\n\", REPORT_CMD);\n}\n\nsyscall::exec*:entry\n/ALLOWED[copyinstr(arg0)] != 1/\n{\n\t/*\n\t * Customize arguments for reporting command:\n\t */\n\tsystem(\"%s %s %d %d %d %Y\\n\", REPORT_CMD, copyinstr(arg0),\n\t    uid, pid, ppid, walltimestamp);\n}\n"
  },
  {
    "path": "Chap12/cswstat.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cswstat.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\t/* print header */\n\tprintf(\"%-20s  %8s %12s %12s\\n\", \"TIME\", \"NUM\", \"CSWTIME(us)\",\n\t    \"AVGTIME(us)\");\n\ttimes = 0;\n\tnum = 0;\n}\n\nsched:::off-cpu\n{\n\t/* csw start */\n\tnum++;\n\tstart[cpu] = timestamp;\n}\n\nsched:::on-cpu\n/start[cpu]/\n{\n\t/* csw end */\n\ttimes += timestamp - start[cpu];\n\tstart[cpu] = 0;\n}\n\nprofile:::tick-1sec\n{\n\t/* print output */\n\tprintf(\"%20Y  %8d %12d %12d\\n\", walltimestamp, num, times/1000,\n\t    num == 0 ? 0 : times/(1000 * num));\n\ttimes = 0;\n\tnum = 0;\n}\n"
  },
  {
    "path": "Chap12/kmem_osx.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * kmem_osx.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nfbt::kmem_alloc:entry\n{\n\t@alloc[arg2] = count();\n}\nfbt::kmem_free:entry\n{\n\t@free[arg2] = count();\n}\nEND\n{\n\tprintf(\"%-16s %-8s %-8s\\n\", \"SIZE\", \"ALLOCS\", \"FREES\");\n\tprinta(\"%-16d %-@8d %-@8d\\n\", @alloc, @free);\n}\n"
  },
  {
    "path": "Chap12/kmem_track.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * kmem_track.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nfbt::kmem_cache_alloc:entry\n{\n\t@alloc[args[0]->cache_name] = count();\n}\nfbt::kmem_cache_free:entry\n{\n\t@free[args[0]->cache_name] = count();\n}\ntick-1sec\n{\n\tprintf(\"%-32s %-8s %-8s\\n\", \"CACHE NAME\", \"ALLOCS\", \"FREES\");\n\tprinta(\"%-32s %-@8d %-@8d\\n\", @alloc, @free);\n\ttrunc(@alloc); trunc(@free);\n}\n"
  },
  {
    "path": "Chap12/koffcpu.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * koffcpu.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nsched:::off-cpu\n{\n\tself->start = timestamp;\n}\n\nsched:::on-cpu\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\t@[\"off-cpu (us):\", stack()] = quantize(this->delta);\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap12/koncpu.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * koncpu.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nprofile:::profile-1001\n{\n\t@[\"\\n  on-cpu stack (count @1001hz):\", stack()] = count();\n}\n"
  },
  {
    "path": "Chap12/ktrace.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ktrace.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n#pragma D option flowindent\n\nsyscall::$1:entry\n{\n\tself->flag = 1;\n}\nfbt:::\n/self->flag/\n{\n}\nsyscall::$1:return\n/self->flag/\n{\n\tself->flag = 0;\n\texit(0);\n}\n"
  },
  {
    "path": "Chap12/kwtrace.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * kwtrace.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option flowindent\n\nsyscall::write:entry\n/fds[arg0].fi_fs == $$1/\n{\n\tself->flag = 1;\n}\nfbt:::\n/self->flag/\n{\n}\nsyscall::write:return\n/self->flag/\n{\n\tself->flag = 0;\n\texit(0);\n}\n"
  },
  {
    "path": "Chap12/priclass.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * priclass.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Sampling... Hit Ctrl-C to end.\\n\");\n}\n\nprofile:::profile-1001hz\n{\n\t@count[stringof(curlwpsinfo->pr_clname)] =\n\t    lquantize(curlwpsinfo->pr_pri, 0, 170, 10);\n}\n"
  },
  {
    "path": "Chap12/putnexts.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * putnexts.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nfbt::putnext:entry\n{\n\t@[stringof(args[0]->q_qinfo->qi_minfo->mi_idname), stack(5)] = count();\n}\n"
  },
  {
    "path": "Chap12/segkmem.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * segkmem.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nfbt::segkmem_xalloc:entry\n{\n\t@segkmem_alloc[args[0]->vm_name, arg2] = count();\n}\nfbt::segkmem_free_vn:entry\n{\n\t@segkmem_free[args[0]->vm_name, arg2] = count();\n}\nEND\n{\n\tprintf(\"%-16s %-8s %-8s %-8s\\n\",\n\t    \"VMEM NAME\", \"SIZE\", \"ALLOCS\", \"FREES\");\n\tprinta(\"%-16s %-8d %-@8d %-@8d\\n\", @segkmem_alloc, @segkmem_free);\n}\n"
  },
  {
    "path": "Chap12/taskq.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * taskq.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN { trace(\"Tracing...  Interval 10 seconds, or Ctrl-C.\\n\"); }\n\nsdt:::taskq-enqueue\n{\n\tthis->tq  = (taskq_t *)arg0;\n\tthis->tqe = (taskq_ent_t *)arg1;\n\t@c[this->tq->tq_name, this->tqe->tqent_func] = count();\n\ttime[arg1] = timestamp;\n}\n\nsdt:::taskq-exec-start\n/time[arg1]/\n{\n\tthis->wait = timestamp - time[arg1];\n\tthis->tq  = (taskq_t *)arg0;\n\tthis->tqe = (taskq_ent_t *)arg1;\n\t@w[this->tq->tq_name, this->tqe->tqent_func] = sum(this->wait);\n\ttime[arg1] = timestamp;\n}\n\nsdt:::taskq-exec-end\n/time[arg1]/\n{\n\tthis->exec = timestamp - time[arg1];\n\tthis->tq  = (taskq_t *)arg0;\n\tthis->tqe = (taskq_ent_t *)arg1;\n\t@e[this->tq->tq_name, this->tqe->tqent_func] = sum(this->exec);\n\ttime[arg1] = 0;\n}\n\nprofile:::tick-10s,\ndtrace:::END\n{\n\tnormalize(@w, 1000000);\n\tnormalize(@e, 1000000);\n\tprintf(\"\\n %-22s %-25s %8s %9s %9s\\n\", \"TASKQ NAME\", \"FUNCTION\",\n\t    \"COUNT\", \"T_WAITms\", \"T_EXECms\");\n\tprinta(\" %-22.22s %-25.25a %8@d %@9d %@9d\\n\", @c, @w, @e);\n\ttrunc(@c); trunc(@w); trunc(@e);\n}\n"
  },
  {
    "path": "Chap12/writek.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * writek.d\n *\n * Example script from Chapter 12 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nsyscall::write:entry\n/fds[arg0].fi_fs == \"nfs4\"/\n{\n\tself->st = timestamp;\n}\nfbt::$1:entry\n/self->st/\n{\n\tself->kst[probefunc] = timestamp;\n}\nfbt::$1:return\n/self->kst[probefunc]/\n{\n\t@ktime[probefunc] = sum(timestamp - self->kst[probefunc]);\n\tself->kst[probefunc] = 0;\n}\nsyscall::write:return\n/self->st/\n{\n\t@write_syscall_time = sum(timestamp - self->st);\n\tself->st = 0;\n\texit(0);\n}\nEND\n{\n\tprinta(\"Write syscall: %@d (nanoseconds)\\n\", @write_syscall_time);\n\tprinta(\"Kernel function %s() time: %@d (nanoseconds)\\n\", @ktime);\n}\n"
  },
  {
    "path": "Chap2/chap2_pexec.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * chap2_pexec.d\n *\n * Example script from Chapter 2 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %6s %6s %6s  %s\\n\", \"ENDTIME\",\n\t    \"UID\", \"PPID\", \"PID\", \"PROCESS\");\n}\n\nproc:::exec-success\n{\n\tprintf(\"%-20Y %6d %6d %6d  %s\\n\", walltimestamp,\n\t    uid, ppid, pid, execname);\n}\n"
  },
  {
    "path": "Chap3/brk.d",
    "content": "#!/usr/sbin/dtrace -qs\n/*\n * brk.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nself int endds;\n\nsyscall::brk:entry\n/pid == $target && !self->endds/\n{\n\tself->endds = arg0;\n}\n\nsyscall::brk:entry\n/pid == $target && self->endds != arg0/\n{\n\tprintf(\"Allocated %d\\n\", arg0 - self->endds);\n\tself->endds = arg0;\n}\n"
  },
  {
    "path": "Chap3/disk_io.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * disk_io.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\n#define\tPRINT_HDR printf(\"%-8s %-16s %-8s %-16s\\n\",\n\t\"RPS\", \"RD BYTES\", \"WPS\", \"WR BYTES\");\n\ndtrace:::BEGIN\n{\n\tPRINT_HDR\n}\n\nio:::start\n/execname == $$1 && args[0]->b_flags & B_READ/\n{\n\t@rps = count();\n\t@rbytes = sum(args[0]->b_bcount);\n}\n\nio:::start\n/execname == $$1 && args[0]->b_flags & B_WRITE/\n{\n\t@wps = count();\n\t@wbytes = sum(args[0]->b_bcount);\n}\ntick-1sec\n{\n\tprinta(\"%-@8d %-@16d %-@8d %-@16d\\n\", @rps, @rbytes, @wps, @wbytes);\n\ttrunc(@rps); trunc(@rbytes); trunc(@wps); trunc(@wbytes);\n}\ntick-1sec\n/x++ == 20/\n{\n\tPRINT_HDR\n\tx = 0;\n}\n"
  },
  {
    "path": "Chap3/fstop10.d",
    "content": "#!/usr/sbin/dtrace -qs\n/*\n * fstop10.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nfsinfo:::\n{\n\t@[execname, probefunc] = count();\n}\nEND\n{\n\ttrunc(@, 10);\n\tprintf(\"%-16s %-16s %-8s\\n\", \"EXEC\", \"FS FUNC\", \"COUNT\");\n\tprinta(\"%-16s %-16s %-@8d\\n\", @);\n}\n"
  },
  {
    "path": "Chap3/fstop10_enhanced.d",
    "content": "#!/usr/sbin/dtrace -qs\n/*\n * fstop10_enhanced.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nfsinfo:::\n{\n\t@[execname, probename, args[0]->fi_fs, args[0]->fi_pathname] = count();\n}\nEND\n{\n\ttrunc(@, 10);\n\tprintf(\"%-16s %-8s %-8s %-32s %-8s\\n\",\n\t    \"EXEC\", \"FS FUNC\", \"FS TYPE\", \"PATH\", \"COUNT\");\n\tprinta(\"%-16s %-8s %-8s %-32s %-@8d\\n\", @);\n}\n"
  },
  {
    "path": "Chap3/iotimeq.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iotimeq.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN { trace(\"Tracing...Output afer 10 seconds, or Ctrl-C\\n\"); }\n\nio:::start\n{\n\tstart[args[0]->b_edev, args[0]->b_blkno] = timestamp;\n}\n\nio:::done\n/start[args[0]->b_edev, args[0]->b_blkno]/\n{\n\tthis->elapsed =\n\t    (timestamp - start[args[0]->b_edev, args[0]->b_blkno]) / 1000000;\n\t@iot[args[1]->dev_statname,\n\t    args[0]->b_flags & B_READ ? \"READS(ms)\" : \"WRITES(ms)\"] =\n\t    quantize(this->elapsed);\n\tstart[args[0]->b_edev, args[0]->b_blkno] = 0;\n}\ntick-10sec\n{\n\tprinta(@iot);\n\texit(0);\n}\n"
  },
  {
    "path": "Chap3/kprof.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * kprof.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nprofile-997hz\n/arg0 && curthread->t_pri != -1/\n{\n\t@[stack()] = count();\n}\ntick-10sec\n{\n\ttrunc(@, 10);\n\tprinta(@);\n\texit(0);\n}\n"
  },
  {
    "path": "Chap3/kprof_func.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * kprof_func.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n#pragma D option quiet\n\nprofile-997hz\n/arg0 && curthread->t_pri != -1/\n{\n\t@[func(caller), func(arg0)] = count();\n}\ntick-10sec\n{\n\ttrunc(@, 20);\n\tprintf(\"%-24s %-32s %-8s\\n\", \"CALLER\", \"FUNCTION\", \"COUNT\");\n\tprinta(\"%-24a %-32a %-@8d\\n\", @);\n\texit(0);\n}\n"
  },
  {
    "path": "Chap3/lat.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * lat.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n#pragma D option quiet\nsched:::enqueue\n{\n\ts[args[0]->pr_lwpid, args[1]->pr_pid] = timestamp;\n}\n\nsched:::dequeue\n/this->start = s[args[0]->pr_lwpid, args[1]->pr_pid]/\n{\n\tthis->time = timestamp - this->start;\n\t@lat_avg[args[2]->cpu_id] = avg(this->time);\n\t@lat_max[args[2]->cpu_id] = max(this->time);\n\t@lat_min[args[2]->cpu_id] = min(this->time);\n\ts[args[0]->pr_lwpid, args[1]->pr_pid] = 0;\n\n}\ntick-1sec\n{\n\tprintf(\"%-8s %-12s %-12s %-12s\\n\",\n\t    \"CPU\", \"AVG(ns)\", \"MAX(ns)\", \"MIN(ns)\");\n\tprinta(\"%-8d %-@12d %-@12d %-@12d\\n\", @lat_avg, @lat_max, @lat_min);\n\ttrunc(@lat_avg); trunc(@lat_max); trunc(@lat_min);\n}\n"
  },
  {
    "path": "Chap3/mmap.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * mmap.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option flowindent\n\nsyscall::mmap:entry\n{\n\tself->flag = 1;\n}\nfbt:::\n/self->flag/\n{\n}\nsyscall::mmap:return\n/self->flag/\n{\n\tself->flag = 0;\n\texit(0);\n}\n"
  },
  {
    "path": "Chap3/net.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * net.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nsyscall::*read:entry,\nsyscall::*write:entry\n/fds[arg0].fi_fs == \"sockfs\"/\n{\n\t@ior[probefunc] = count();\n\t@net_bytes[probefunc] = sum(arg2);\n}\ntick-1sec\n{\n\tprintf(\"%-8s %-16s %-16s\\n\", \"FUNC\", \"OPS PER SEC\", \"BYTES PER SEC\");\n\tprinta(\"%-8s %-@16d %-@16d\\n\", @ior, @net_bytes);\n\ttrunc(@ior); trunc(@net_bytes);\n\tprintf(\"\\n\");\n}\n"
  },
  {
    "path": "Chap3/nfs.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfs.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nfbt:nfs:nfs4_getapage:entry\n/execname == \"m2loader\"/\n{\n\tself->st = timestamp;\n\t@calls = count();\n}\nfbt:nfs:nfs4_getapage:return\n/self->st/\n{\n\t@mint = min(timestamp - self->st);\n\t@maxt = max(timestamp - self->st);\n\t@avgt = avg(timestamp - self->st);\n\t@t[\"ns\"] = quantize(timestamp - self->st);\n\tself->st = 0;\n}\nEND\n{\n\tnormalize(@mint, 1000);\n\tnormalize(@maxt, 1000);\n\tnormalize(@avgt, 1000);\n\tprintf(\"%-8s %-8s %-8s %-8s\\n\",\n\t    \"CALLS\", \"MIN(us)\", \"MAX(us)\", \"AVG(us)\");\n\tprinta(\"%-@8d %-@8d %-@8d %-@8d\\n\", @calls, @mint, @maxt, @avgt);\n\tprintf(\"\\n\");\n\tprinta(@t);\n}\n"
  },
  {
    "path": "Chap3/pf.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * pf.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN { trace(\"Tracing...Ouput after 10 seconds, or Ctrl-C\\n\"); }\n\nfbt:unix:pagefault:entry\n{\n\t@st[execname] = count();\n\tself->pfst = timestamp\n}\nfbt:unix:pagefault:return\n/self->pfst/\n{\n\t@pft[execname] = sum(timestamp - self->pfst);\n\tself->pfst = 0;\n}\ntick-10s\n{\n\tprintf(\"Pagefault counts by execname ...\\n\");\n\tprinta(@st);\n\n\tprintf(\"\\nPagefault times(ns) by execname...\\n\");\n\tprinta(@pft);\n\n\ttrunc(@st);\n\ttrunc(@pft);\n}\n"
  },
  {
    "path": "Chap3/plat.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * plat.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n#pragma D option quiet\nsched:::enqueue\n/args[1]->pr_pid == $target/\n{\n\ts[args[2]->cpu_id] = timestamp;\n}\n\nsched:::dequeue\n/s[args[2]->cpu_id]/\n{\n\t@lat_sum[args[1]->pr_pid] = sum(timestamp - s[args[2]->cpu_id]);\n\ts[args[2]->cpu_id] = 0;\n}\n\ntick-1sec\n{\n\tnormalize(@lat_sum, 1000);\n\tprinta(\"PROCESS: %d spent %@d microseconds waiting for a CPU\\n\",\n\t    @lat_sum);\n\ttrunc(@lat_sum);\n}\n"
  },
  {
    "path": "Chap3/rq.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * rq.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nsched:::enqueue\n{\n\tthis->len = qlen[args[2]->cpu_id]++;\n\t@[args[2]->cpu_id] = lquantize(this->len, 0, 100);\n}\n\nsched:::dequeue\n/qlen[args[2]->cpu_id]/\n{\n\tqlen[args[2]->cpu_id]--;\n}\n"
  },
  {
    "path": "Chap3/rw_bytes.d",
    "content": "#! /usr/sbin/dtrace -qs\n/*\n * rw_bytes.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nsyscall::read:entry,\nsyscall::write:entry\n/fds[arg0].fi_fs == \"sockfs\"/\n{\n\tself->flag = 1\n}\nsyscall::read:return,\nsyscall::write:return\n/(int)arg0 != -1 && self->flag/\n{\n\t@[probefunc] = sum(arg0);\n}\nsyscall::read:return,\nsyscall::write:return\n{\n\tself->flag = 0;\n}\n"
  },
  {
    "path": "Chap3/rwa.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * rwa.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN { trace(\"Tracing... Output after 10 seconds, or Ctrl-C\\n\"); }\n\nsyscall::$1:entry\n/execname == $$2/\n{\n\tself->fd = arg0;\n\tself->st = timestamp;\n}\nsyscall::$1:return\n/self->st/\n{\n\t@iot[pid, probefunc, fds[self->fd].fi_pathname] =\n\t    sum(timestamp - self->st);\n\tself->fd = 0;\n\tself->st = 0;\n}\ntick-10sec\n{\n\tnormalize(@iot, 1000);\n\tprintf(\"%-8s %-8s %-32s %-16s\\n\",\n\t    \"PID\", \"SYSCALL\", \"PATHNAME\", \"TIME(us)\");\n\tprinta(\"%-8d %-8s %-32s %-@16d\\n\", @iot);\n}\n"
  },
  {
    "path": "Chap3/scrwtop10.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * scrwtop10.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nsyscall::*read*:entry,\nsyscall::*write*:entry\n{\n\t@[execname, probefunc, fds[arg0].fi_fs] = count();\n}\nEND\n{\n\ttrunc(@, 10);\n\tprintf(\"%-16s %-16s %-8s %-8s\\n\", \"EXEC\", \"SYSCALL\", \"FS\", \"COUNT\");\n\tprinta(\"%-16s %-16s %-8s %-@8d\\n\", @);\n}\n"
  },
  {
    "path": "Chap3/sctop10.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sctop10.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nsyscall:::entry\n{\n\t@[execname, probefunc] = count();\n}\nEND\n{\n\ttrunc(@, 10);\n\tprintf(\"%-16s %-16s %-8s\\n\", \"EXEC\", \"SYSCALL\", \"COUNT\");\n\tprinta(\"%-16s %-16s %-@8d\\n\", @);\n}\n"
  },
  {
    "path": "Chap3/sock.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sock.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nfbt:sockfs::entry\n{\n\t@[execname, probefunc] = count();\n}\nEND\n{\n\tprintf(\"%-16s %-24s %-8s\\n\", \"EXEC\", \"SOCKFS FUNC\", \"COUNT\");\n\tprinta(\"%-16s %-24s %-@8d\\n\", @);\n}\n"
  },
  {
    "path": "Chap3/sock_j.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sock_j.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nfbt:sockfs::entry\n/execname == \"java\"/\n{\n\t@[probefunc] = count();\n\tself->st[stackdepth] = timestamp;\n\n}\nfbt:sockfs::return\n/self->st[stackdepth]/\n{\n\t@sockfs_times[pid, probefunc] = sum(timestamp - self->st[stackdepth]);\n\tself->st[stackdepth] = 0;\n}\ntick-1sec\n{\n\tnormalize(@sockfs_times, 1000);\n\tprintf(\"%-8s %-24s %-16s\\n\", \"PID\", \"SOCKFS FUNC\", \"TIME(ms)\");\n\tprinta(\"%-8d %-24s %-@16d\\n\", @sockfs_times);\n\n\tprintf(\"\\nSOCKFS CALLS PER SECOND:\\n\");\n\tprinta(@);\n\n\ttrunc(@); trunc(@sockfs_times);\n\tprintf(\"\\n\\n\");\n}\n"
  },
  {
    "path": "Chap3/vmtop10.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * vmtop10.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nvminfo:::\n{\n\t@[execname, probefunc, probename] = count();\n}\ntick-1sec\n{\n\ttrunc(@, 10);\n\tprintf(\"%-16s %-16s %-16s %-8s\\n\", \"EXEC\", \"FUNCTION\", \"NAME\", \"COUNT\");\n\tprinta(\"%-16s %-16s %-16s %-@8d\\n\", @);\n\ttrunc(@);\n\tprintf(\"\\n\");\n}\n"
  },
  {
    "path": "Chap3/wrun.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * wrun.d\n *\n * Example script from Chapter 3 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\ninline int MAX = 10;\n\ndtrace:::BEGIN\n{\n\tstart = timestamp;\n\tprintf(\"Tracing for %d seconds...hit Ctrl-C to terminate sooner\\n\",\n\t    MAX);\n}\n\nsched:::on-cpu\n/pid == $target/\n{\n\tself->ts = timestamp;\n}\n\nsched:::off-cpu\n/self->ts/\n{\n\t@[cpu] = sum(timestamp - self->ts);\n\tself->ts = 0;\n}\n\nprofile:::tick-1sec\n/++x == MAX/\n{\n\texit(0);\n}\n\ndtrace:::END\n{\n\tprintf(\"\\nCPU distribution over %d milliseconds:\\n\\n\",\n\t    (timestamp - start) / 1000000);\n\tprintf(\"CPU microseconds\\n--- ------------\\n\");\n\tnormalize(@, 1000);\n\tprinta(\"%3d %@d\\n\", @);\n}\n"
  },
  {
    "path": "Chap4/bitesize.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * bitesize.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nio:::start\n{\n\tthis->size = args[0]->b_bcount;\n\t@Size[pid, curpsinfo->pr_psargs] = quantize(this->size);\n}\n\ndtrace:::END\n{\n\tprintf(\"\\n%8s  %s\\n\", \"PID\", \"CMD\");\n\tprinta(\"%8d  %S\\n%@d\\n\", @Size);\n}\n"
  },
  {
    "path": "Chap4/disklatency.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * disklatency.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nio:::start\n{\n\tstart_time[arg0] = timestamp;\n}\n\nio:::done\n/this->start = start_time[arg0]/\n{\n\tthis->delta = (timestamp - this->start) / 1000;\n\t@[args[1]->dev_statname, args[1]->dev_major, args[1]->dev_minor] =\n\t    quantize(this->delta);\n\tstart_time[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tprinta(\"   %s (%d,%d), us:\\n%@d\\n\", @);\n}\n"
  },
  {
    "path": "Chap4/geomiosnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * geomiosnoop.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\n/* from /usr/src/sys/sys/bio.h */\ninline int BIO_READ = 0x01;\ninline int BIO_WRITE = 0x02;\n\ndtrace:::BEGIN\n{\n\tprintf(\"%5s %5s %1s %10s %6s %16s %-8s %s\\n\", \"UID\", \"PID\", \"D\",\n\t    \"OFFSET(KB)\", \"BYTES\", \"COMM\", \"VNODE\", \"INFO\");\n}\n\nfbt::g_vfs_strategy:entry\n{\n\t/* attempt to fetch the filename from the namecache */\n\tthis->file = args[1]->b_vp->v_cache_dd != NULL ?\n\t    stringof(args[1]->b_vp->v_cache_dd->nc_name) : \"<unknown>\";\n\tprintf(\"%5d %5d %1s %10d %6d %16s %-8x %s \\n\", uid, pid,\n\t    args[1]->b_iocmd & BIO_READ ? \"R\" : \"W\",\n\t    args[1]->b_iooffset / 1024, args[1]->b_bcount,\n\t    execname, (uint64_t)args[1]->b_vp, this->file);\n}\n\nfbt::g_dev_strategy:entry\n{\n\tprintf(\"%5d %5d %1s %10d %6d %16s %-8s %s\\n\", uid, pid,\n\t    args[0]->bio_cmd & BIO_READ ? \"R\" : \"W\",\n\t    args[0]->bio_offset / 1024, args[0]->bio_bcount,\n\t    execname, \"<dev>\", stringof(args[0]->bio_dev->si_name));\n}\n"
  },
  {
    "path": "Chap4/ideerr.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ideerr.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nstring dcmd[uchar_t];\n\ndtrace:::BEGIN\n{\n\t/*\n\t * These command and error descriptions are from the DCMD_* and DERR_*\n\t * definitions in /usr/include/sys/dktp/dadkio.h:\n\t */\n\n\tdcmd[1] = \"Read Sectors/Blocks\";\n\tdcmd[2] = \"Write Sectors/Blocks\";\n\tdcmd[3] = \"Format Tracks\";\n\tdcmd[4] = \"Format entire drive\";\n\tdcmd[5] = \"Recalibrate\";\n\tdcmd[6] = \"Seek to Cylinder\";\n\tdcmd[7] = \"Read Verify sectors on disk\";\n\tdcmd[8] = \"Read manufacturers defect list\";\n\tdcmd[9] = \"Lock door\";\n\tdcmd[10] = \"Unlock door\";\n\tdcmd[11] = \"Start motor\";\n\tdcmd[12] = \"Stop motor\";\n\tdcmd[13] = \"Eject medium\";\n\tdcmd[14] = \"Update geometry\";\n\tdcmd[15] = \"Get removable disk status\";\n\tdcmd[16] = \"cdrom pause\";\n\tdcmd[17] = \"cdrom resume\";\n\tdcmd[18] = \"cdrom play by track and index\";\n\tdcmd[19] = \"cdrom play msf\";\n\tdcmd[20] = \"cdrom sub channel\";\n\tdcmd[21] = \"cdrom read mode 1\";\n\tdcmd[22] = \"cdrom read table of contents header\";\n\tdcmd[23] = \"cdrom read table of contents entry\";\n\tdcmd[24] = \"cdrom read offset\";\n\tdcmd[25] = \"cdrom mode 2\";\n\tdcmd[26] = \"cdrom volume control\";\n\tdcmd[27] = \"flush write cache to physical medium\";\n\n\tderr[0] = \"success\";\n\tderr[1] = \"address mark not found\";\n\tderr[2] = \"track 0 not found\";\n\tderr[3] = \"aborted command\";\n\tderr[4] = \"write fault\";\n\tderr[5] = \"ID not found\";\n\tderr[6] = \"drive busy\";\n\tderr[7] = \"uncorrectable data error\";\n\tderr[8] = \"bad block detected\";\n\tderr[9] = \"invalid cdb\";\n\tderr[10] = \"hard device error- no retry\";\n\tderr[11] = \"Illegal length indication\";\n\tderr[12] = \"End of media detected\";\n\tderr[13] = \"Media change requested\";\n\tderr[14] = \"Recovered from error\";\n\tderr[15] = \"Device not ready\";\n\tderr[16] = \"Medium error\";\n\tderr[17] = \"Hardware error\";\n\tderr[18] = \"Illegal request\";\n\tderr[19] = \"Unit attention\";\n\tderr[20] = \"Data protection\";\n\tderr[21] = \"Miscompare\";\n\tderr[22] = \"Interface CRC error\";\n\tderr[23] = \"Reserved\";\n\n\t/* from CPS_* definitions in /usr/include/sys/dktp/cmpkt.h */\n\treason[0] = \"success\";\n\treason[1] = \"failure\";\n\treason[2] = \"fail+err\";\n\treason[3] = \"aborted\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::dadk_pktcb:entry\n{\n\tthis->pktp = args[0];\n\n\tthis->cmd = *(char *)this->pktp->cp_cdbp;\n\tthis->cmd_text = dcmd[this->cmd] != NULL ?\n\t    dcmd[this->cmd] : lltostr(this->cmd);\n\tthis->reason = this->pktp->cp_reason;\n\tthis->reason_text = reason[this->reason] != NULL ?\n\t    reason[this->reason] : lltostr(this->reason);\n\tthis->err = *(char *)this->pktp->cp_scbp;\n\tthis->err_text = derr[this->err] != NULL ?\n\t    derr[this->err] : lltostr(this->err);\n\n\t@[this->cmd_text, this->reason_text, this->err_text] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"%-36s %8s %27s %s\\n\", \"IDE COMMAND\", \"REASON\", \"ERROR\",\n\t    \"COUNT\");\n\tprinta(\"%-36s %8s %27s %@d\\n\", @);\n}\n"
  },
  {
    "path": "Chap4/idelatency.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * idelatency.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nstring dcmd[uchar_t];\n\ndtrace:::BEGIN\n{\n\t/*\n\t * These command descriptions are from the DCMD_* definitions\n\t * in /usr/include/sys/dktp/dadkio.h:\n\t */\n\tdcmd[1] = \"Read Sectors/Blocks\";\n\tdcmd[2] = \"Write Sectors/Blocks\";\n\tdcmd[3] = \"Format Tracks\";\n\tdcmd[4] = \"Format entire drive\";\n\tdcmd[5] = \"Recalibrate\";\n\tdcmd[6] = \"Seek to Cylinder\";\n\tdcmd[7] = \"Read Verify sectors on disk\";\n\tdcmd[8] = \"Read manufacturers defect list\";\n\tdcmd[9] = \"Lock door\";\n\tdcmd[10] = \"Unlock door\";\n\tdcmd[11] = \"Start motor\";\n\tdcmd[12] = \"Stop motor\";\n\tdcmd[13] = \"Eject medium\";\n\tdcmd[14] = \"Update geometry\";\n\tdcmd[15] = \"Get removable disk status\";\n\tdcmd[16] = \"cdrom pause\";\n\tdcmd[17] = \"cdrom resume\";\n\tdcmd[18] = \"cdrom play by track and index\";\n\tdcmd[19] = \"cdrom play msf\";\n\tdcmd[20] = \"cdrom sub channel\";\n\tdcmd[21] = \"cdrom read mode 1\";\n\tdcmd[22] = \"cdrom read table of contents header\";\n\tdcmd[23] = \"cdrom read table of contents entry\";\n\tdcmd[24] = \"cdrom read offset\";\n\tdcmd[25] = \"cdrom mode 2\";\n\tdcmd[26] = \"cdrom volume control\";\n\tdcmd[27] = \"flush write cache to physical medium\";\n\n\t/* from CPS_* definitions in /usr/include/sys/dktp/cmpkt.h */\n\treason[0] = \"success\";\n\treason[1] = \"failure\";\n\treason[2] = \"fail+err\";\n\treason[3] = \"aborted\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\n/* IDE command start */\nfbt::dadk_pktprep:return\n{\n\tstart[arg1] = timestamp;\n}\n\n/* IDE command completion */\nfbt::dadk_pktcb:entry\n/start[arg0]/\n{\n\tthis->pktp = args[0];\n\n\tthis->delta = (timestamp - start[arg0]) / 1000;\n\tthis->cmd = *((uchar_t *)this->pktp->cp_cdbp);\n\tthis->cmd_text = dcmd[this->cmd] != NULL ?\n\t    dcmd[this->cmd] : lltostr(this->cmd);\n\tthis->reason = this->pktp->cp_reason;\n\tthis->reason_text = reason[this->reason] != NULL ?\n\t    reason[this->reason] : lltostr(this->reason);\n\n\t@num[this->cmd_text, this->reason_text] = count();\n\t@average[this->cmd_text, this->reason_text] = avg(this->delta);\n\t@total[this->cmd_text, this->reason_text] = sum(this->delta);\n\n\tstart[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tnormalize(@total, 1000);\n\tprintf(\"\\n  %-36s %8s %8s %10s %10s\\n\", \"IDE COMMAND\",\n\t    \"REASON\", \"COUNT\", \"AVG(us)\", \"TOTAL(ms)\");\n\tprinta(\"  %-36s %8s %@8d %@10d %@10d\\n\", @num, @average, @total);\n}\n"
  },
  {
    "path": "Chap4/iderw.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iderw.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nstring dcmd[uchar_t];\n\ndtrace:::BEGIN\n{\n\t/*\n\t * These commands of interest are from the DCMD_* definitions in\n\t * /usr/include/sys/dktp/dadkio.h:\n\t */\n\tdcmd[1] = \"Read Sectors/Blocks\";\n\tdcmd[2] = \"Write Sectors/Blocks\";\n\tdcmd[27] = \"flush write cache\";\n\n\t/* from CPS_* definitions in /usr/include/sys/dktp/cmpkt.h */\n\treason[0] = \"success\";\n\treason[1] = \"failure\";\n\treason[2] = \"fail+err\";\n\treason[3] = \"aborted\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::dadk_pktprep:entry\n{\n\tself->size = args[2]->b_bcount;\n}\n\n/* IDE command start */\nfbt::dadk_pktprep:return\n{\n\tstart[arg1] = timestamp;\n\tsize[arg1] = self->size;\n\tself->size = 0;\n}\n\n/* IDE command completion */\nfbt::dadk_pktcb:entry\n/start[arg0]/\n{\n\tthis->pktp = args[0];\n\tthis->cmd = *((uchar_t *)this->pktp->cp_cdbp);\n}\n\n/* Only match desired commands: read/write/flush-cache */\nfbt::dadk_pktcb:entry\n/start[arg0] && dcmd[this->cmd] != NULL/\n{\n\tthis->delta = (timestamp - start[arg0]) / 1000;\n\tthis->cmd_text = dcmd[this->cmd] != NULL ?\n\t    dcmd[this->cmd] : lltostr(this->cmd);\n\tthis->size = size[arg0];\n\n\t@num[this->cmd_text] = count();\n\t@avg_size[this->cmd_text] = avg(this->size);\n\t@avg_time[this->cmd_text] = avg(this->delta);\n\t@sum_size[this->cmd_text] = sum(this->size);\n\t@sum_time[this->cmd_text] = sum(this->delta);\n\t@plot_size[this->cmd_text] = quantize(this->size);\n\t@plot_time[this->cmd_text] = quantize(this->delta);\n\n\tstart[arg0] = 0;\n\tsize[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tnormalize(@avg_size, 1024);\n\tnormalize(@sum_size, 1048576);\n\tnormalize(@sum_time, 1000);\n\tprintf(\"  %-20s  %8s  %10s %10s  %10s %11s\\n\", \"DIR\",\n\t    \"COUNT\", \"AVG(KB)\", \"TOTAL(MB)\", \"AVG(us)\", \"TOTAL(ms)\");\n\tprinta(\"  %-20s  %@8d  %@10d %@10d  %@10d %@11d\\n\", @num,\n\t    @avg_size, @sum_size, @avg_time, @sum_time);\n\tprintf(\"\\n\\nIDE I/O size (bytes):\\n\");\n\tprinta(@plot_size);\n\tprintf(\"\\nIDE I/O latency (us):\\n\");\n\tprinta(@plot_time);\n}\n"
  },
  {
    "path": "Chap4/iolatency.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iolatency.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nio:::start\n{\n\tstart[arg0] = timestamp;\n}\n\nio:::done\n/start[arg0]/\n{\n\t@time[\"disk I/O latency (ns)\"] = quantize(timestamp - start[arg0]);\n\tstart[arg0] = 0;\n}\n"
  },
  {
    "path": "Chap4/iotypes.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iotypes.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nio:::start\n{\n\tstart_time[arg0] = timestamp;\n}\n\nio:::done\n/this->start = start_time[arg0]/\n{\n\tthis->delta = (timestamp - this->start) / 1000;\n\tthis->type = args[0]->b_flags & B_READ ? \"read\" : \"write\";\n\tthis->type = args[0]->b_flags & B_PHYS ?\n\t    strjoin(\"phys-\", this->type) : this->type;\n\tthis->type = args[0]->b_flags & B_ASYNC ?\n\t    strjoin(\"async-\", this->type) : this->type;\n\tthis->pageio = args[0]->b_flags & B_PAGEIO ? \"yes\" : \"no\";\n\tthis->error = args[0]->b_error != 0 ?\n\t    strjoin(\"Error:\", lltostr(args[0]->b_error)) : \"Success\";\n\n\t@num[this->type, this->pageio, this->error] = count();\n\t@average[this->type, this->pageio, this->error] = avg(this->delta);\n\t@total[this->type, this->pageio, this->error] = sum(this->delta);\n\n\tstart_time[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tnormalize(@total, 1000);\n\tprintf(\"\\n  %-18s %6s %10s %11s %11s %12s\\n\", \"TYPE\", \"PAGEIO\",\n\t    \"RESULT\", \"COUNT\", \"AVG(us)\", \"TOTAL(ms)\");\n\tprinta(\"  %-18s %6s %10s %@11d %@11d %@12d\\n\", @num, @average, @total);\n}\n"
  },
  {
    "path": "Chap4/mptevents.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * mptevents.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\t/*\n\t * These MPI_EVENT_* definitions are from uts/common/sys/mpt/mpi_ioc.h\n\t */\n\n\tmpi_event[0x00000000] = \"NONE\";\n\tmpi_event[0x00000001] = \"LOG_DATA\";\n\tmpi_event[0x00000002] = \"STATE_CHANGE\";\n\tmpi_event[0x00000003] = \"UNIT_ATTENTION\";\n\tmpi_event[0x00000004] = \"IOC_BUS_RESET\";\n\tmpi_event[0x00000005] = \"EXT_BUS_RESET\";\n\tmpi_event[0x00000006] = \"RESCAN\";\n\tmpi_event[0x00000007] = \"LINK_STATUS_CHANGE\";\n\tmpi_event[0x00000008] = \"LOOP_STATE_CHANGE\";\n\tmpi_event[0x00000009] = \"LOGOUT\";\n\tmpi_event[0x0000000A] = \"EVENT_CHANGE\";\n\tmpi_event[0x0000000B] = \"INTEGRATED_RAID\";\n\tmpi_event[0x0000000C] = \"SCSI_DEVICE_STATUS_CHANGE\";\n\tmpi_event[0x0000000D] = \"ON_BUS_TIMER_EXPIRED\";\n\tmpi_event[0x0000000E] = \"QUEUE_FULL\";\n\tmpi_event[0x0000000F] = \"SAS_DEVICE_STATUS_CHANGE\";\n\tmpi_event[0x00000010] = \"SAS_SES\";\n\tmpi_event[0x00000011] = \"PERSISTENT_TABLE_FULL\";\n\tmpi_event[0x00000012] = \"SAS_PHY_LINK_STATUS\";\n\tmpi_event[0x00000013] = \"SAS_DISCOVERY_ERROR\";\n\tmpi_event[0x00000014] = \"IR_RESYNC_UPDATE\";\n\tmpi_event[0x00000015] = \"IR2\";\n\tmpi_event[0x00000016] = \"SAS_DISCOVERY\";\n\tmpi_event[0x00000017] = \"SAS_BROADCAST_PRIMITIVE\";\n\tmpi_event[0x00000018] = \"SAS_INIT_DEVICE_STATUS_CHANGE\";\n\tmpi_event[0x00000019] = \"SAS_INIT_TABLE_OVERFLOW\";\n\tmpi_event[0x0000001A] = \"SAS_SMP_ERROR\";\n\tmpi_event[0x0000001B] = \"SAS_EXPANDER_STATUS_CHANGE\";\n\tmpi_event[0x00000021] = \"LOG_ENTRY_ADDED\";\n\n\tsas_discovery[0x00000000] = \"SAS_DSCVRY_COMPLETE\";\n\tsas_discovery[0x00000001] = \"SAS_DSCVRY_IN_PROGRESS\";\n\n\tdev_stat[0x03] = \"ADDED\";\n\tdev_stat[0x04] = \"NOT_RESPONDING\";\n\tdev_stat[0x05] = \"SMART_DATA\";\n\tdev_stat[0x06] = \"NO_PERSIST_ADDED\";\n\tdev_stat[0x07] = \"UNSUPPORTED\";\n\tdev_stat[0x08] = \"INTERNAL_DEVICE_RESET\";\n\tdev_stat[0x09] = \"TASK_ABORT_INTERNAL\";\n\tdev_stat[0x0A] = \"ABORT_TASK_SET_INTERNAL\";\n\tdev_stat[0x0B] = \"CLEAR_TASK_SET_INTERNAL\";\n\tdev_stat[0x0C] = \"QUERY_TASK_INTERNAL\";\n\tdev_stat[0x0D] = \"ASYNC_NOTIFICATION\";\n\tdev_stat[0x0E] = \"CMPL_INTERNAL_DEV_RESET\";\n\tdev_stat[0x0F] = \"CMPL_TASK_ABORT_INTERNAL\";\n\n\tprintf(\"%-20s  %-6s %-3s    %s\\n\", \"TIME\", \"MODULE\", \"CPU\", \"EVENT\");\n}\nsdt:mpt::handle-event-sync\n{\n\tthis->mpt = (mpt_t *)arg0;\n\tthis->mpt_name = strjoin(\"mpt\", lltostr(this->mpt->m_instance));\n\tthis->event_text = mpi_event[arg1] != NULL ?\n\t    mpi_event[arg1] : lltostr(arg1);\n\tprintf(\"%-20Y  %-6s %-3d -> %s\\n\", walltimestamp, this->mpt_name, cpu,\n\t    this->event_text);\n}\nsdt:mpt::handle-event-sync\n/arg1 == 0x00000016/\n{\n\tself->mpt = (mpt_t *)arg0;\n\tself->discovery = 1;\n}\nfbt::mpt_handle_event_sync:return\n/self->discovery/\n{\n\t/* remove the PHY_BITS from the discovery status */\n\tthis->cond = self->mpt->m_discovery & 0x0000FFFF;\n\tthis->cond_text = sas_discovery[this->cond] != NULL ?\n\t    sas_discovery[this->cond] : lltostr(this->cond);\n\tprintf(\"%-20Y  %-6s %-3d    -> discovery status: %s\\n\", walltimestamp,\n\t    this->mpt_name, cpu, this->cond_text);\n\tself->mpt = 0;\n\tself->discovery = 0;\n}\nsdt:mpt::device-status-change\n{\n\tthis->mpt = (mpt_t *)arg0;\n\tthis->mpt_name = strjoin(\"mpt\", lltostr(this->mpt->m_instance));\n\tthis->reason = arg2;\n\tthis->reason_text = dev_stat[this->reason] != NULL ?\n\t    dev_stat[this->reason] : lltostr(this->reason);\n\tprintf(\"%-20Y  %-6s %-3d    -> device change: %s\\n\", walltimestamp,\n\t    this->mpt_name, cpu, this->reason_text);\n\tprintf(\"%-20Y  %-6s %-3d       wwn=%x\\n\", walltimestamp,\n\t    this->mpt_name, cpu, arg3);\n}\nsdt:mpt::event-sas-phy-link-status\n{\n\tthis->mpt = (mpt_t *)arg0;\n\tthis->mpt_name = strjoin(\"mpt\", lltostr(this->mpt->m_instance));\n\tthis->phynum = arg1;\n\tprintf(\"%-20Y  %-6s %-3d    -> phy link status, phy=%d\\n\",\n\t    walltimestamp, this->mpt_name, cpu, this->phynum);\n}\n"
  },
  {
    "path": "Chap4/mptlatency.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * mptlatency.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\ndtrace:::BEGIN\n{\n\t/* See /usr/include/sys/scsi/generic/commands.h for the full list. */\n\tscsi_cmd[0x00] = \"test_unit_ready\";\n\tscsi_cmd[0x08] = \"read\";\n\tscsi_cmd[0x0a] = \"write\";\n\tscsi_cmd[0x12] = \"inquiry\";\n\tscsi_cmd[0x17] = \"release\";\n\tscsi_cmd[0x1a] = \"mode_sense\";\n\tscsi_cmd[0x1b] = \"load/start/stop\";\n\tscsi_cmd[0x1c] = \"get_diagnostic_results\";\n\tscsi_cmd[0x1d] = \"send_diagnostic_command\";\n\tscsi_cmd[0x25] = \"read_capacity\";\n\tscsi_cmd[0x28] = \"read(10)\";\n\tscsi_cmd[0x2a] = \"write(10)\";\n\tscsi_cmd[0x35] = \"synchronize_cache\";\n\tscsi_cmd[0x4d] = \"log_sense\";\n\tscsi_cmd[0x5e] = \"persistent_reserve_in\";\n\tscsi_cmd[0xa0] = \"report_luns\";\n}\n\nsdt:mpt::io-time-on-hba-non-a-reply\n{\n\tthis->mpt = (mpt_t *)arg0;\n\tthis->mpt_cmd = (mpt_cmd_t *)arg1;\n\n\tthis->mpt_name = strjoin(\"mpt\", lltostr(this->mpt->m_instance));\n\tthis->delta = (this->mpt_cmd->cmd_io_done_time -\n\t    this->mpt_cmd->cmd_io_start_time) / 1000;\n\tthis->code = *this->mpt_cmd->cmd_cdb;\n\tthis->cmd_text = scsi_cmd[this->code] != NULL ?\n\t    scsi_cmd[this->code] : lltostr(this->code);\n\t@[this->mpt_name, this->cmd_text] = quantize(this->delta);\n}\n\ndtrace:::END\n{\n\tprintf(\"Command Latency (us):\\n\");\n\tprinta(@);\n}\n"
  },
  {
    "path": "Chap4/mptsasscsi.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * mptsasscsi.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\n/* From uts/common/sys/mpt/mpi_ioc.h */\n#define\tMPI_PORTFACTS_PORTTYPE_INACTIVE\t\t0x00\n#define\tMPI_PORTFACTS_PORTTYPE_SCSI\t\t0x01\n#define\tMPI_PORTFACTS_PORTTYPE_FC\t\t0x10\n#define\tMPI_PORTFACTS_PORTTYPE_ISCSI\t\t0x20\n#define\tMPI_PORTFACTS_PORTTYPE_SAS\t\t0x30\n\ndtrace:::BEGIN\n{\n\t/* See /usr/include/sys/scsi/generic/commands.h for the full list. */\n\tscsi_cmd[0x00] = \"test_unit_ready\";\n\tscsi_cmd[0x08] = \"read\";\n\tscsi_cmd[0x0a] = \"write\";\n\tscsi_cmd[0x12] = \"inquiry\";\n\tscsi_cmd[0x17] = \"release\";\n\tscsi_cmd[0x1a] = \"mode_sense\";\n\tscsi_cmd[0x1b] = \"load/start/stop\";\n\tscsi_cmd[0x1c] = \"get_diagnostic_results\";\n\tscsi_cmd[0x1d] = \"send_diagnostic_command\";\n\tscsi_cmd[0x25] = \"read_capacity\";\n\tscsi_cmd[0x28] = \"read(10)\";\n\tscsi_cmd[0x2a] = \"write(10)\";\n\tscsi_cmd[0x35] = \"synchronize_cache\";\n\tscsi_cmd[0x4d] = \"log_sense\";\n\tscsi_cmd[0x5e] = \"persistent_reserve_in\";\n\tscsi_cmd[0xa0] = \"report_luns\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::mpt_start_cmd:entry\n/args[0]->m_port_type[0] == MPI_PORTFACTS_PORTTYPE_SAS/\n{\n\tthis->mpt = args[0];\n\tthis->mpt_name = strjoin(\"mpt\", lltostr(this->mpt->m_instance));\n\tthis->node_name = this->mpt->m_dip != NULL ?\n\t    stringof(((struct dev_info *)this->mpt->m_dip)->devi_node_name) :\n\t    \"<unknown>\";\n\tthis->scsi_pkt = args[1]->cmd_pkt;\n\tthis->code = *this->scsi_pkt->pkt_cdbp;\n\tthis->cmd_text = scsi_cmd[this->code] != NULL ?\n\t    scsi_cmd[this->code] : lltostr(this->code);\n\t@cmd[this->node_name, this->mpt_name, this->cmd_text] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-16s %-12s %-36s %s\\n\", \"DEVICE NODE\", \"MODULE\", \"SCSI CMD\",\n\t    \"COUNT\");\n\tprinta(\"  %-16s %-12s %-36s %@d\\n\", @cmd);\n}\n"
  },
  {
    "path": "Chap4/rwtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * rwtime.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nio:::start\n{\n\tstart_time[arg0] = timestamp;\n}\n\nio:::done\n/(args[0]->b_flags & B_READ) && (this->start = start_time[arg0])/\n{\n\tthis->delta = (timestamp - this->start) / 1000;\n\t@plots[\"read I/O, us\"] = quantize(this->delta);\n\t@avgs[\"average read I/O, us\"] = avg(this->delta);\n\tstart_time[arg0] = 0;\n}\n\nio:::done\n/!(args[0]->b_flags & B_READ) && (this->start = start_time[arg0])/\n{\n\tthis->delta = (timestamp - this->start) / 1000;\n\t@plots[\"write I/O, us\"] = quantize(this->delta);\n\t@avgs[\"average write I/O, us\"] = avg(this->delta);\n\tstart_time[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tprinta(\"   %s\\n%@d\\n\", @plots);\n\tprinta(@avgs);\n}\n"
  },
  {
    "path": "Chap4/satacmds.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * satacmds.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nstring sata_cmd[uchar_t];\n\ndtrace:::BEGIN\n{\n\t/*\n\t * These are from the SATA_DIR_* and SATA_OPMODE_* definitions in\n\t * /usr/include/sys/sata/sata_hba.h:\n\t */\n\tsata_dir[1] = \"no-data\";\n\tsata_dir[2] = \"read\";\n\tsata_dir[4] = \"write\";\n\tsata_opmode[0] = \"ints+async\";\t/* interrupts and asynchronous */\n\tsata_opmode[1] = \"poll\";\t/* polling */\n\tsata_opmode[4] = \"synch\";\t/* synchronous */\n\tsata_opmode[5] = \"synch+poll\";\t/* (valid?) */\n\n\t/*\n\t * These SATA command descriptions were generated from the SATAC_*\n\t * definitions in /usr/include/sys/sata/sata_defs.h:\n\t */\n\tsata_cmd[0x90] = \"diagnose command\";\n\tsata_cmd[0x10] = \"restore cmd, 4 bits step rate\";\n\tsata_cmd[0x50] = \"format track command\";\n\tsata_cmd[0xef] = \"set features\";\n\tsata_cmd[0xe1] = \"idle immediate\";\n\tsata_cmd[0xe0] = \"standby immediate\";\n\tsata_cmd[0xde] = \"door lock\";\n\tsata_cmd[0xdf] = \"door unlock\";\n\tsata_cmd[0xe3] = \"idle\";\n\tsata_cmd[0xe2] = \"standby\";\n\tsata_cmd[0x08] = \"ATAPI device reset\";\n\tsata_cmd[0x92] = \"Download microcode\";\n\tsata_cmd[0xed] = \"media eject\";\n\tsata_cmd[0xe7] = \"flush write-cache\";\n\tsata_cmd[0xec] = \"IDENTIFY DEVICE\";\n\tsata_cmd[0xa1] = \"ATAPI identify packet device\";\n\tsata_cmd[0x91] = \"initialize device parameters\";\n\tsata_cmd[0xa0] = \"ATAPI packet\";\n\tsata_cmd[0xc4] = \"read multiple w/DMA\";\n\tsata_cmd[0x20] = \"read sector\";\n\tsata_cmd[0x40] = \"read verify\";\n\tsata_cmd[0xc8] = \"read DMA\";\n\tsata_cmd[0x70] = \"seek\";\n\tsata_cmd[0xa2] = \"queued/overlap service\";\n\tsata_cmd[0xc6] = \"set multiple mode\";\n\tsata_cmd[0xca] = \"write (multiple) w/DMA\";\n\tsata_cmd[0xc5] = \"write multiple\";\n\tsata_cmd[0x30] = \"write sector\";\n\tsata_cmd[0x24] = \"read sector extended (LBA48)\";\n\tsata_cmd[0x25] = \"read DMA extended (LBA48)\";\n\tsata_cmd[0x29] = \"read multiple extended (LBA48)\";\n\tsata_cmd[0x34] = \"write sector extended (LBA48)\";\n\tsata_cmd[0x35] = \"write DMA extended (LBA48)\";\n\tsata_cmd[0x39] = \"write multiple extended (LBA48)\";\n\tsata_cmd[0xc7] = \"read DMA / may be queued\";\n\tsata_cmd[0x26] = \"read DMA ext / may be queued\";\n\tsata_cmd[0xcc] = \"write DMA / may be queued\";\n\tsata_cmd[0x36] = \"write DMA ext / may be queued\";\n\tsata_cmd[0xe4] = \"read port mult reg\";\n\tsata_cmd[0xe8] = \"write port mult reg\";\n\tsata_cmd[0x60] = \"First-Party-DMA read queued\";\n\tsata_cmd[0x61] = \"First-Party-DMA write queued\";\n\tsata_cmd[0x2f] = \"read log\";\n\tsata_cmd[0xb0] = \"SMART\";\n\tsata_cmd[0xe5] = \"check power mode\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\n/*\n * Trace SATA command start by probing the entry to the SATA HBA driver.  Four\n * different drivers are covered here; add yours here if it is missing.\n */\nfbt::nv_sata_start:entry,\nfbt::bcm_sata_start:entry,\nfbt::ahci_tran_start:entry,\nfbt::mv_start:entry\n{\n\tthis->dev = (struct dev_info *)arg0;\n\tthis->sata_pkt = (sata_pkt_t *)arg1;\n\n\tthis->modname = this->dev != NULL ?\n\t    stringof(this->dev->devi_node_name) : \"<unknown>\";\n\tthis->dir =\n\t    this->sata_pkt->satapkt_cmd.satacmd_flags.sata_data_direction;\n\tthis->dir_text = sata_dir[this->dir] != NULL ?\n\t    sata_dir[this->dir] : \"<none>\";\n\tthis->cmd = this->sata_pkt->satapkt_cmd.satacmd_cmd_reg;\n\tthis->cmd_text = sata_cmd[this->cmd] != NULL ?\n\t    sata_cmd[this->cmd] : lltostr(this->cmd);\n\tthis->op_mode = this->sata_pkt->satapkt_op_mode;\n\tthis->op_text = sata_opmode[this->op_mode] != NULL ?\n\t    sata_opmode[this->op_mode] : lltostr(this->op_mode);\n\n\t@[this->modname, this->dir_text, this->cmd_text, this->op_text] =\n\t    count();\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-14s %-9s %-30s %-10s   %s\\n\", \"DEVICE NODE\", \"DIR\",\n\t    \"COMMAND\", \"OPMODE\", \"COUNT\");\n\tprinta(\"  %-14s %-9s %-30s %-10s   %@d\\n\", @);\n}\n"
  },
  {
    "path": "Chap4/satalatency.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * satalatency.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nstring sata_cmd[uchar_t];\n\ndtrace:::BEGIN\n{\n\t/*\n\t * Some SATAC_* definitions from /usr/include/sys/sata/sata_defs.h, for\n\t * commands commonly issued.  More can be added from satacmds.d.\n\t */\n\tsata_cmd[0x20] = \"read sector\";\n\tsata_cmd[0x25] = \"read DMA extended\";\n\tsata_cmd[0x35] = \"write DMA extended\";\n\tsata_cmd[0x30] = \"write sector\";\n\tsata_cmd[0x40] = \"read verify\";\n\tsata_cmd[0x70] = \"seek\";\n\tsata_cmd[0x90] = \"diagnose command\";\n\tsata_cmd[0xb0] = \"SMART\";\n\tsata_cmd[0xec] = \"IDENTIFY DEVICE\";\n\tsata_cmd[0xe5] = \"check power mode\";\n\tsata_cmd[0xe7] = \"flush write-cache\";\n\tsata_cmd[0xef] = \"set features\";\n\n\t/*\n\t * These are SATA_PKT_* from /usr/include/sys/sata/sata_hba.h:\n\t */\n\tsata_reason[-1] = \"Not completed, busy\";\n\tsata_reason[0] = \"Success\";\n\tsata_reason[1] = \"Device reported error\";\n\tsata_reason[2] = \"Not accepted, queue full\";\n\tsata_reason[3] = \"Not completed, port error\";\n\tsata_reason[4] = \"Cmd unsupported\";\n\tsata_reason[5] = \"Aborted by request\";\n\tsata_reason[6] = \"Operation timeout\";\n\tsata_reason[7] = \"Aborted by reset request\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\n\t/*\n\t * Trace SATA command start by probing the entry to the SATA HBA\n\t * driver.  Four different drivers are covered here; add yours here\n\t * if it is missing.\n\t */\nfbt::nv_sata_start:entry,\nfbt::bcm_sata_start:entry,\nfbt::ahci_tran_start:entry,\nfbt::mv_start:entry\n{\n\tstart[arg1] = timestamp;\n}\n\nfbt::sata_pkt_free:entry\n/start[(uint64_t)args[0]->txlt_sata_pkt]/\n{\n\tthis->sata_pkt = args[0]->txlt_sata_pkt;\n\tthis->delta = (timestamp - start[(uint64_t)this->sata_pkt]) / 1000;\n\tthis->cmd = this->sata_pkt->satapkt_cmd.satacmd_cmd_reg;\n\tthis->cmd_text = sata_cmd[this->cmd] != NULL ?\n\t    sata_cmd[this->cmd] : lltostr(this->cmd);\n\tthis->reason = this->sata_pkt->satapkt_reason;\n\tthis->reason_text = sata_reason[this->reason] != NULL ?\n\t    sata_reason[this->reason] : lltostr(this->reason);\n\n\t@num[this->cmd_text, this->reason_text] = count();\n\t@average[this->cmd_text, this->reason_text] = avg(this->delta);\n\t@total[this->cmd_text, this->reason_text] = sum(this->delta);\n\n\tstart[(uint64_t)this->sata_pkt] = 0;\n}\n\ndtrace:::END\n{\n\tnormalize(@total, 1000);\n\tprintf(\"\\n  %-18s %23s %10s %10s %10s\\n\", \"SATA COMMAND\",\n\t    \"COMPLETION\", \"COUNT\", \"AVG(us)\", \"TOTAL(ms)\");\n\tprinta(\"  %-18s %23s %@10d %@10d %@10d\\n\", @num, @average, @total);\n}\n"
  },
  {
    "path": "Chap4/satareasons.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * satareasons.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nstring sata_cmd[uchar_t];\n\ndtrace:::BEGIN\n{\n\t/*\n\t * These are SATA_DIR_* from /usr/include/sys/sata/sata_hba.h:\n\t */\n\tsata_dir[1] = \"no-data\";\n\tsata_dir[2] = \"read\";\n\tsata_dir[4] = \"write\";\n\n\t/*\n\t * Some SATAC_* definitions from /usr/include/sys/sata/sata_defs.h, for\n\t * commands commonly issued.  More can be added from satacmds.d.\n\t */\n\tsata_cmd[0x20] = \"read sector\";\n\tsata_cmd[0x25] = \"read DMA extended\";\n\tsata_cmd[0x35] = \"write DMA extended\";\n\tsata_cmd[0x30] = \"write sector\";\n\tsata_cmd[0x40] = \"read verify\";\n\tsata_cmd[0x70] = \"seek\";\n\tsata_cmd[0x90] = \"diagnose command\";\n\tsata_cmd[0xb0] = \"SMART\";\n\tsata_cmd[0xec] = \"IDENTIFY DEVICE\";\n\tsata_cmd[0xe5] = \"check power mode\";\n\tsata_cmd[0xe7] = \"flush write-cache\";\n\tsata_cmd[0xef] = \"set features\";\n\n\t/*\n\t * These are SATA_PKT_* from /usr/include/sys/sata/sata_hba.h:\n\t */\n\tsata_reason[-1] = \"Not completed, busy\";\n\tsata_reason[0] = \"Success\";\n\tsata_reason[1] = \"Device reported error\";\n\tsata_reason[2] = \"Not accepted, queue full\";\n\tsata_reason[3] = \"Not completed, port error\";\n\tsata_reason[4] = \"Cmd unsupported\";\n\tsata_reason[5] = \"Aborted by request\";\n\tsata_reason[6] = \"Operation timeout\";\n\tsata_reason[7] = \"Aborted by reset request\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::sd_start_cmds:entry\n{\n\t/* see the sd_start_cmds() source to understand the following logic */\n\tself->bp = args[1] != NULL ? args[1] : args[0]->un_waitq_headp;\n}\n\nfbt::sd_start_cmds:return { self->bp = 0; }\n\nfbt::sata_hba_start:entry\n/self->bp->b_dip/\n{\n\tstatname[args[0]->txlt_sata_pkt] =\n\t    xlate <devinfo_t *>(self->bp)->dev_statname;\n}\n\nfbt::sata_pkt_free:entry\n/args[0]->txlt_sata_pkt->satapkt_cmd.satacmd_cmd_reg/\n{\n\tthis->sata_pkt = args[0]->txlt_sata_pkt;\n\tthis->devname = statname[this->sata_pkt] != NULL ?\n\t    statname[this->sata_pkt] : \"<?>\";\n\tthis->dir =\n\t    this->sata_pkt->satapkt_cmd.satacmd_flags.sata_data_direction;\n\tthis->dir_text = sata_dir[this->dir] != NULL ?\n\t    sata_dir[this->dir] : \"<none>\";\n\tthis->cmd = this->sata_pkt->satapkt_cmd.satacmd_cmd_reg;\n\tthis->cmd_text = sata_cmd[this->cmd] != NULL ?\n\t    sata_cmd[this->cmd] : lltostr(this->cmd);\n\tthis->reason = this->sata_pkt->satapkt_reason;\n\tthis->reason_text = sata_reason[this->reason] != NULL ?\n\t    sata_reason[this->reason] : lltostr(this->reason);\n\tstatname[this->sata_pkt] = 0;\n\n\t@[this->devname, this->dir_text, this->cmd_text, this->reason_text] =\n\t    count();\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-8s %-10s %-20s %25s  %s\\n\", \"DEVICE\", \"DIR\", \"COMMAND\",\n\t    \"REASON\", \"COUNT\");\n\tprinta(\"  %-8s %-10s %-20s %25s  %@d\\n\", @);\n}\n"
  },
  {
    "path": "Chap4/satarw.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * satarw.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\t/*\n\t * SATA_DIR of type 1 normally means no-data, but we can call it\n\t * sync-cache as that's the only type 1 we are tracing.\n\t */\n\tsata_dir[1] = \"sync-cache\";\n\tsata_dir[2] = \"read\";\n\tsata_dir[4] = \"write\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\n/* cache the I/O size while it is still easy to determine */\nfbt::sd_start_cmds:entry\n{\n\t/* see the sd_start_cmds() source to understand the following logic */\n\tthis->bp = args[1] != NULL ? args[1] : args[0]->un_waitq_headp;\n\tself->size = this->bp != NULL ? this->bp->b_bcount : 0;\n}\n\nfbt::sd_start_cmds:return { self->size = 0; }\n\n/* trace generic SATA driver functions for read, write and sync-cache */\nfbt::sata_txlt_read:entry,\nfbt::sata_txlt_write:entry,\nfbt::sata_txlt_synchronize_cache:entry\n{\n\tthis->sata_pkt = args[0]->txlt_sata_pkt;\n\tstart[(uint64_t)this->sata_pkt] = timestamp;\n\tsize[(uint64_t)this->sata_pkt] = self->size;\n}\n\n/* SATA command completed */\nfbt::sata_pkt_free:entry\n/start[(uint64_t)args[0]->txlt_sata_pkt]/\n{\n\tthis->sata_pkt = args[0]->txlt_sata_pkt;\n\tthis->delta = (timestamp - start[(uint64_t)this->sata_pkt]) / 1000;\n\tthis->size = size[(uint64_t)this->sata_pkt];\n\tthis->dir =\n\t    this->sata_pkt->satapkt_cmd.satacmd_flags.sata_data_direction;\n\tthis->dir_text = sata_dir[this->dir] != NULL ?\n\t    sata_dir[this->dir] : \"<none>\";\n\n\t@num[this->dir_text] = count();\n\t@avg_size[this->dir_text] = avg(this->size);\n\t@avg_time[this->dir_text] = avg(this->delta);\n\t@sum_size[this->dir_text] = sum(this->size);\n\t@sum_time[this->dir_text] = sum(this->delta);\n\t@plot_size[this->dir_text] = quantize(this->size);\n\t@plot_time[this->dir_text] = quantize(this->delta);\n\n\tstart[(uint64_t)this->sata_pkt] = 0;\n\tsize[(uint64_t)this->sata_pkt] = 0;\n}\n\ndtrace:::END\n{\n\tnormalize(@avg_size, 1024);\n\tnormalize(@sum_size, 1048576);\n\tnormalize(@sum_time, 1000);\n\tprintf(\"  %-10s  %10s  %10s %10s  %10s %12s\\n\", \"DIR\",\n\t    \"COUNT\", \"AVG(KB)\", \"TOTAL(MB)\", \"AVG(us)\", \"TOTAL(ms)\");\n\tprinta(\"  %-10s  %@10d  %@10d %@10d  %@10d %@12d\\n\", @num,\n\t    @avg_size, @sum_size, @avg_time, @sum_time);\n\tprintf(\"\\n\\nSATA I/O size (bytes):\\n\");\n\tprinta(@plot_size);\n\tprintf(\"\\nSATA I/O latency (us):\\n\");\n\tprinta(@plot_time);\n}\n"
  },
  {
    "path": "Chap4/scsicmds.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * scsicmds.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n#pragma D option quiet\nstring scsi_cmd[uchar_t];\ndtrace:::BEGIN\n{\n\t/*\n\t * The following was generated from the SCSI_CMDS_KEY_STRINGS\n\t * definitions in /usr/include/sys/scsi/generic/commands.h using sed.\n\t */\n\tscsi_cmd[0x00] = \"test_unit_ready\";\n\tscsi_cmd[0x01] = \"rezero/rewind\";\n\tscsi_cmd[0x03] = \"request_sense\";\n\tscsi_cmd[0x04] = \"format\";\n\tscsi_cmd[0x05] = \"read_block_limits\";\n\tscsi_cmd[0x07] = \"reassign\";\n\tscsi_cmd[0x08] = \"read\";\n\tscsi_cmd[0x0a] = \"write\";\n\tscsi_cmd[0x0b] = \"seek\";\n\tscsi_cmd[0x0f] = \"read_reverse\";\n\tscsi_cmd[0x10] = \"write_file_mark\";\n\tscsi_cmd[0x11] = \"space\";\n\tscsi_cmd[0x12] = \"inquiry\";\n\tscsi_cmd[0x13] = \"verify\";\n\tscsi_cmd[0x14] = \"recover_buffer_data\";\n\tscsi_cmd[0x15] = \"mode_select\";\n\tscsi_cmd[0x16] = \"reserve\";\n\tscsi_cmd[0x17] = \"release\";\n\tscsi_cmd[0x18] = \"copy\";\n\tscsi_cmd[0x19] = \"erase_tape\";\n\tscsi_cmd[0x1a] = \"mode_sense\";\n\tscsi_cmd[0x1b] = \"load/start/stop\";\n\tscsi_cmd[0x1c] = \"get_diagnostic_results\";\n\tscsi_cmd[0x1d] = \"send_diagnostic_command\";\n\tscsi_cmd[0x1e] = \"door_lock\";\n\tscsi_cmd[0x23] = \"read_format_capacity\";\n\tscsi_cmd[0x25] = \"read_capacity\";\n\tscsi_cmd[0x28] = \"read(10)\";\n\tscsi_cmd[0x2a] = \"write(10)\";\n\tscsi_cmd[0x2b] = \"seek(10)\";\n\tscsi_cmd[0x2e] = \"write_verify\";\n\tscsi_cmd[0x2f] = \"verify(10)\";\n\tscsi_cmd[0x30] = \"search_data_high\";\n\tscsi_cmd[0x31] = \"search_data_equal\";\n\tscsi_cmd[0x32] = \"search_data_low\";\n\tscsi_cmd[0x33] = \"set_limits\";\n\tscsi_cmd[0x34] = \"read_position\";\n\tscsi_cmd[0x35] = \"synchronize_cache\";\n\tscsi_cmd[0x37] = \"read_defect_data\";\n\tscsi_cmd[0x39] = \"compare\";\n\tscsi_cmd[0x3a] = \"copy_verify\";\n\tscsi_cmd[0x3b] = \"write_buffer\";\n\tscsi_cmd[0x3c] = \"read_buffer\";\n\tscsi_cmd[0x3e] = \"read_long\";\n\tscsi_cmd[0x3f] = \"write_long\";\n\tscsi_cmd[0x44] = \"report_densities/read_header\";\n\tscsi_cmd[0x4c] = \"log_select\";\n\tscsi_cmd[0x4d] = \"log_sense\";\n\tscsi_cmd[0x55] = \"mode_select(10)\";\n\tscsi_cmd[0x56] = \"reserve(10)\";\n\tscsi_cmd[0x57] = \"release(10)\";\n\tscsi_cmd[0x5a] = \"mode_sense(10)\";\n\tscsi_cmd[0x5e] = \"persistent_reserve_in\";\n\tscsi_cmd[0x5f] = \"persistent_reserve_out\";\n\tscsi_cmd[0x80] = \"write_file_mark(16)\";\n\tscsi_cmd[0x81] = \"read_reverse(16)\";\n\tscsi_cmd[0x83] = \"extended_copy\";\n\tscsi_cmd[0x88] = \"read(16)\";\n\tscsi_cmd[0x8a] = \"write(16)\";\n\tscsi_cmd[0x8c] = \"read_attribute\";\n\tscsi_cmd[0x8d] = \"write_attribute\";\n\tscsi_cmd[0x8f] = \"verify(16)\";\n\tscsi_cmd[0x91] = \"space(16)\";\n\tscsi_cmd[0x92] = \"locate(16)\";\n\tscsi_cmd[0x9e] = \"service_action_in(16)\";\n\tscsi_cmd[0x9f] = \"service_action_out(16)\";\n\tscsi_cmd[0xa0] = \"report_luns\";\n\tscsi_cmd[0xa2] = \"security_protocol_in\";\n\tscsi_cmd[0xa3] = \"maintenance_in\";\n\tscsi_cmd[0xa4] = \"maintenance_out\";\n\tscsi_cmd[0xa8] = \"read(12)\";\n\tscsi_cmd[0xa9] = \"service_action_out(12)\";\n\tscsi_cmd[0xaa] = \"write(12)\";\n\tscsi_cmd[0xab] = \"service_action_in(12)\";\n\tscsi_cmd[0xac] = \"get_performance\";\n\tscsi_cmd[0xAF] = \"verify(12)\";\n\tscsi_cmd[0xb5] = \"security_protocol_out\";\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\nfbt::scsi_transport:entry\n{\n\tthis->dev =\n\t    (struct dev_info *)args[0]->pkt_address.a_hba_tran->tran_hba_dip;\n\tthis->nodename = this->dev != NULL ?\n\t    stringof(this->dev->devi_node_name) : \"<unknown>\";\n\tthis->code = *args[0]->pkt_cdbp;\n\tthis->cmd = scsi_cmd[this->code] != NULL ?\n\t    scsi_cmd[this->code] : lltostr(this->code);\n\t@[this->nodename, this->cmd] = count();\n}\ndtrace:::END\n{\n\tprintf(\"  %-24s %-36s  %s\\n\", \"DEVICE NODE\", \"SCSI COMMAND\", \"COUNT\");\n\tprinta(\"  %-24s %-36s  %@d\\n\", @);\n}\n"
  },
  {
    "path": "Chap4/scsilatency.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * scsilatency.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nstring scsi_cmd[uchar_t];\n\ndtrace:::BEGIN\n{\n\t/* See /usr/include/sys/scsi/generic/commands.h for the full list. */\n\tscsi_cmd[0x00] = \"test_unit_ready\";\n\tscsi_cmd[0x08] = \"read\";\n\tscsi_cmd[0x0a] = \"write\";\n\tscsi_cmd[0x12] = \"inquiry\";\n\tscsi_cmd[0x17] = \"release\";\n\tscsi_cmd[0x1a] = \"mode_sense\";\n\tscsi_cmd[0x1b] = \"load/start/stop\";\n\tscsi_cmd[0x1c] = \"get_diagnostic_results\";\n\tscsi_cmd[0x1d] = \"send_diagnostic_command\";\n\tscsi_cmd[0x25] = \"read_capacity\";\n\tscsi_cmd[0x28] = \"read(10)\";\n\tscsi_cmd[0x2a] = \"write(10)\";\n\tscsi_cmd[0x35] = \"synchronize_cache\";\n\tscsi_cmd[0x4d] = \"log_sense\";\n\tscsi_cmd[0x5e] = \"persistent_reserve_in\";\n\tscsi_cmd[0xa0] = \"report_luns\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::scsi_transport:entry\n{\n\tstart[arg0] = timestamp;\n}\n\nfbt::scsi_destroy_pkt:entry\n/start[arg0]/\n{\n\tthis->delta = (timestamp - start[arg0]) / 1000;\n\tthis->code = *args[0]->pkt_cdbp;\n\tthis->cmd = scsi_cmd[this->code] != NULL ?\n\t    scsi_cmd[this->code] : lltostr(this->code);\n\tthis->reason = args[0]->pkt_reason == 0 ? \"Success\" :\n\t    strjoin(\"Fail:\", lltostr(args[0]->pkt_reason));\n\n\t@num[this->cmd, this->reason] = count();\n\t@average[this->cmd, this->reason] = avg(this->delta);\n\t@total[this->cmd, this->reason] = sum(this->delta);\n\n\tstart[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tnormalize(@total, 1000);\n\tprintf(\"\\n  %-26s %-12s %11s %11s %11s\\n\", \"SCSI COMMAND\",\n\t    \"COMPLETION\", \"COUNT\", \"AVG(us)\", \"TOTAL(ms)\");\n\tprinta(\"  %-26s %-12s %@11d %@11d %@11d\\n\", @num, @average, @total);\n}\n"
  },
  {
    "path": "Chap4/scsireasons.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * scsireasons.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\t/*\n\t * The following was generated from the CMD_* pkt_reason definitions\n\t * in /usr/include/sys/scsi/scsi_pkt.h using sed.\n\t */\n\tscsi_reason[0] = \"no transport errors- normal completion\";\n\tscsi_reason[1] = \"transport stopped with not normal state\";\n\tscsi_reason[2] = \"dma direction error occurred\";\n\tscsi_reason[3] = \"unspecified transport error\";\n\tscsi_reason[4] = \"Target completed hard reset sequence\";\n\tscsi_reason[5] = \"Command transport aborted on request\";\n\tscsi_reason[6] = \"Command timed out\";\n\tscsi_reason[7] = \"Data Overrun\";\n\tscsi_reason[8] = \"Command Overrun\";\n\tscsi_reason[9] = \"Status Overrun\";\n\tscsi_reason[10] = \"Message not Command Complete\";\n\tscsi_reason[11] = \"Target refused to go to Message Out phase\";\n\tscsi_reason[12] = \"Extended Identify message rejected\";\n\tscsi_reason[13] = \"Initiator Detected Error message rejected\";\n\tscsi_reason[14] = \"Abort message rejected\";\n\tscsi_reason[15] = \"Reject message rejected\";\n\tscsi_reason[16] = \"No Operation message rejected\";\n\tscsi_reason[17] = \"Message Parity Error message rejected\";\n\tscsi_reason[18] = \"Bus Device Reset message rejected\";\n\tscsi_reason[19] = \"Identify message rejected\";\n\tscsi_reason[20] = \"Unexpected Bus Free Phase occurred\";\n\tscsi_reason[21] = \"Target rejected our tag message\";\n\tscsi_reason[22] = \"Command transport terminated on request\";\n\tscsi_reason[24] = \"The device has been removed\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::scsi_init_pkt:entry\n/args[2] != NULL/\n{\n\tself->name = xlate <devinfo_t *>(args[2])->dev_statname;\n}\n\nfbt::scsi_init_pkt:return\n{\n\tpkt_name[arg1] = self->name;\n\tself->name = 0;\n}\n\nfbt::scsi_destroy_pkt:entry\n{\n\tthis->code = args[0]->pkt_reason;\n\tthis->reason = scsi_reason[this->code] != NULL ?\n\t    scsi_reason[this->code] : \"<unknown reason code>\";\n\t@all[this->reason] = count();\n}\n\nfbt::scsi_destroy_pkt:entry\n/this->code != 0/\n{\n\tthis->name = pkt_name[arg0] != NULL ? pkt_name[arg0] : \"<unknown>\";\n\t    @errors[pkt_name[arg0], this->reason] = count();\n}\n\nfbt::scsi_destroy_pkt:entry\n{\n\tpkt_name[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"\\nSCSI I/O completion reason summary:\\n\");\n\t    printa(@all);\n\tprintf(\"\\n\\nSCSI I/O reason errors by disk device and reason:\\n\\n\");\n\tprintf(\"  %-16s  %-44s %s\\n\", \"DEVICE\", \"ERROR REASON\", \"COUNT\");\n\tprinta(\"  %-16s  %-44s %@d\\n\", @errors);\n}\n"
  },
  {
    "path": "Chap4/scsirw.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * scsirw.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::sd_setup_rw_pkt:entry { self->in__sd_setup_rw_pkt = 1; }\nfbt::sd_setup_rw_pkt:return { self->in__sd_setup_rw_pkt = 0; }\n\nfbt::scsi_init_pkt:entry\n/self->in__sd_setup_rw_pkt/\n{\n\tself->buf = args[2];\n}\n\n/* Store start time and size for read and write commands */\nfbt::scsi_init_pkt:return\n/self->buf/\n{\n\tstart[arg1] = timestamp;\n\tsize[arg1] = self->buf->b_bcount;\n\tdir[arg1] = self->buf->b_flags & B_WRITE ? \"write\" : \"read\";\n\tself->buf = 0;\n}\n\nfbt::sd_send_scsi_SYNCHRONIZE_CACHE:entry { self->in__sync_cache = 1; }\nfbt::sd_send_scsi_SYNCHRONIZE_CACHE:return { self->in__sync_cache = 0; }\n\n/* Store start time for sync-cache commands */\nfbt::scsi_init_pkt:return\n/self->in__sync_cache/\n{\n\tstart[arg1] = timestamp;\n\tdir[arg1] = \"sync-cache\";\n}\n\n/* SCSI command completed */\nfbt::scsi_destroy_pkt:entry\n/start[arg0]/\n{\n\tthis->delta = (timestamp - start[arg0]) / 1000;\n\tthis->size = size[arg0];\n\tthis->dir = dir[arg0];\n\n\t@num[this->dir] = count();\n\t@avg_size[this->dir] = avg(this->size);\n\t@avg_time[this->dir] = avg(this->delta);\n\t@sum_size[this->dir] = sum(this->size);\n\t@sum_time[this->dir] = sum(this->delta);\n\t@plot_size[this->dir] = quantize(this->size);\n\t@plot_time[this->dir] = quantize(this->delta);\n\n\tstart[arg0] = 0;\n\tsize[arg0] = 0;\n\tdir[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tnormalize(@avg_size, 1024);\n\tnormalize(@sum_size, 1048576);\n\tnormalize(@sum_time, 1000);\n\tprintf(\"  %-10s  %10s  %10s %10s  %10s %12s\\n\", \"DIR\",\n\t    \"COUNT\", \"AVG(KB)\", \"TOTAL(MB)\", \"AVG(us)\", \"TOTAL(ms)\");\n\tprinta(\"  %-10s  %@10d  %@10d %@10d  %@10d %@12d\\n\", @num,\n\t    @avg_size, @sum_size, @avg_time, @sum_time);\n\tprintf(\"\\n\\nSCSI I/O size (bytes):\\n\");\n\tprinta(@plot_size);\n\tprintf(\"\\nSCSI I/O latency (us):\\n\");\n\tprinta(@plot_time);\n}\n"
  },
  {
    "path": "Chap4/sdqueue.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sdqueue.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::sd_add_buf_to_waitq:entry\n/args[1]->b_dip/\n{\n\tstart_time[arg1] = timestamp;\n}\n\nsdt:::scsi-transport-dispatch\n/this->start = start_time[arg0]/\n{\n\tthis->delta = (timestamp - this->start) / 1000;\n\tthis->bp = (buf_t *)arg0;\n\tthis->dev = xlate <devinfo_t *>(this->bp)->dev_statname;\n\tthis->path = xlate <devinfo_t *>(this->bp)->dev_pathname;\n\t@avg[this->dev, this->path] = avg(this->delta);\n\t@plot[this->dev, this->path] = lquantize(this->delta / 1000, 0, 1000,\n\t    100);\n\tstart_time[arg0] = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"Wait queue time by disk (ms):\\n\");\n\tprinta(\"\\n  %-12s %-50s\\n%@d\", @plot);\n\tprintf(\"\\n\\n  %-12s %-50s %12s\\n\", \"DEVICE\", \"PATH\", \"AVG_WAIT(us)\");\n\tprinta(\"  %-12s %-50s %@12d\\n\", @avg);\n}\n"
  },
  {
    "path": "Chap4/sdretry.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sdretry.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... output every 10 seconds.\\n\");\n}\n\nfbt::sd_set_retry_bp:entry\n{\n\t@[xlate <devinfo_t *>(args[1])->dev_statname,\n\t    xlate <devinfo_t *>(args[1])->dev_major,\n\t    xlate <devinfo_t *>(args[1])->dev_minor] = count();\n}\n\ntick-10sec\n{\n\tprintf(\"\\n%Y:\\n\", walltimestamp);\n\tprintf(\"%28s  %-3s,%-4s  %s\\n\", \"DEVICE\", \"MAJ\", \"MIN\", \"RETRIES\");\n\tprinta(\"%28s  %-03d,%-4d  %@d\\n\", @);\n\ttrunc(@);\n}\n"
  },
  {
    "path": "Chap4/seeksize.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * seeksize.d\n *\n * Example script from Chapter 4 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nself int last[dev_t];\n\nio:::start\n/self->last[args[0]->b_edev] != 0/\n{\n\tthis->last = self->last[args[0]->b_edev];\n\tthis->dist = (int)(args[0]->b_blkno - this->last) > 0 ?\n\t    args[0]->b_blkno - this->last : this->last - args[0]->b_blkno;\n\t@Size[pid, curpsinfo->pr_psargs] = quantize(this->dist);\n}\n\nio:::start\n{\n\tself->last[args[0]->b_edev] = args[0]->b_blkno +\n\t    args[0]->b_bcount / 512;\n}\n\ndtrace:::END\n{\n\tprintf(\"\\n%8s  %s\\n\", \"PID\", \"CMD\");\n\tprinta(\"%8d  %S\\n%@d\\n\", @Size);\n}\n"
  },
  {
    "path": "Chap5/cdrom.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * cdrom.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing hsfs (cdrom) mountfs...\\n\");\n}\n\nfbt::hs_mountfs:entry\n{\n\tprintf(\"%Y:  Mounting %s... \", walltimestamp, stringof(arg2));\n\tself->start = timestamp;\n}\n\nfbt::hs_mountfs:return\n/self->start/\n{\n\tthis->time = (timestamp - self->start) / 1000000;\n\tprintf(\"result: %d%s, time: %d ms\\n\", arg1,\n\t    arg1 ? \"\" : \" (SUCCESS)\", this->time);\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap5/dnlcps.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * dnlcps.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::dnlc_lookup:return\n{\n\tthis->code = arg1 == 0 ? 0 : 1;\n\t@Result[execname, pid] = lquantize(this->code, 0, 1, 1);\n}\n\ndtrace:::END\n{\n\tprinta(\" CMD: %-16s PID: %d\\n%@d\\n\", @Result);\n}\n"
  },
  {
    "path": "Chap5/dvd.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * dvd.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing udfs (dvd) mountfs...\\n\");\n}\n\nfbt::ud_mountfs:entry\n{\n\tprintf(\"%Y:  Mounting %s... \", walltimestamp, stringof(arg2));\n\tself->start = timestamp;\n}\n\nfbt::ud_mountfs:return\n/self->start/\n{\n\tthis->time = (timestamp - self->start) / 1000000;\n\tprintf(\"result: %d%s, time: %d ms\\n\", arg1,\n\t    arg1 ? \"\" : \" (SUCCESS)\", this->time);\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap5/fserrors.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * fserrors.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing syscall errors... Hit Ctrl-C to end.\\n\");\n}\n\nsyscall::read*:entry,\nsyscall::write*:entry\n{ self->fd = arg0; }\n\nsyscall::open*:entry,\nsyscall::stat*:entry\n{ self->ptr = arg0; }\n\nsyscall::read*:return,\nsyscall::write*:return\n/(int)arg0 < 0 && self->fd > 2/\n{\n\tself->path = fds[self->fd].fi_pathname;\n}\n\nsyscall::open*:return,\nsyscall::stat*:return\n/(int)arg0 < 0 && self->ptr/\n{\n\tself->path = copyinstr(self->ptr);\n}\n\nsyscall::read*:return,\nsyscall::write*:return,\nsyscall::open*:return,\nsyscall::stat*:return\n/(int)arg0 < 0 && self->path != NULL/\n{\n\t@[execname, probefunc, errno, self->path] = count();\n\tself->path = 0;\n}\n\nsyscall::read*:return,\nsyscall::write*:return\n{ self->fd = 0; }\n\nsyscall::open*:return,\nsyscall::stat*:return\n{ self->ptr = 0; }\n\ndtrace:::END\n{\n\tprintf(\"%16s %16s %3s %8s %s\\n\", \"PROCESSES\", \"SYSCALL\", \"ERR\",\n\t    \"COUNT\", \"PATH\");\n\tprinta(\"%16s %16s %3d %@8d %s\\n\", @);\n}\n"
  },
  {
    "path": "Chap5/fsflush.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * fsflush.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nBEGIN\n{\n\tlexam = 0; lscan = 0; llock = 0; lmod = 0; lcoal = 0; lrel = 0;\n\tltime = 0;\n\tprintf(\"%10s %10s %10s %10s %10s %10s %10s\\n\", \"SCANNED\", \"EXAMINED\",\n\t    \"LOCKED\", \"MODIFIED\", \"COALESCE\", \"RELEASES\", \"TIME(ns)\");\n}\n\ntick-1s\n/lexam/\n{\n\tprintf(\"%10d %10d %10d %10d %10d %10d %10d\\n\", `fsf_total.fsf_scan,\n\t    `fsf_total.fsf_examined - lexam, `fsf_total.fsf_locked - llock,\n\t    `fsf_total.fsf_modified - lmod, `fsf_total.fsf_coalesce - lcoal,\n\t    `fsf_total.fsf_releases - lrel, `fsf_total.fsf_time - ltime);\n\tlexam = `fsf_total.fsf_examined;\n\tlscan = `fsf_total.fsf_scan;\n\tllock = `fsf_total.fsf_locked;\n\tlmod = `fsf_total.fsf_modified;\n\tlcoal = `fsf_total.fsf_coalesce;\n\tlrel = `fsf_total.fsf_releases;\n\tltime = `fsf_total.fsf_time;\n}\n\n/*\n * First time through\n */\n\ntick-1s\n/!lexam/\n{\n\tlexam = `fsf_total.fsf_examined;\n\tlscan = `fsf_total.fsf_scan;\n\tllock = `fsf_total.fsf_locked;\n\tlmod = `fsf_total.fsf_modified;\n\tlcoal = `fsf_total.fsf_coalesce;\n\tltime = `fsf_total.fsf_time;\n\tlrel = `fsf_total.fsf_releases;\n}\n"
  },
  {
    "path": "Chap5/fsflush_cpu.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * fsflush_cpu.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing fsflush...\\n\");\n\t@fopbytes = sum(0); @iobytes = sum(0);\n}\n\nfbt::fsflush_do_pages:entry\n{\n\tself->vstart = vtimestamp;\n}\n\nfbt::fop_putpage:entry\n/self->vstart/\n{\n\t@fopbytes = sum(arg2);\n}\n\nio:::start\n/self->vstart/\n{\n\t@iobytes = sum(args[0]->b_bcount);\n\t@ionum = count();\n}\n\nfbt::fsflush_do_pages:return\n/self->vstart/\n{\n\tnormalize(@fopbytes, 1024);\n\tnormalize(@iobytes, 1024);\n\tthis->delta = (vtimestamp - self->vstart) / 1000000;\n\tprintf(\"%Y %4d ms, \", walltimestamp, this->delta);\n\tprinta(\"fop: %7@d KB, \", @fopbytes);\n\tprinta(\"device: %7@d KB \", @iobytes);\n\tprinta(\"%5@d I/O\", @ionum);\n\tprintf(\"\\n\");\n\tself->vstart = 0;\n\tclear(@fopbytes); clear(@iobytes); clear(@ionum);\n}\n"
  },
  {
    "path": "Chap5/fsrtpk.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * fsrtpk.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n/* trace read() variants, but not readlink() or __pthread*() (macosx) */\nsyscall::read:entry,\nsyscall::readv:entry,\nsyscall::pread*:entry,\nsyscall::*read*nocancel:entry\n{\n\tself->fd = arg0;\n\tself->start = timestamp;\n}\n\nsyscall::*read*:return\n/self->start && arg0 > 0/\n{\n\tthis->kb = (arg1 / 1024) ? arg1 / 1024 : 1;\n\tthis->ns_per_kb = (timestamp - self->start) / this->kb;\n\t@[fds[self->fd].fi_fs, probefunc, fds[self->fd].fi_mount] =\n\t    quantize(this->ns_per_kb);\n}\n\nsyscall::*read*:return\n{\n\tself->fd = 0; self->start = 0;\n}\n\ndtrace:::END\n{\n\tprinta(\"\\n  %s %s (ns per kb) \\t%s%@d\", @);\n}\n"
  },
  {
    "path": "Chap5/fsrwcount.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * fsrwcount.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\n/* trace read() variants, but not readlink() or __pthread*() (macosx) */\nsyscall::read:entry,\nsyscall::readv:entry,\nsyscall::pread*:entry,\nsyscall::*read*nocancel:entry,\nsyscall::*write*:entry\n{\n\t@[fds[arg0].fi_fs, probefunc, fds[arg0].fi_mount] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-9s  %-16s %-40s %7s\\n\", \"FS\", \"SYSCALL\", \"MOUNTPOINT\",\n\t    \"COUNT\");\n\tprinta(\"  %-9.9s  %-16s %-40s %@7d\\n\", @);\n}\n"
  },
  {
    "path": "Chap5/fsrwtime.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * fsrwtime.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n/* trace read() variants, but not readlink() or __pthread*() (macosx) */\nsyscall::read:entry,\nsyscall::readv:entry,\nsyscall::pread*:entry,\nsyscall::*read*nocancel:entry,\nsyscall::*write*:entry\n{\n\tself->fd = arg0;\n\tself->start = timestamp;\n}\n\nsyscall::*read*:return,\nsyscall::*write*:return\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\t@[fds[self->fd].fi_fs, probefunc, fds[self->fd].fi_mount] =\n\t    quantize(this->delta);\n\tself->fd = 0; self->start = 0;\n}\n\ndtrace:::END\n{\n\tprinta(\"\\n  %s %s (us) \\t%s%@d\", @);\n}\n"
  },
  {
    "path": "Chap5/fssnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * fssnoop.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %-6s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"BYTES\", \"PATH\");\n}\n\nfsinfo:::\n/execname != \"dtrace\" && ($$1 == NULL || $$1 == execname)/\n{\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %-6d %s\\n\", timestamp / 1000000,\n\t    uid, pid, execname, probename, arg1, args[0]->fi_pathname);\n}\n"
  },
  {
    "path": "Chap5/fswho.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * fswho.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nfsinfo:::read,\nfsinfo:::write\n{\n\t@[execname, probename == \"read\" ? \"R\" : \"W\", args[0]->fi_fs,\n\t    args[0]->fi_mount] = sum(arg1);\n}\n\ndtrace:::END\n{\n\tnormalize(@, 1024);\n\tprintf(\"  %-16s  %1s %12s  %-10s %s\\n\", \"PROCESSES\", \"D\", \"KBYTES\",\n\t    \"FS\", \"MOUNTPOINT\");\n\tprinta(\"  %-16s  %1.1s %@12d  %-10s %s\\n\", @);\n}\n"
  },
  {
    "path": "Chap5/hfsfileread.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * hfsfileread.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing HFS+ file reads... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::hfs_vnop_read:entry\n{\n\tthis->read = (struct vnop_read_args *)arg0;\n\tthis->path = this->read->a_vp->v_name;\n\tthis->bytes = this->read->a_uio->uio_resid_64;\n\t@r[this->path ? stringof(this->path) : \"<null>\"] = sum(this->bytes);\n}\n\nfbt::hfs_vnop_strategy:entry\n/((struct vnop_strategy_args *)arg0)->a_bp->b_flags & B_READ/\n{\n\tthis->strategy = (struct vnop_strategy_args *)arg0;\n\tthis->path = this->strategy->a_bp->b_vp->v_name;\n\tthis->bytes = this->strategy->a_bp->b_bcount;\n\t@s[this->path ? stringof(this->path) : \"<null>\"] = sum(this->bytes);\n}\n\ndtrace:::END\n{\n\tprintf(\" %-56s %10s %10s\\n\", \"FILE\", \"READ(B)\", \"DISK(B)\");\n\tprinta(\" %-56s %@10d %@10d\\n\", @r, @s);\n}\n"
  },
  {
    "path": "Chap5/hfsslower.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * hfsslower.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %-16s %1s %4s %6s %s\\n\", \"TIME\", \"PROCESS\",\n\t    \"D\", \"KB\", \"ms\", \"FILE\");\n\tmin_ns = $1 * 1000000;\n}\n\n/* see bsd/hfs/hfs_vnops.c */\n\nfbt::hfs_vnop_read:entry\n{\n\tthis->read = (struct vnop_read_args *)arg0;\n\tself->path = this->read->a_vp->v_name;\n\tself->kb = this->read->a_uio->uio_resid_64 / 1024;\n\tself->start = timestamp;\n}\n\nfbt::hfs_vnop_write:entry\n{\n\tthis->write = (struct vnop_write_args *)arg0;\n\tself->path = this->write->a_vp->v_name;\n\tself->kb = this->write->a_uio->uio_resid_64 / 1024;\n\tself->start = timestamp;\n}\n\nfbt::hfs_vnop_read:return,\nfbt::hfs_vnop_write:return\n/self->start && (timestamp - self->start) >= min_ns/\n{\n\tthis->iotime = (timestamp - self->start) / 1000000;\n\tthis->dir = probefunc == \"hfs_vnop_read\" ? \"R\" : \"W\";\n\tprintf(\"%-20Y %-16s %1s %4d %6d %s\\n\", walltimestamp,\n\t    execname, this->dir, self->kb, this->iotime,\n\tself->path != NULL ? stringof(self->path) : \"<null>\");\n}\n\nfbt::hfs_vnop_read:return,\nfbt::hfs_vnop_write:return\n{\n\tself->path = 0; self->kb = 0; self->start = 0;\n}\n"
  },
  {
    "path": "Chap5/hfssnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * hfssnoop.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-14s %-4s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"KB\", \"FILE\");\n}\n\n/* see bsd/hfs/hfs_vnops.c */\n\nfbt::hfs_vnop_read:entry\n{\n\tthis->read = (struct vnop_read_args *)arg0;\n\tself->path = this->read->a_vp->v_name;\n\tself->kb = this->read->a_uio->uio_resid_64 / 1024;\n}\n\nfbt::hfs_vnop_write:entry\n{\n\tthis->write = (struct vnop_write_args *)arg0;\n\tself->path = this->write->a_vp->v_name;\n\tself->kb = this->write->a_uio->uio_resid_64 / 1024;\n}\n\nfbt::hfs_vnop_read:entry, fbt::hfs_vnop_write:entry\n{\n\tprintf(\"%-12d %6d %6d %-12.12s %-14s %-4d %s\\n\", timestamp / 1000000,\n\t    uid, pid, execname, probefunc, self->kb,\n\t    self->path != NULL ? stringof(self->path) : \"<null>\");\n\tself->path = 0; self->kb = 0;\n}\n"
  },
  {
    "path": "Chap5/maclife.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * maclife.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"DIR/FILE\");\n}\n\n/* see sys/bsd/sys/vnode_if.h */\n\nfbt::VNOP_CREATE:entry,\nfbt::VNOP_REMOVE:entry\n{\n\tthis->path = ((struct vnode *)arg0)->v_name;\n\tthis->name = ((struct componentname *)arg2)->cn_nameptr;\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %s/%s\\n\",\n\t    timestamp / 1000000, uid, pid, execname, probefunc,\n\t    this->path != NULL ? stringof(this->path) : \"<null>\",\n\t    stringof(this->name));\n}\n"
  },
  {
    "path": "Chap5/macvfssnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * macvfssnoop.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %-4s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"KB\", \"PATH\");\n}\n\n/* see sys/bsd/sys/vnode_if.h */\n\nfbt::VNOP_READ:entry, fbt::VNOP_WRITE:entry\n{\n\tself->path = ((struct vnode *)arg0)->v_name;\n\tself->kb = ((struct uio *)arg1)->uio_resid_64 / 1024;\n}\n\nfbt::VNOP_OPEN:entry\n{\n\tself->path = ((struct vnode *)arg0)->v_name;\n\tself->kb = 0;\n}\n\nfbt::VNOP_CLOSE:entry, fbt::VNOP_IOCTL:entry, fbt::VNOP_GETATTR:entry,\nfbt::VNOP_READDIR:entry\n{\n\tself->path = ((struct vnode *)arg0)->v_name;\n\tself->kb = 0;\n}\n\nfbt::VNOP_READ:entry, fbt::VNOP_WRITE:entry, fbt::VNOP_OPEN:entry,\nfbt::VNOP_CLOSE:entry, fbt::VNOP_IOCTL:entry, fbt::VNOP_GETATTR:entry,\nfbt::VNOP_READDIR:entry\n/execname != \"dtrace\" && ($$1 == NULL || $$1 == execname)/\n{\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %-4d %s\\n\", timestamp / 1000000,\n\tuid, pid, execname, probefunc, self->kb,\n\tself->path != NULL ? stringof(self->path) : \"<null>\");\n}\n\nfbt::VNOP_READ:entry, fbt::VNOP_WRITE:entry, fbt::VNOP_OPEN:entry,\nfbt::VNOP_CLOSE:entry, fbt::VNOP_IOCTL:entry, fbt::VNOP_GETATTR:entry,\nfbt::VNOP_READDIR:entry\n{\n\tself->path = 0; self->kb = 0;\n}\n"
  },
  {
    "path": "Chap5/mmap.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * mmap.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#include <sys/mman.h>\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%6s %-12s %-4s %-8s %-8s %-8s %s\\n\", \"PID\",\n\t    \"PROCESS\", \"PROT\", \"FLAGS\", \"OFFS(KB)\", \"SIZE(KB)\", \"PATH\");\n}\n\nsyscall::mmap*:entry\n/fds[arg4].fi_pathname != \"<none>\"/\n{\n\t/* see mmap(2) and /usr/include/sys/mman.h */\n\tprintf(\"%6d %-12.12s %s%s%s  %s%s%s%s%s%s%s%s %-8d %-8d %s\\n\",\n\t    pid, execname,\n\t    arg2 & PROT_EXEC  ? \"E\" : \"-\",\t/* pages can be executed */\n\t    arg2 & PROT_WRITE ? \"W\" : \"-\",\t/* pages can be written */\n\t    arg2 & PROT_READ  ? \"R\" : \"-\",\t/* pages can be read */\n\t    arg3 & MAP_INITDATA  ? \"I\" : \"-\",\t/* map data segment */\n\t    arg3 & MAP_TEXT      ? \"T\" : \"-\",\t/* map code segment */\n\t    arg3 & MAP_ALIGN     ? \"L\" : \"-\",\t/* addr specifies alignment */\n\t    arg3 & MAP_ANON      ? \"A\" : \"-\",\t/* map anon pages directly */\n\t    arg3 & MAP_NORESERVE ? \"N\" : \"-\",\t/* don't reserve swap area */\n\t    arg3 & MAP_FIXED     ? \"F\" : \"-\",\t/* user assigns address */\n\t    arg3 & MAP_PRIVATE   ? \"P\" : \"-\",\t/* changes are private */\n\t    arg3 & MAP_SHARED    ? \"S\" : \"-\",\t/* share changes */\n\t    arg5 / 1024, arg1 / 1024, fds[arg4].fi_pathname);\n}\n"
  },
  {
    "path": "Chap5/nfs3fileread.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfs3fileread.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing NFSv3 client file reads... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::nfs3_read:entry\n{\n\tthis->path = args[0]->v_path;\n\tthis->bytes = args[1]->uio_resid;\n\t@r[this->path ? stringof(this->path) : \"<null>\"] = sum(this->bytes);\n}\n\nfbt::nfs3_directio_read:entry\n{\n\tthis->path = args[0]->v_path;\n\tthis->bytes = args[1]->uio_resid;\n\t@n[this->path ? stringof(this->path) : \"<null>\"] = sum(this->bytes);\n}\n\nfbt::nfs3_getpage:entry\n{\n\tthis->path = args[0]->v_path;\n\tthis->bytes = arg2;\n\t@n[this->path ? stringof(this->path) : \"<null>\"] = sum(this->bytes);\n}\n\ndtrace:::END\n{\n\tprintf(\" %-56s %10s %10s\\n\", \"FILE\", \"READ(B)\", \"NET(B)\");\n\tprinta(\" %-56s %@10d %@10d\\n\", @r, @n);\n}\n"
  },
  {
    "path": "Chap5/nfs3sizes.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfs3sizes.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing NFSv3 client file reads... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::nfs3_read:entry\n{\n\t@q[\"NFS read size (bytes)\"] = quantize(args[1]->uio_resid);\n\t@s[\"NFS read (bytes)\"] = sum(args[1]->uio_resid);\n}\n\nfbt::nfs3_directio_read:entry\n{\n\t@q[\"NFS network read size (bytes)\"] = quantize(args[1]->uio_resid);\n\t@s[\"NFS network read (bytes)\"] = sum(args[1]->uio_resid);\n}\n\nfbt::nfs3_getpage:entry\n{\n\t@q[\"NFS network read size (bytes)\"] = quantize(arg2);\n\t@s[\"NFS network read (bytes)\"] = sum(arg2);\n}\n"
  },
  {
    "path": "Chap5/nfswizard.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfswizard.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n\tscriptstart = walltimestamp;\n\ttimestart = timestamp;\n}\n\nio:nfs::start\n{\n\t/* tally file sizes */\n\t@file[args[2]->fi_pathname] = sum(args[0]->b_bcount);\n\n\t/* time response */\n\tstart[args[0]->b_addr] = timestamp;\n\n\t/* overall stats */\n\t@rbytes = sum(args[0]->b_flags & B_READ ? args[0]->b_bcount : 0);\n\t@wbytes = sum(args[0]->b_flags & B_READ ? 0 : args[0]->b_bcount);\n\t@events = count();\n}\n\nio:nfs::done\n/start[args[0]->b_addr]/\n{\n\t/* calculate and save response time stats */\n\tthis->elapsed = timestamp - start[args[0]->b_addr];\n\t@maxtime = max(this->elapsed);\n\t@avgtime = avg(this->elapsed);\n\t@qnztime = quantize(this->elapsed / 1000);\n}\n\ndtrace:::END\n{\n\t/* print header */\n\tprintf(\"NFS Client Wizard. %Y -> %Y\\n\\n\", scriptstart, walltimestamp);\n\n\t/* print read/write stats */\n\tprinta(\"Read:  %@d bytes \", @rbytes);\n\tnormalize(@rbytes, 1000000);\n\tprinta(\"(%@d Mb)\\n\", @rbytes);\n\tprinta(\"Write: %@d bytes \", @wbytes);\n\tnormalize(@wbytes, 1000000);\n\tprinta(\"(%@d Mb)\\n\\n\", @wbytes);\n\n\t/* print throughput stats */\n\tdenormalize(@rbytes);\n\tnormalize(@rbytes, (timestamp - timestart) / 1000000);\n\tprinta(\"Read:  %@d Kb/sec\\n\", @rbytes);\n\tdenormalize(@wbytes);\n\tnormalize(@wbytes, (timestamp - timestart) / 1000000);\n\tprinta(\"Write: %@d Kb/sec\\n\\n\", @wbytes);\n\n\t/* print time stats */\n\tprinta(\"NFS I/O events:    %@d\\n\", @events);\n\tnormalize(@avgtime, 1000000);\n\tprinta(\"Avg response time: %@d ms\\n\", @avgtime);\n\tnormalize(@maxtime, 1000000);\n\tprinta(\"Max response time: %@d ms\\n\\n\", @maxtime);\n\tprinta(\"Response times (us):%@d\\n\", @qnztime);\n\n\t/* print file stats */\n\tprintf(\"Top 25 files accessed (bytes):\\n\");\n\tprintf(\"   %-64s %s\\n\", \"PATHNAME\", \"BYTES\");\n\ttrunc(@file, 25);\n\tprinta(\"   %-64s %@d\\n\", @file);\n}\n"
  },
  {
    "path": "Chap5/pcfsrw.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * pcfsrw.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %1s %4s %6s %3s %s\\n\", \"TIME\", \"D\", \"KB\",\n\t    \"ms\", \"ERR\", \"PATH\");\n}\n\nfbt::pcfs_read:entry,\nfbt::pcfs_write:entry,\nfbt::pcfs_readdir:entry\n{\n\tself->path = args[0]->v_path;\n\tself->kb = args[1]->uio_resid / 1024;\n\tself->start = timestamp;\n}\n\nfbt::pcfs_read:return,\nfbt::pcfs_write:return,\nfbt::pcfs_readdir:return\n/self->start/\n{\n\tthis->iotime = (timestamp - self->start) / 1000000;\n\tthis->dir = probefunc == \"pcfs_read\" ? \"R\" : \"W\";\n\tprintf(\"%-20Y %1s %4d %6d %3d %s\\n\", walltimestamp,\n\t    this->dir, self->kb, this->iotime, arg1,\n\t    self->path != NULL ? stringof(self->path) : \"<null>\");\n\tself->start = 0; self->path = 0; self->kb = 0;\n}\n"
  },
  {
    "path": "Chap5/perturbation.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * perturbation.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing ZFS perturbation by %s()... Ctrl-C to end.\\n\", $$1);\n}\n\nfbt::$$1:entry\n{\n\tself->pstart = timestamp;\n\tperturbation = 1;\n}\n\nfbt::$$1:return\n/self->pstart/\n{\n\tthis->ptime = (timestamp - self->pstart) / 1000000;\n\t@[probefunc, \"perturbation duration (ms)\"] = quantize(this->ptime);\n\tperturbation = 0;\n}\n\nfbt::zfs_read:entry,\nfbt::zfs_write:entry\n{\n\tself->start = timestamp;\n}\n\nfbt::zfs_read:return,\nfbt::zfs_write:return\n/self->start/\n{\n\tthis->iotime = (timestamp - self->start) / 1000000;\n\t@[probefunc, perturbation ? \"during perturbation (ms)\" :\n\t    \"normal (ms)\"] = quantize(this->iotime);\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap5/readtype.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * readtype.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ninline int TOP = 20;\nself int trace;\nuint64_t lbytes;\nuint64_t pbytes;\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing... Output every 5 secs, or Ctrl-C.\\n\");\n}\n\nfsinfo:::read\n{\n\t@io[args[0]->fi_mount, \"logical\"] = count();\n\t@bytes[args[0]->fi_mount, \"logical\"] = sum(arg1);\n\tlbytes += arg1;\n}\n\nio:::start\n/args[0]->b_flags & B_READ/\n{\n\t@io[args[2]->fi_mount, \"physical\"] = count();\n\t@bytes[args[2]->fi_mount, \"physical\"] = sum(args[0]->b_bcount);\n\tpbytes += args[0]->b_bcount;\n}\n\nprofile:::tick-5s,\ndtrace:::END\n{\n\ttrunc(@io, TOP);\n\ttrunc(@bytes, TOP);\n\tprintf(\"\\n%Y:\\n\", walltimestamp);\n\tprintf(\"\\n Read I/O (top %d)\\n\", TOP);\n\tprinta(\" %-32s %10s %10@d\\n\", @io);\n\tprintf(\"\\n Read Bytes (top %d)\\n\", TOP);\n\tprinta(\" %-32s %10s %10@d\\n\", @bytes);\n\tprintf(\"\\nphysical/logical bytes rate: %d%%\\n\",\n\t    lbytes ? 100 * pbytes / lbytes : 0);\n\ttrunc(@bytes);\n\ttrunc(@io);\n\tlbytes = pbytes = 0;\n}\n"
  },
  {
    "path": "Chap5/sollife.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sollife.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"PATH\");\n}\n\n/* see /usr/include/sys/vnode.h */\n\nfbt::fop_create:entry,\nfbt::fop_remove:entry\n{\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %s/%s\\n\",\n\t    timestamp / 1000000, uid, pid, execname, probefunc,\n\t    args[0]->v_path != NULL ? stringof(args[0]->v_path) : \"<null>\",\n\t    stringof(arg1));\n}\n"
  },
  {
    "path": "Chap5/solvfssnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * solvfssnoop.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %-4s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"KB\", \"PATH\");\n}\n\n/* see /usr/include/sys/vnode.h */\n\nfbt::fop_read:entry, fbt::fop_write:entry\n{\n\tself->path = args[0]->v_path;\n\tself->kb = args[1]->uio_resid / 1024;\n}\n\nfbt::fop_open:entry\n{\n\tself->path = (*args[0])->v_path;\n\tself->kb = 0;\n}\n\nfbt::fop_close:entry, fbt::fop_ioctl:entry, fbt::fop_getattr:entry,\nfbt::fop_readdir:entry\n{\n\tself->path = args[0]->v_path;\n\tself->kb = 0;\n}\n\nfbt::fop_read:entry, fbt::fop_write:entry, fbt::fop_open:entry,\nfbt::fop_close:entry, fbt::fop_ioctl:entry, fbt::fop_getattr:entry,\nfbt::fop_readdir:entry\n/execname != \"dtrace\" && ($$1 == NULL || $$1 == execname)/\n{\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %-4d %s\\n\", timestamp / 1000000,\n\t    uid, pid, execname, probefunc, self->kb,\n\t    self->path != NULL ? stringof(self->path) : \"<null>\");\n}\n\nfbt::fop_read:entry, fbt::fop_write:entry, fbt::fop_open:entry,\nfbt::fop_close:entry, fbt::fop_ioctl:entry, fbt::fop_getattr:entry,\nfbt::fop_readdir:entry\n{\n\tself->path = 0; self->kb = 0;\n}\n"
  },
  {
    "path": "Chap5/spasync.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * spasync.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ninline int MIN_MS = 1;\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing ZFS spa_sync() slower than %d ms...\\n\", MIN_MS);\n\t@bytes = sum(0);\n}\n\nfbt::spa_sync:entry\n/!self->start/\n{\n\tin_spa_sync = 1;\n\tself->start = timestamp;\n\tself->spa = args[0];\n}\n\nio:::start\n/in_spa_sync/\n{\n\t@io = count();\n\t@bytes = sum(args[0]->b_bcount);\n}\n\nfbt::spa_sync:return\n/self->start && (this->ms = (timestamp - self->start) / 1000000) > MIN_MS/\n{\n\tnormalize(@bytes, 1048576);\n\tprintf(\"%-20Y %-10s %6d ms, \", walltimestamp,\n\t    stringof(self->spa->spa_name), this->ms);\n\tprinta(\"%@d MB %@d I/O\\n\", @bytes, @io);\n}\n\nfbt::spa_sync:return\n{\n\tself->start = 0; self->spa = 0; in_spa_sync = 0;\n\tclear(@bytes); clear(@io);\n}\n"
  },
  {
    "path": "Chap5/sysfs.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * sysfs.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\n/* trace read() variants, but not readlink() or __pthread*() (macosx) */\nsyscall::read:entry,\nsyscall::readv:entry,\nsyscall::pread*:entry,\nsyscall::*read*nocancel:entry,\nsyscall::*write*:entry\n{\n\t@[execname, probefunc, fds[arg0].fi_mount] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-16s %-16s %-30s %7s\\n\", \"PROCESS\", \"SYSCALL\",\n\t    \"MOUNTPOINT\", \"COUNT\");\n\tprinta(\"  %-16s %-16s %-30s %@7d\\n\", @);\n}\n"
  },
  {
    "path": "Chap5/tmpgetpage.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tmpgetpage.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing tmpfs disk read time (us):\\n\");\n}\n\nfbt::tmp_getpage:entry\n{\n\tself->vp = args[0];\n\tself->start = timestamp;\n}\n\nfbt::tmp_getpage:return\n/self->start/\n{\n\t@[execname, stringof(self->vp->v_path)] =\n\t    quantize((timestamp - self->start) / 1000);\n\tself->vp = 0;\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap5/tmpusers.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tmpusers.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"%6s %6s %-16s %s\\n\", \"UID\", \"PID\", \"PROCESS\", \"FILE\");\n}\n\nfbt::tmp_open:entry\n{\n\tprintf(\"%6d %6d %-16s %s\\n\", uid, pid, execname,\n\t    stringof((*args[0])->v_path));\n}\n"
  },
  {
    "path": "Chap5/ufsimiss.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ufsimiss.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%6s %-16s %s\\n\", \"PID\", \"PROCESS\", \"INODE MISS PATH\");\n}\n\nfbt::ufs_lookup:entry\n{\n\tself->dvp = args[0];\n\tself->name = arg1;\n}\n\nfbt::ufs_lookup:return\n{\n\tself->dvp = 0;\n\tself->name = 0;\n}\n\nfbt::ufs_alloc_inode:entry\n/self->dvp && self->name/\n{\n\tprintf(\"%6d %-16s %s/%s\\n\", pid, execname,\n\t    stringof(self->dvp->v_path), stringof(self->name));\n}\n"
  },
  {
    "path": "Chap5/ufsreadahead.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ufsreadahead.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nfbt::ufs_getpage:entry\n{\n\t@[\"UFS read (bytes)\"] = sum(arg2);\n}\n\nfbt::ufs_getpage_ra:return\n{\n\t@[\"UFS read ahead (bytes)\"] = sum(arg1);\n}\n"
  },
  {
    "path": "Chap5/ufssnoop.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * ufssnoop.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %-4s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"KB\", \"PATH\");\n}\n\n/* see uts/common/fs/ufs/ufs_vnops.c */\n\nfbt::ufs_read:entry, fbt::ufs_write:entry\n{\n\tself->path = args[0]->v_path;\n\tself->kb = args[1]->uio_resid / 1024;\n}\n\nfbt::ufs_open:entry\n{\n\tself->path = (*(struct vnode **)arg0)->v_path;\n\tself->kb = 0;\n}\n\nfbt::ufs_close:entry, fbt::ufs_ioctl:entry, fbt::ufs_getattr:entry,\nfbt::ufs_readdir:entry\n{\n\tself->path = args[0]->v_path;\n\tself->kb = 0;\n}\n\nfbt::ufs_read:entry, fbt::ufs_write:entry, fbt::ufs_open:entry,\nfbt::ufs_close:entry, fbt::ufs_ioctl:entry, fbt::ufs_getattr:entry,\nfbt::ufs_readdir:entry\n{\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %-4d %s\\n\", timestamp / 1000000,\n\t    uid, pid, execname, probefunc, self->kb,\n\tself->path != NULL ? stringof(self->path) : \"<null>\");\n\tself->path = 0; self->kb = 0;\n}\n"
  },
  {
    "path": "Chap5/vfslife.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * vfslife.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"DIR/FILE\");\n}\n\n/* see sys/bsd/sys/vnode_if.h */\n\nvfs::vop_create:entry,\nvfs::vop_remove:entry\n{\n\tthis->dir = args[0]->v_cache_dd != NULL ?\n\t    stringof(args[0]->v_cache_dd->nc_name) : \"<null>\";\n\tthis->name = args[1]->a_cnp->cn_nameptr != NULL ?\n\t    stringof(args[1]->a_cnp->cn_nameptr) : \"<null>\";\n\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %s/%s\\n\",\n\t    timestamp / 1000000, uid, pid, execname, probefunc,\n\t    this->dir, this->name);\n}\n"
  },
  {
    "path": "Chap5/vfssnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * vfssnoop.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n#pragma D option dynvarsize=4m\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %-4s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"KB\", \"PATH/FILE\");\n}\n\n/*\n * Populate Vnode2Path from namecache hits\n */\nvfs:namecache:lookup:hit\n/V2P[arg2] == NULL/\n{\n\tV2P[arg2] = stringof(arg1);\n}\n\n/*\n * (Re)populate Vnode2Path from successful namei() lookups\n */\nvfs:namei:lookup:entry\n{\n\tself->buf = arg1;\n}\nvfs:namei:lookup:return\n/self->buf != NULL && arg0 == 0/\n{\n\tV2P[arg1] = stringof(self->buf);\n}\nvfs:namei:lookup:return\n{\n\tself->buf = 0;\n}\n\n/*\n * Trace and print VFS calls\n */\nvfs::vop_read:entry, vfs::vop_write:entry\n{\n\tself->path = V2P[arg0];\n\tself->kb = args[1]->a_uio->uio_resid / 1024;\n}\n\nvfs::vop_open:entry, vfs::vop_close:entry, vfs::vop_ioctl:entry,\nvfs::vop_getattr:entry, vfs::vop_readdir:entry\n{\n\tself->path = V2P[arg0];\n\tself->kb = 0;\n}\n\nvfs::vop_read:entry, vfs::vop_write:entry, vfs::vop_open:entry,\nvfs::vop_close:entry, vfs::vop_ioctl:entry, vfs::vop_getattr:entry,\nvfs::vop_readdir:entry\n/execname != \"dtrace\" && ($$1 == NULL || $$1 == execname)/\n{\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %-4d %s\\n\", timestamp / 1000000,\n\t    uid, pid, execname, probefunc, self->kb,\n\tself->path != NULL ? self->path : \"<unknown>\");\n}\n\nvfs::vop_read:entry, vfs::vop_write:entry, vfs::vop_open:entry,\nvfs::vop_close:entry, vfs::vop_ioctl:entry, vfs::vop_getattr:entry,\nvfs::vop_readdir:entry\n{\n\tself->path = 0; self->kb = 0;\n}\n\n/*\n * Tidy V2P, otherwise it gets too big (dynvardrops)\n */\nvfs:namecache:purge:done,\nvfs::vop_close:entry\n{\n\tV2P[arg0] = 0;\n}\n"
  },
  {
    "path": "Chap5/writetype.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * writetype.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ninline int TOP = 20;\nself int trace;\nuint64_t lbytes;\nuint64_t pbytes;\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing... Output every 5 secs, or Ctrl-C.\\n\");\n}\n\nfsinfo:::write\n{\n\t@io[args[0]->fi_mount, \"logical\"] = count();\n\t@bytes[args[0]->fi_mount, \"logical\"] = sum(arg1);\n\tlbytes += arg1;\n}\n\nio:::start\n/!args[0]->b_flags & B_READ/\n{\n\t@io[args[2]->fi_mount, \"physical\"] = count();\n\t@bytes[args[2]->fi_mount, \"physical\"] = sum(args[0]->b_bcount);\n\tpbytes += args[0]->b_bcount;\n}\n\nprofile:::tick-5s,\ndtrace:::END\n{\n\ttrunc(@io, TOP);\n\ttrunc(@bytes, TOP);\n\tprintf(\"\\n%Y:\\n\", walltimestamp);\n\tprintf(\"\\n Write I/O (top %d)\\n\", TOP);\n\tprinta(\" %-32s %10s %10@d\\n\", @io);\n\tprintf(\"\\n Write Bytes (top %d)\\n\", TOP);\n\tprinta(\" %-32s %10s %10@d\\n\", @bytes);\n\tprintf(\"\\nphysical/logical bytes rate: %d%%\\n\",\n\t    lbytes ? 100 * pbytes / lbytes : 0);\n\ttrunc(@bytes);\n\ttrunc(@io);\n\tlbytes = pbytes = 0;\n}\n"
  },
  {
    "path": "Chap5/zfsslower.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * zfsslower.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %-16s %1s %4s %6s %s\\n\", \"TIME\", \"PROCESS\",\n\t    \"D\", \"KB\", \"ms\", \"FILE\");\n\tmin_ns = $1 * 1000000;\n}\n\n/* see uts/common/fs/zfs/zfs_vnops.c */\n\nfbt::zfs_read:entry,\nfbt::zfs_write:entry\n{\n\tself->path = args[0]->v_path;\n\tself->kb = args[1]->uio_resid / 1024;\n\tself->start = timestamp;\n}\n\nfbt::zfs_read:return,\nfbt::zfs_write:return\n/self->start && (timestamp - self->start) >= min_ns/\n{\n\tthis->iotime = (timestamp - self->start) / 1000000;\n\tthis->dir = probefunc == \"zfs_read\" ? \"R\" : \"W\";\n\tprintf(\"%-20Y %-16s %1s %4d %6d %s\\n\", walltimestamp,\n\t    execname, this->dir, self->kb, this->iotime,\n\t    self->path != NULL ? stringof(self->path) : \"<null>\");\n}\n\nfbt::zfs_read:return,\nfbt::zfs_write:return\n{\n\tself->path = 0; self->kb = 0; self->start = 0;\n}\n"
  },
  {
    "path": "Chap5/zfssnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * zfssnoop.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-12s %6s %6s %-12.12s %-12s %-4s %s\\n\", \"TIME(ms)\", \"UID\",\n\t    \"PID\", \"PROCESS\", \"CALL\", \"KB\", \"PATH\");\n}\n\n/* see uts/common/fs/zfs/zfs_vnops.c */\n\nfbt::zfs_read:entry, fbt::zfs_write:entry\n{\n\tself->path = args[0]->v_path;\n\tself->kb = args[1]->uio_resid / 1024;\n}\n\nfbt::zfs_open:entry\n{\n\tself->path = (*args[0])->v_path;\n\tself->kb = 0;\n}\n\nfbt::zfs_close:entry, fbt::zfs_ioctl:entry, fbt::zfs_getattr:entry,\nfbt::zfs_readdir:entry\n{\n\tself->path = args[0]->v_path;\n\tself->kb = 0;\n}\n\nfbt::zfs_read:entry, fbt::zfs_write:entry, fbt::zfs_open:entry,\nfbt::zfs_close:entry, fbt::zfs_ioctl:entry, fbt::zfs_getattr:entry,\nfbt::zfs_readdir:entry\n{\n\tprintf(\"%-12d %6d %6d %-12.12s %-12s %-4d %s\\n\", timestamp / 1000000,\n\t    uid, pid, execname, probefunc, self->kb,\n\t    self->path != NULL ? stringof(self->path) : \"<null>\");\n\tself->path = 0; self->kb = 0;\n}\n"
  },
  {
    "path": "Chap5/zioprint.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * zioprint.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-16s %-3s %-22s %-6s %s\\n\", \"TIME(us)\", \"CPU\", \"FUNC\",\n\t    \"NAME\", \"ARGS\");\n}\n\nfbt::zio_*:entry\n{\n\tprintf(\"%-16d %-3d %-22s %-6s %x %x %x %x %x\\n\", timestamp / 1000,\n\t    cpu, probefunc, probename, arg0, arg1, arg2, arg3, arg4);\n}\n\nfbt::zio_*:return\n{\n\tprintf(\"%-16d %-3d %-22s %-6s %x %x\\n\", timestamp / 1000, cpu,\n\t    probefunc, probename, arg0, arg1);\n}\n"
  },
  {
    "path": "Chap5/ziosnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ziosnoop.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tstart = timestamp;\n\tprintf(\"%-10s %-3s %-12s %-16s %s\\n\", \"TIME(us)\", \"CPU\",\n\t    \"ZIO_EVENT\", \"ARG0\", \"INFO (see script)\");\n}\n\nfbt::zfs_read:entry,\nfbt::zfs_write:entry\n{ self->vp = args[0]; }\n\nfbt::zfs_read:return,\nfbt::zfs_write:return\n{ self->vp = 0; }\n\nfbt::zio_create:return\n/$1 || args[1]->io_type/\n{\n\t/* INFO: pool zio_type zio_flag bytes path */\n\tprintf(\"%-10d %-3d %-12s %-16x %s %d %x %d %s\\n\",\n\t    (timestamp - start) / 1000, cpu, \"CREATED\", arg1,\n\t    stringof(args[1]->io_spa->spa_name), args[1]->io_type,\n\t    args[1]->io_flags, args[1]->io_size, self->vp &&\n\t    self->vp->v_path ? stringof(self->vp->v_path) : \"<null>\");\n}\n\nfbt::zio_*:entry\n/$1/\n{\n\tprintf(\"%-10d %-3d %-12s %-16x\\n\", (timestamp - start) / 1000, cpu,\n\t    probefunc, arg0);\n}\n\nfbt::zio_done:entry\n/$1 || args[0]->io_type/\n{\n\t/* INFO: io_error vdev_state vdev_path */\n\tprintf(\"%-10d %-3d %-12s %-16x %d %d %s\\n\", (timestamp - start) / 1000,\n\t    cpu, \"DONE\", arg0, args[0]->io_error,\n\t    args[0]->io_vd ? args[0]->io_vd->vdev_state : 0,\n\t    args[0]->io_vd && args[0]->io_vd->vdev_path ?\n\t    stringof(args[0]->io_vd->vdev_path) : \"<null>\");\n}\n"
  },
  {
    "path": "Chap5/ziotype.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ziotype.d\n *\n * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\t/* see /usr/include/sys/fs/zfs.h */\n\tziotype[0] = \"null\";\n\tziotype[1] = \"read\";\n\tziotype[2] = \"write\";\n\tziotype[3] = \"free\";\n\tziotype[4] = \"claim\";\n\tziotype[5] = \"ioctl\";\n\ttrace(\"Tracing ZIO...  Output interval 5 seconds, or Ctrl-C.\\n\");\n}\n\nfbt::zio_create:return\n/args[1]->io_type/\t\t/* skip null */\n{\n\t@[stringof(args[1]->io_spa->spa_name),\n\t    ziotype[args[1]->io_type] != NULL ?\n\t    ziotype[args[1]->io_type] : \"?\"] = count();\n}\n\nprofile:::tick-5sec,\ndtrace:::END\n{\n\tprintf(\"\\n %-32s %-10s %10s\\n\", \"POOL\", \"ZIO_TYPE\", \"CREATED\");\n\tprinta(\" %-32s %-10s %@10d\\n\", @);\n\ttrunc(@);\n}\n"
  },
  {
    "path": "Chap6/icmpsnoop.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * icmpsnoop.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\n#define\tIPPROTO_ICMP            1\n#define\tIPH_HDR_LENGTH(iph)     (((struct ip *)(iph))->ip_hl << 2)\n\ndtrace:::BEGIN\n{\n\t/* See RFC792 and ip_icmp.h */\n\ticmptype[0] = \"ECHOREPLY\";\n\ticmptype[3] = \"UNREACH\";\n\ticmpcode[3, 0] = \"NET\";\n\ticmpcode[3, 1] = \"HOST\";\n\ticmpcode[3, 2] = \"PROTOCOL\";\n\ticmpcode[3, 3] = \"PORT\";\n\ticmpcode[3, 4] = \"NEEDFRAG\";\n\ticmpcode[3, 5] = \"SRCFAIL\";\n\ticmpcode[3, 6] = \"NET_UNKNOWN\";\n\ticmpcode[3, 7] = \"HOST_UNKNOWN\";\n\ticmpcode[3, 8] = \"ISOLATED\";\n\ticmpcode[3, 9] = \"NET_PROHIB\";\n\ticmpcode[3, 10] = \"HOST_PROHIB\";\n\ticmpcode[3, 11] = \"TOSNET\";\n\ticmpcode[3, 12] = \"TOSHOST\";\n\ticmpcode[3, 13] = \"FILTER_PROHIB\";\n\ticmpcode[3, 14] = \"HOST_PRECEDENCE\";\n\ticmpcode[3, 15] = \"PRECEDENCE_CUTOFF\";\n\ticmptype[4] = \"SOURCEQUENCH\";\n\ticmptype[5] = \"REDIRECT\";\n\ticmpcode[5, 0] = \"NET\";\n\ticmpcode[5, 0] = \"HOST\";\n\ticmpcode[5, 0] = \"TOSNET\";\n\ticmpcode[5, 0] = \"TOSHOST\";\n\ticmptype[8] = \"ECHO\";\n\ticmptype[9] = \"ROUTERADVERT\";\n\ticmpcode[9, 0] = \"COMMON\";\n\ticmpcode[9, 16] = \"NOCOMMON\";\n\ticmptype[10] = \"ROUTERSOLICIT\";\n\ticmptype[11] = \"TIMXCEED\";\n\ticmpcode[11, 0] = \"INTRANS\";\n\ticmpcode[11, 1] = \"REASS\";\n\ticmptype[12] = \"PARAMPROB\";\n\ticmpcode[12, 1] = \"OPTABSENT\";\n\ticmpcode[12, 2] = \"BADLENGTH\";\n\ticmptype[13] = \"TSTAMP\";\n\ticmptype[14] = \"TSTAMPREPLY\";\n\ticmptype[15] = \"IREQ\";\n\ticmptype[16] = \"IREQREPLY\";\n\ticmptype[17] = \"MASKREQ\";\n\ticmptype[18] = \"MASKREPLY\";\n\n\tprintf(\"%-20s  %-12s %1s %-15s %-15s %s\\n\", \"TIME\", \"PROCESS\", \"D\",\n\t    \"REMOTE\", \"TYPE\", \"CODE\");\n}\n\nfbt::icmp_inbound:entry\n{\n\tthis->mp = args[1];\n\tthis->ipha = (ipha_t *)this->mp->b_rptr;\n\t/* stringify manually if inet_ntoa() unavailable */\n\tthis->addr = inet_ntoa(&this->ipha->ipha_src);\n\tthis->dir = \"<\";\n}\n\nfbt::ip_xmit_v4:entry\n/arg4 && args[4]->conn_ulp == IPPROTO_ICMP/\n{\n\tthis->mp = args[0];\n\tthis->ipha = (ipha_t *)this->mp->b_rptr;\n\t/* stringify manually if inet_ntoa() unavailable */\n\tthis->addr = inet_ntoa(&this->ipha->ipha_dst);\n\tthis->dir = \">\";\n}\n\nfbt::icmp_inbound:entry,\nfbt::ip_xmit_v4:entry\n/this->dir != NULL/\n{\n\tthis->iph_hdr_length = IPH_HDR_LENGTH(this->ipha);\n\tthis->icmph = (icmph_t *)&this->mp->b_rptr[(char)this->iph_hdr_length];\n\tthis->type = this->icmph->icmph_type;\n\tthis->code = this->icmph->icmph_code;\n\tthis->typestr = icmptype[this->type] != NULL ?\n\t    icmptype[this->type] : lltostr(this->type);\n\tthis->codestr = icmpcode[this->type, this->code] != NULL ?\n\t    icmpcode[this->type, this->code] : lltostr(this->code);\n\n\tprintf(\"%-20Y  %-12.12s %1s %-15s %-15s %s\\n\", walltimestamp, execname,\n\t    this->dir, this->addr, this->typestr, this->codestr);\n}\n"
  },
  {
    "path": "Chap6/icmpstat.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * icmpstat.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nmib::icmp_*:\n{\n\t@icmp[probename] = sum(arg0);\n}\n\nprofile:::tick-1sec\n{\n\tprintf(\"\\n%Y:\\n\\n\", walltimestamp);\n\tprintf(\"  %32s %8s\\n\", \"STATISTIC\", \"VALUE\");\n\tprinta(\"  %32s %@8d\\n\", @icmp);\n\ttrunc(@icmp);\n}\n"
  },
  {
    "path": "Chap6/ipfbtsnoop.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * ipfbtsnoop.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\n#define\tETHERTYPE_IP            (0x0800)        /* IP protocol */\n#define\tETHERTYPE_IPV6          (0x86dd)        /* IPv6 */\n\n#define\tIPPROTO_IP              0\n#define\tIPPROTO_ICMP            1\n#define\tIPPROTO_IGMP            2\n#define\tIPPROTO_TCP             6\n#define\tIPPROTO_UDP             17\n\n#define\tDL_ETHER                0x4\n\n#define\tIPH_HDR_VERSION(ipha) \\\n\t((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length) >> 4)\n\n/* stringify an IPv4 address without inet*() being available */\n#define\tIPV4_ADDR_TO_STR(string, addr)                                  \\\n\tthis->a = (uint8_t *)&addr;                                     \\\n\tthis->addr1 = strjoin(lltostr(this->a[0] + 0ULL), strjoin(\".\",  \\\n\t    strjoin(lltostr(this->a[1] + 0ULL), \".\")));                 \\\n\tthis->addr2 = strjoin(lltostr(this->a[2] + 0ULL), strjoin(\".\",  \\\n\t    lltostr(this->a[3] + 0ULL)));                               \\\n\tstring = strjoin(this->addr1, this->addr2);\n\n/* convert net to host byte order for little-endian systems  */\n#define\tBSWAP_16(host, net)                                             \\\n\thost = (net & 0xFF00) >> 8;                                     \\\n\thost |= (net & 0xFF) << 8;\n\ndtrace:::BEGIN\n{\n\t/* selected protocols; see /usr/include/netinet/in.h for full list */\n\tipproto[IPPROTO_IP] = \"IP\";\n\tipproto[IPPROTO_ICMP] = \"ICMP\";\n\tipproto[IPPROTO_IGMP] = \"IGMP\";\n\tipproto[IPPROTO_TCP] = \"TCP\";\n\tipproto[IPPROTO_UDP] = \"UDP\";\n\n\tprintf(\"%-15s %-8s %-8s %-15s   %-15s %5s %5s\\n\", \"TIME(us)\",\n\t    \"ONCPU\", \"INT\", \"SOURCE\", \"DEST\", \"BYTES\", \"PROTO\");\n}\n\nfbt::ip_input:entry\n{\n\tthis->mp = args[2];\n\tthis->ill = args[0];\n\tthis->ipha = (ipha_t *)this->mp->b_rptr;\n\tthis->name = stringof(this->ill->ill_name);\n\tthis->ok = 1;\n}\n\n/* rewrite for dls_tx() on older Solaris kernels */\nfbt::mac_tx:entry\n{\n\tthis->mc = (mac_client_impl_t *)args[0];\n}\n\n/* filter out non-Ethernet calls */\nfbt::mac_tx:entry\n/this->mc->mci_mip->mi_info.mi_nativemedia == DL_ETHER/\n{\n\tthis->mp = args[1];\n\tthis->eth = (struct ether_header *)this->mp->b_rptr;\n\tthis->type = this->eth->ether_type;\n}\n\n/* filter out non-IP calls */\nfbt::mac_tx:entry\n/this->type == ETHERTYPE_IP || this->type == ETHERTYPE_IPV6/\n{\n\tthis->ipha = (ipha_t *)&this->mp->b_rptr[sizeof (struct ether_header)];\n\tthis->name = this->mc->mci_name;\n\tthis->ok = 1;\n}\n\nfbt::ip_input:entry, fbt::mac_tx:entry\n/this->ok && IPH_HDR_VERSION(this->ipha) == 4/\n{\n\tBSWAP_16(this->pktlen, this->ipha->ipha_length);\n\tIPV4_ADDR_TO_STR(this->src, this->ipha->ipha_src);\n\tIPV4_ADDR_TO_STR(this->dst, this->ipha->ipha_dst);\n\n\tthis->proto = ipproto[this->ipha->ipha_protocol] != NULL ?\n\t    ipproto[this->ipha->ipha_protocol] :\n\t    lltostr(this->ipha->ipha_protocol);\n\n\tprintf(\"%-15d %-8.8s %-8.8s %-15s > %-15s %5d %5s\\n\",\n\t    timestamp / 1000, execname, this->name, this->src, this->dst,\n\t    this->pktlen, this->proto);\n}\n"
  },
  {
    "path": "Chap6/ipio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ipio.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\" %3s %10s %15s    %15s %8s %6s\\n\", \"CPU\", \"DELTA(us)\",\n\t    \"SOURCE\", \"DEST\", \"INT\", \"BYTES\");\n\tlast = timestamp;\n}\n\nip:::send\n{\n\tthis->delta = (timestamp - last) / 1000;\n\tprintf(\" %3d %10d %15s -> %15s %8s %6d\\n\", cpu, this->delta,\n\t    args[2]->ip_saddr, args[2]->ip_daddr, args[3]->if_name,\n\t    args[2]->ip_plength);\n\tlast = timestamp;\n}\n\nip:::receive\n{\n\tthis->delta = (timestamp - last) / 1000;\n\tprintf(\" %3d %10d %15s <- %15s %8s %6d\\n\", cpu, this->delta,\n\t    args[2]->ip_daddr, args[2]->ip_saddr, args[3]->if_name,\n\t    args[2]->ip_plength);\n\tlast = timestamp;\n}\n"
  },
  {
    "path": "Chap6/ipproto.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ipproto.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nip:::send,\nip:::receive\n{\n\tthis->protostr = args[2]->ip_ver == 4 ?\n\t    args[4]->ipv4_protostr : args[5]->ipv6_nextstr;\n\t@num[args[2]->ip_saddr, args[2]->ip_daddr, this->protostr] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %-28s %-28s %6s %8s\\n\", \"SADDR\", \"DADDR\", \"PROTO\", \"COUNT\");\n\tprinta(\"   %-28s %-28s %6s %@8d\\n\", @num);\n}\n"
  },
  {
    "path": "Chap6/ipstat.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ipstat.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tLINES = 20; line = 0;\n}\n\nprofile:::tick-1sec\n/--line <= 0/\n{\n\tprintf(\"  IP IF:  %12s %12s %12s %12s %12s\\n\", \"out(bytes)\",\n\t    \"outDiscards\", \"in(bytes)\", \"inDiscards\", \"inErrors\");\n\tline = LINES;\n}\n\nmib:::ipIfStatsHCInOctets       { @in = sum(arg0);      }\nmib:::ipIfStatsHCOutOctets      { @out = sum(arg0);     }\nmib:::ipIfStatsInDiscards       { @inDis = sum(arg0);   }\nmib:::ipIfStatsOutDiscards      { @outDis = sum(arg0);  }\nmib:::ipIfStatsIn*Errors        { @inErr = sum(arg0);   }\n\nprofile:::tick-1sec\n{\n\tprinta(\"          %@12d %@12d %@12d %@12d %@12d\\n\",\n\t    @out, @outDis, @in, @inDis, @inErr);\n\tclear(@out); clear(@outDis); clear(@in); clear(@inDis); clear(@inErr);\n}\n"
  },
  {
    "path": "Chap6/macops.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * macops.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\t/* See /usr/include/sys/dlpi.h */\n\tmediatype[0x0] = \"CSMACD\";\n\tmediatype[0x1] = \"TPB\";\n\tmediatype[0x2] = \"TPR\";\n\tmediatype[0x3] = \"METRO\";\n\tmediatype[0x4] = \"ETHER\";\n\tmediatype[0x05] = \"HDLC\";\n\tmediatype[0x06] = \"CHAR\";\n\tmediatype[0x07] = \"CTCA\";\n\tmediatype[0x08] = \"FDDI\";\n\tmediatype[0x10] = \"FC\";\n\tmediatype[0x11] = \"ATM\";\n\tmediatype[0x12] = \"IPATM\";\n\tmediatype[0x13] = \"X25\";\n\tmediatype[0x14] = \"ISDN\";\n\tmediatype[0x15] = \"HIPPI\";\n\tmediatype[0x16] = \"100VG\";\n\tmediatype[0x17] = \"100VGTPR\";\n\tmediatype[0x18] = \"ETH_CSMA\";\n\tmediatype[0x19] = \"100BT\";\n\tmediatype[0x1a] = \"IB\";\n\tmediatype[0x0a] = \"FRAME\";\n\tmediatype[0x0b] = \"MPFRAME\";\n\tmediatype[0x0c] = \"ASYNC\";\n\tmediatype[0x0d] = \"IPX25\";\n\tmediatype[0x0e] = \"LOOP\";\n\tmediatype[0x09] = \"OTHER\";\n\n\tprintf(\"Tracing MAC calls... Hit Ctrl-C to end.\\n\");\n}\n\n/* the following are not complete lists of mac functions; add as needed */\n\n/* mac functions with mac_client_impl_t as the first arg */\nfbt::mac_promisc_add:entry,\nfbt::mac_promisc_remove:entry,\nfbt::mac_multicast_add:entry,\nfbt::mac_multicast_remove:entry,\nfbt::mac_unicast_add:entry,\nfbt::mac_unicast_remove:entry,\nfbt::mac_tx:entry\n{\n\tthis->macp = (mac_client_impl_t *)arg0;\n\tthis->name = stringof(this->macp->mci_name);\n\tthis->media = this->macp->mci_mip->mi_info.mi_media;\n\tthis->type = mediatype[this->media] != NULL ?\n\t    mediatype[this->media] : lltostr(this->media);\n\tthis->dir = probefunc == \"mac_tx\" ? \"->\" : \".\";\n\t@[this->name, this->type, probefunc, this->dir] = count();\n}\n\n/* mac functions with mac_impl_t as the first arg */\nfbt::mac_stop:entry,\nfbt::mac_start:entry,\nfbt::mac_stat_get:entry,\nfbt::mac_ioctl:entry,\nfbt::mac_capab_get:entry,\nfbt::mac_set_prop:entry,\nfbt::mac_get_prop:entry,\nfbt::mac_rx:entry\n{\n\tthis->mip = (mac_impl_t *)arg0;\n\tthis->name = stringof(this->mip->mi_name);\n\tthis->media = this->mip->mi_info.mi_media;\n\tthis->type = mediatype[this->media] != NULL ?\n\t    mediatype[this->media] : lltostr(this->media);\n\tthis->dir = probefunc == \"mac_rx\" ? \"<-\" : \".\";\n\t@[this->name, this->type, probefunc, this->dir] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-16s %-16s %-16s %-4s %14s\\n\", \"INT\", \"MEDIA\", \"MAC\",\n\t    \"DATA\", \"CALLS\");\n\tprinta(\"  %-16s %-16s %-16s %-4s %@14d\\n\", @);\n}\n"
  },
  {
    "path": "Chap6/ngelink.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ngelink.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate\n\nint seen[nge_t *];\nint up[nge_t *];\nint speed[nge_t *];\nint duplex[nge_t *];\nint last[nge_t *];\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s  %-10s %6s %8s %8s   %s\\n\", \"TIME\", \"INT\", \"UP\",\n\t    \"SPEED\", \"DUPLEX\", \"DELTA(ms)\");\n}\n\nfbt::nge_check_copper:entry\n{\n\tself->ngep = args[0];\n}\n\nfbt::nge_check_copper:return\n/self->ngep && (!seen[self->ngep] ||\n\t(up[self->ngep] != self->ngep->param_link_up ||\n\tspeed[self->ngep] != self->ngep->param_link_speed ||\n\tduplex[self->ngep] != self->ngep->param_link_duplex))/\n{\n\tthis->delta = last[self->ngep] ? timestamp - last[self->ngep] : 0;\n\tthis->name = stringof(self->ngep->ifname);\n\tprintf(\"%-20Y  %-10s %6d %8d %8d   %d\\n\", walltimestamp, this->name,\n\t    self->ngep->param_link_up, self->ngep->param_link_speed,\n\tself->ngep->param_link_duplex, this->delta / 1000000);\n\tseen[self->ngep] = 1;\n\tlast[self->ngep] = timestamp;\n}\n\nfbt::nge_check_copper:return\n/self->ngep/\n{\n\tup[self->ngep] = self->ngep->param_link_up;\n\tspeed[self->ngep] = self->ngep->param_link_speed;\n\tduplex[self->ngep] = self->ngep->param_link_duplex;\n\tself->ngep = 0;\n}\n"
  },
  {
    "path": "Chap6/ngesnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ngesnoop.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-15s  %-8s %-2s %-17s  %-17s  %-5s %5s\\n\", \"TIME(us)\",\n\t    \"INT\", \"D\", \"SOURCE\", \"DEST\", \"PROTO\", \"BYTES\");\n}\n\nfbt::nge_recv_ring:entry\n{\n\tself->ngep = args[0];\n}\n\nfbt::mac_rx:entry\n/self->ngep/\n{\n\tthis->mp = args[2];\n\tthis->nge = self->ngep;\n\tthis->dir = \"<-\";\n\tself->ngep = 0;\n}\n\nfbt::nge_send:entry\n{\n\tthis->nge = (nge_t *)arg0;\n\tthis->mp = args[1];\n\tthis->dir = \"->\";\n}\n\nfbt::mac_rx:entry,\nfbt::nge_send:entry\n/this->mp/\n{\n\tthis->eth = (struct ether_header *)this->mp->b_rptr;\n\tthis->s = (char *)&this->eth->ether_shost;\n\tthis->d = (char *)&this->eth->ether_dhost;\n\tthis->t = ntohs(this->eth->ether_type);\n\tprintf(\"%-15d  %-8s %2s \", timestamp / 1000, this->nge->ifname,\n\t    this->dir);\n\tprintf(\"%02x:%02x:%02x:%02x:%02x:%02x  \", this->s[0], this->s[1],\n\t    this->s[2], this->s[3], this->s[4], this->s[5]);\n\tprintf(\"%02x:%02x:%02x:%02x:%02x:%02x  \", this->d[0], this->d[1],\n\t    this->d[2], this->d[3], this->d[4], this->d[5]);\n\tprintf(\" %-04x %5d\\n\", this->t, msgdsize(this->mp));\n}\n"
  },
  {
    "path": "Chap6/so1stbyte.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * so1stbyte.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"  %6s %-16s %6s  %14s %14s  %8s\\n\", \"PID\", \"PROCESS\", \"PORT\",\n\t    \"CONNECT(us)\", \"1stBYTE(us)\", \"BYTES\");\n}\n\nsyscall::connect*:entry\n{\n\tthis->s = (struct sockaddr_in *)copyin(arg1, sizeof (struct sockaddr));\n\tself->port = (this->s->sin_port & 0xFF00) >> 8;\n\tself->port |= (this->s->sin_port & 0xFF) << 8;\n\tself->start = timestamp;\n\tself->connected = 0;\n}\n\nsyscall::connect*:return\n{\n\tself->connection = (timestamp - self->start) / 1000;\n\tself->start = 0;\n\tself->connected = timestamp;\n}\n\nsyscall::read*:entry,\nsyscall::recv*:entry\n/(fds[arg0].fi_fs == \"sockfs\" || fds[arg0].fi_name == \"<socket>\") &&\n    self->connected/\n{\n\tself->socket = 1;\n}\n\nsyscall::read*:return,\nsyscall::recv*:return\n/self->socket && arg0 > 0/\n{\n\tthis->firstbyte = (timestamp - self->connected) / 1000;\n\tprintf(\"  %6d %-16s %6d  %14d %14d  %8d\\n\", pid, execname, self->port,\n\t    self->connection, this->firstbyte, arg0);\n\tself->connected = 0;\n\tself->socket = 0;\n\tself->port = 0;\n}\n"
  },
  {
    "path": "Chap6/soaccept.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * soaccept.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\n/* If AF_INET and AF_INET6 are \"Unknown\" to DTrace, replace with numbers: */\ninline int af_inet = AF_INET;\ninline int af_inet6 = AF_INET6;\n\ndtrace:::BEGIN\n{\n\t/* Add translations as desired from /usr/include/sys/errno.h */\n\terr[0]            = \"Success\";\n\terr[EINTR]        = \"Interrupted syscall\";\n\terr[EIO]          = \"I/O error\";\n\terr[EAGAIN]       = \"Resource temp unavail\";\n\terr[EACCES]       = \"Permission denied\";\n\terr[ECONNABORTED] = \"Connection aborted\";\n\terr[ECONNRESET]   = \"Connection reset\";\n\terr[ETIMEDOUT]    = \"Timed out\";\n\terr[EINPROGRESS]  = \"In progress\";\n\n\tprintf(\"%-6s %-16s %-3s %-16s %-5s %8s %s\\n\", \"PID\", \"PROCESS\", \"FAM\",\n\t    \"ADDRESS\", \"PORT\", \"LAT(us)\", \"RESULT\");\n}\n\nsyscall::accept*:entry\n{\n\tself->sa = arg1;\n\tself->start = timestamp;\n}\n\nsyscall::accept*:return\n/self->sa/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\t/* assume this is sockaddr_in until we can examine family */\n\tthis->s = (struct sockaddr_in *)copyin(self->sa,\n\t    sizeof (struct sockaddr_in));\n\tthis->f = this->s->sin_family;\n}\n\nsyscall::accept*:return\n/this->f == af_inet/\n{\n\tthis->port = ntohs(this->s->sin_port);\n\tthis->address = inet_ntoa((ipaddr_t *)&this->s->sin_addr);\n\tthis->errstr = err[errno] != NULL ? err[errno] : lltostr(errno);\n\tprintf(\"%-6d %-16s %-3d %-16s %-5d %8d %s\\n\", pid, execname,\n\t    this->f, this->address, this->port, this->delta, this->errstr);\n}\n\nsyscall::accept*:return\n/this->f == af_inet6/\n{\n\t/* refetch for sockaddr_in6 */\n\tthis->s6 = (struct sockaddr_in6 *)copyin(self->sa,\n\t    sizeof (struct sockaddr_in6));\n\tthis->port = ntohs(this->s6->sin6_port);\n\tthis->address = inet_ntoa6((in6_addr_t *)&this->s6->sin6_addr);\n\tthis->errstr = err[errno] != NULL ? err[errno] : lltostr(errno);\n\tprintf(\"%-6d %-16s %-3d %-16s %-5d %8d %s\\n\", pid, execname,\n\t    this->f, this->address, this->port, this->delta, this->errstr);\n}\n\nsyscall::accept*:return\n/self->start/\n{\n\tself->sa = 0; self->start = 0;\n}\n"
  },
  {
    "path": "Chap6/socketio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * socketio.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing Socket I/O... Hit Ctrl-C to end.\\n\");\n}\n\nsyscall::read*:entry,\nsyscall::write*:entry,\nsyscall::send*:entry,\nsyscall::recv*:entry\n/fds[arg0].fi_fs == \"sockfs\" || fds[arg0].fi_name == \"<socket>\"/\n{\n\t@[execname, pid, probefunc] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-16s %-8s %-16s %10s\\n\", \"PROCESS\", \"PID\", \"SYSCALL\",\n\t    \"COUNT\");\n\tprinta(\"  %-16s %-8d %-16s %@10d\\n\", @);\n}\n"
  },
  {
    "path": "Chap6/socketiosort.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * socketiosort.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing Socket I/O... Hit Ctrl-C to end.\\n\");\n}\n\nsyscall::read*:entry,\nsyscall::write*:entry,\nsyscall::send*:entry,\nsyscall::recv*:entry\n/fds[arg0].fi_fs == \"sockfs\" || fds[arg0].fi_name == \"<socket>\"/\n{\n\t@num[execname, probefunc, pid] = count();\n\t@pid[execname, probefunc, pid] = max(pid);\n\t@pid[\"--------------\", \"------\", pid] = max(pid);\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-8s %-16s %-16s %10s\\n\", \"PID\", \"PROCESS\", \"SYSCALL\",\n\t    \"COUNT\");\n\tsetopt(\"aggsortpos\", \"0\");\n\tprinta(\"  %@-8d %-16s %-16s %@10d\\n\", @pid, @num);\n}\n"
  },
  {
    "path": "Chap6/soclose.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * soclose.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\n/* If AF_INET and AF_INET6 are \"Unknown\" to DTrace, replace with numbers: */\ninline int af_inet = AF_INET;\ninline int af_inet6 = AF_INET6;\n\ndtrace:::BEGIN\n{\n\tprintf(\"  %-6s %-16s %-3s %-16s %-5s %s\\n\", \"PID\", \"PROCESS\", \"FAM\",\n\t    \"ADDRESS\", \"PORT\", \"DURATION(sec)\");\n}\n\nsyscall::connect*:entry\n{\n\tthis->s = (struct sockaddr_in *)copyin(arg1, sizeof (struct sockaddr));\n\tthis->f = this->s->sin_family;\n}\n\nsyscall::connect*:entry\n/this->f == af_inet || this->f == af_inet6/\n{\n\tself->family[arg0] = this->f;\n\tself->port[arg0] = ntohs(this->s->sin_port);\n\tself->address[arg0] = inet_ntop(this->s->sin_family,\n\t    (void *)&this->s->sin_addr);\n\tself->start[arg0] = timestamp;\n}\n\nsyscall::close:entry\n/self->start[arg0]/\n{\n\tthis->delta = (timestamp - self->start[arg0]) / 1000;\n\tthis->sec = this->delta / 1000000;\n\tthis->ms = (this->delta - (this->sec * 1000000)) / 1000;\n\tprintf(\"  %-6d %-16s %-3d %-16s %-5d %d.%03d\\n\", pid, execname,\n\t    self->family[arg0], self->address[arg0], self->port[arg0],\n\t    this->sec, this->ms);\n\tself->family[arg0] = 0;\n\tself->address[arg0] = 0;\n\tself->port[arg0] = 0;\n\tself->start[arg0] = 0;\n}\n"
  },
  {
    "path": "Chap6/soconnect.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * soconnect.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\n/* If AF_INET and AF_INET6 are \"Unknown\" to DTrace, replace with numbers: */\ninline int af_inet = AF_INET;\ninline int af_inet6 = AF_INET6;\n\ndtrace:::BEGIN\n{\n\t/* Add translations as desired from /usr/include/sys/errno.h */\n\terr[0]            = \"Success\";\n\terr[EINTR]        = \"Interrupted syscall\";\n\terr[EIO]          = \"I/O error\";\n\terr[EACCES]       = \"Permission denied\";\n\terr[ENETDOWN]     = \"Network is down\";\n\terr[ENETUNREACH]  = \"Network unreachable\";\n\terr[ECONNRESET]   = \"Connection reset\";\n\terr[ECONNREFUSED] = \"Connection refused\";\n\terr[ETIMEDOUT]    = \"Timed out\";\n\terr[EHOSTDOWN]    = \"Host down\";\n\terr[EHOSTUNREACH] = \"No route to host\";\n\terr[EINPROGRESS]  = \"In progress\";\n\n\tprintf(\"%-6s %-16s %-3s %-16s %-5s %8s %s\\n\", \"PID\", \"PROCESS\", \"FAM\",\n\t    \"ADDRESS\", \"PORT\", \"LAT(us)\", \"RESULT\");\n}\n\nsyscall::connect*:entry\n{\n\t/* assume this is sockaddr_in until we can examine family */\n\tthis->s = (struct sockaddr_in *)copyin(arg1, sizeof (struct sockaddr));\n\tthis->f = this->s->sin_family;\n}\n\nsyscall::connect*:entry\n/this->f == af_inet/\n{\n\tself->family = this->f;\n\tself->port = ntohs(this->s->sin_port);\n\tself->address = inet_ntop(self->family, (void *)&this->s->sin_addr);\n\tself->start = timestamp;\n}\n\nsyscall::connect*:entry\n/this->f == af_inet6/\n{\n\t/* refetch for sockaddr_in6 */\n\tthis->s6 = (struct sockaddr_in6 *)copyin(arg1,\n\t    sizeof (struct sockaddr_in6));\n\tself->family = this->f;\n\tself->port = ntohs(this->s6->sin6_port);\n\tself->address = inet_ntoa6((in6_addr_t *)&this->s6->sin6_addr);\n\tself->start = timestamp;\n}\n\nsyscall::connect*:return\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\tthis->errstr = err[errno] != NULL ? err[errno] : lltostr(errno);\n\tprintf(\"%-6d %-16s %-3d %-16s %-5d %8d %s\\n\", pid, execname,\n\t    self->family, self->address, self->port, this->delta, this->errstr);\n\tself->family = 0;\n\tself->address = 0;\n\tself->port = 0;\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap6/soconnect_mac.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * soconnect_mac.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ninline int af_inet = 2;\t\t/* AF_INET defined in bsd/sys/socket.h */\ninline int af_inet6 = 30;\t/* AF_INET6 defined in bsd/sys/socket.h */\n\ndtrace:::BEGIN\n{\n\t/* Add translations as desired from /usr/include/sys/errno.h */\n\terr[0]            = \"Success\";\n\terr[EINTR]        = \"Interrupted syscall\";\n\terr[EIO]          = \"I/O error\";\n\terr[EACCES]       = \"Permission denied\";\n\terr[ENETDOWN]     = \"Network is down\";\n\terr[ENETUNREACH]  = \"Network unreachable\";\n\terr[ECONNRESET]   = \"Connection reset\";\n\terr[ECONNREFUSED] = \"Connection refused\";\n\terr[ETIMEDOUT]    = \"Timed out\";\n\terr[EHOSTDOWN]    = \"Host down\";\n\terr[EHOSTUNREACH] = \"No route to host\";\n\terr[EINPROGRESS]  = \"In progress\";\n\n\tprintf(\"%-6s %-16s %-3s %-16s %-5s %8s %s\\n\", \"PID\", \"PROCESS\", \"FAM\",\n\t    \"ADDRESS\", \"PORT\", \"LAT(us)\", \"RESULT\");\n}\n\nsyscall::connect*:entry\n{\n\t/* assume this is sockaddr_in until we can examine family */\n\tthis->s = (struct sockaddr_in *)copyin(arg1, sizeof (struct sockaddr));\n\tthis->f = this->s->sin_family;\n}\n\nsyscall::connect*:entry\n/this->f == af_inet/\n{\n\tself->family = this->f;\n\n\t/* Convert port to host byte order without ntohs() being available. */\n\tself->port = (this->s->sin_port & 0xFF00) >> 8;\n\tself->port |= (this->s->sin_port & 0xFF) << 8;\n\n\t/*\n\t * Convert an IPv4 address into a dotted quad decimal string.\n\t * Until the inet_ntoa() functions are available from DTrace, this is\n\t * converted using the existing strjoin() and lltostr().  It's done in\n\t * two parts to avoid exhausting DTrace registers in one line of code.\n\t */\n\tthis->a = (uint8_t *)&this->s->sin_addr;\n\tthis->addr1 = strjoin(lltostr(this->a[0] + 0ULL), strjoin(\".\",\n\t    strjoin(lltostr(this->a[1] + 0ULL), \".\")));\n\tthis->addr2 = strjoin(lltostr(this->a[2] + 0ULL), strjoin(\".\",\n\t    lltostr(this->a[3] + 0ULL)));\n\tself->address = strjoin(this->addr1, this->addr2);\n\n\tself->start = timestamp;\n}\n\nsyscall::connect*:return\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\tthis->errstr = err[errno] != NULL ? err[errno] : lltostr(errno);\n\tprintf(\"%-6d %-16s %-3d %-16s %-5d %8d %s\\n\", pid, execname,\n\t    self->family, self->address, self->port, this->delta, this->errstr);\n\tself->family = 0;\n\tself->address = 0;\n\tself->port = 0;\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap6/soerrors.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * soerrors.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\t/* Add translations as desired from /usr/include/sys/errno.h */\n\terr[0]            = \"Success\";\n\terr[EACCES]       = \"Permission denied\";\n\terr[ECONNABORTED] = \"Connection abort\";\n\terr[ECONNREFUSED] = \"Connection refused\";\n\terr[ECONNRESET]   = \"Connection reset\";\n\terr[EHOSTDOWN]    = \"Host down\";\n\terr[EHOSTUNREACH] = \"No route to host\";\n\terr[EINPROGRESS]  = \"In progress\";\n\terr[EINTR]        = \"Interrupted syscall\";\n\terr[EINVAL]       = \"Invalid argument\";\n\terr[EIO]          = \"I/O error\";\n\terr[ENETDOWN]     = \"Network is down\";\n\terr[ENETUNREACH]  = \"Network unreachable\";\n\terr[EPROTO]       = \"Protocol error\";\n\terr[ETIMEDOUT]    = \"Timed out\";\n\terr[EWOULDBLOCK]  = \"Would block\";\n\n\tprintf(\"  %-6s %-16s %-10s %-4s %4s %4s  %s\\n\", \"PID\", \"PROCESS\",\n\t    \"SYSCALL\", \"FD\", \"RVAL\", \"ERR\", \"RESULT\");\n}\n\nsyscall::connect*:entry,\nsyscall::accept*:entry,\nsyscall::getsockopt:entry,\nsyscall::setsockopt:entry\n{\n\tself->fd = arg0; self->ok = 1;\n}\n\nsyscall::read*:entry,\nsyscall::write*:entry,\nsyscall::send*:entry,\nsyscall::recv*:entry\n/fds[arg0].fi_fs == \"sockfs\" || fds[arg0].fi_name == \"<socket>\"/\n{\n\tself->fd = arg0; self->ok = 1;\n}\n\nsyscall::so*:entry\n{\n\tself->ok = 1;\n}\n\nsyscall::connect*:return,\nsyscall::accept*:return,\nsyscall::read*:return,\nsyscall::write*:return,\nsyscall::send*:return,\nsyscall::recv*:return,\nsyscall::getsockopt:return,\nsyscall::setsockopt:return\n/errno != 0 && errno != EAGAIN && self->ok/\n{\n\tthis->errstr = err[errno] != NULL ? err[errno] : lltostr(errno);\n\tprintf(\"  %-6d %-16s %-10s %-4d %4d %4d  %s\\n\", pid, execname,\n\t    probefunc, self->fd, arg0, errno, this->errstr);\n}\n\nsyscall::so*:return\n/errno != 0/\n{\n\t/* these syscalls (such as sockconfig) don't operate on socket fds */\n\tthis->errstr = err[errno] != NULL ? err[errno] : lltostr(errno);\n\tprintf(\"  %-6d %-16s %-10s %-4s %4d %4d  %s\\n\", pid, execname,\n\t    probefunc, \"-\", arg0, errno, this->errstr);\n}\n\nsyscall::connect*:return,\nsyscall::accept*:return,\nsyscall::read*:return,\nsyscall::write*:return,\nsyscall::send*:return,\nsyscall::recv*:return,\nsyscall::getsockopt:return,\nsyscall::setsockopt:return,\nsyscall::so*:return\n{\n\tself->fd = 0; self->ok = 0;\n}\n"
  },
  {
    "path": "Chap6/sotop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sotop.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option destructive\n\nsyscall::read*:entry,\nsyscall::recv*:entry\n/fds[arg0].fi_fs == \"sockfs\" || fds[arg0].fi_name == \"<socket>\"/\n{\n\tself->read = 1;\n}\n\nsyscall::read*:return,\nsyscall::recv*:return\n/self->read/\n{\n\tthis->size = (int)arg0 > 0 ? arg0 : 0;\n\t@rc[execname, pid] = count();\n\t@rb[execname, pid] = sum(this->size);\n\tself->read = 0;\n}\n\nsyscall::write*:entry,\nsyscall::send*:entry\n/fds[arg0].fi_fs == \"sockfs\" || fds[arg0].fi_name == \"<socket>\"/\n{\n\t/* this under-counts writev() size (assumes iov_len is 1) */\n\tthis->size = arg2;\n\t@wc[execname, pid] = count();\n\t@wb[execname, pid] = sum(this->size);\n}\n\nprofile:::profile-100hz\n{\n\t/* will sum %CPUs on multi-core systems */\n\t@cpu[execname, pid] = count();\n}\n\nprofile:::tick-1sec\n{\n\tnormalize(@rb, 1024); normalize(@wb, 1024);\n\tsystem(\"clear\");\n\tprintf(\"  %-16s %-8s %8s %8s %10s %10s %8s\\n\", \"PROCESS\", \"PID\",\n\t    \"READS\", \"WRITES\", \"READ_KB\", \"WRITE_KB\", \"CPU\");\n\tsetopt(\"aggsortpos\", \"4\"); setopt(\"aggsortrev\", \"4\");\n\tprinta(\"  %-16s %-8d %@8d %@8d %@10d %@10d %@8d\\n\",\n\t    @rc, @wc, @rb, @wb, @cpu);\n\ttrunc(@rc); trunc(@rb); trunc(@wc); trunc(@wb); trunc(@cpu);\n}\n"
  },
  {
    "path": "Chap6/superping.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * superping.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\nmib:::rawipOutDatagrams\n/pid == $target/\n{\n\tstart = timestamp;\n}\n\nmib:::icmpInEchoReps\n/start/\n{\n\tthis->delta = (timestamp - start) / 1000;\n\tprintf(\"dtrace measured: %d us\\n\", this->delta);\n\t@a[\"\\n  ICMP packet delta average (us):\"] = avg(this->delta);\n\t@q[\"\\n  ICMP packet delta distribution (us):\"] =\n\t    lquantize(this->delta, 0, 1000000, 100);\n\tstart = 0;\n}\n"
  },
  {
    "path": "Chap6/tcp1stbyte.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcp1stbyte.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\ntcp:::connect-established\n{\n\tstart[args[1]->cs_cid] = timestamp;\n}\n\ntcp:::receive\n/start[args[1]->cs_cid] && (args[2]->ip_plength - args[4]->tcp_offset) > 0/\n{\n\t@latency[\"1st Byte Latency (ns)\", args[2]->ip_saddr] =\n\t    quantize(timestamp - start[args[1]->cs_cid]);\n\tstart[args[1]->cs_cid] = 0;\n}\n"
  },
  {
    "path": "Chap6/tcp_rwndclosed.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcp_rwndclosed.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ntcp:::send\n/ args[4]->tcp_window == 0 && (args[4]->tcp_flags & TH_RST) == 0 /\n{\n\trwndclosed[args[1]->cs_cid] = timestamp;\n\trwndrnxt[args[1]->cs_cid] = args[3]->tcps_rnxt;\n\t@numrwndclosed[args[2]->ip_daddr, args[4]->tcp_dport] = count();\n}\n\ntcp:::receive\n/ rwndclosed[args[1]->cs_cid] && args[4]->tcp_seq >= rwndrnxt[args[1]->cs_cid] /\n{\n\t@meantimeclosed[args[2]->ip_saddr, args[4]->tcp_sport] =\n\t    avg(timestamp - rwndclosed[args[1]->cs_cid]);\n\t@stddevtimeclosed[args[2]->ip_saddr, args[4]->tcp_sport] =\n\t    stddev(timestamp - rwndclosed[args[1]->cs_cid]);\n\trwndclosed[args[1]->cs_cid] = 0;\n\trwndrnxt[args[1]->cs_cid] = 0;\n}\n\nEND\n{\n\tprintf(\"%-20s %-8s %-25s %-8s %-8s\\n\",\n\t    \"Remote host\", \"Port\", \"TCP Avg RwndClosed(ns)\", \"StdDev\",\n\t    \"Num\");\n\tprinta(\"%-20s %-8d %@-25d %@-8d %@-8d\\n\", @meantimeclosed,\n\t@stddevtimeclosed, @numrwndclosed);\n}\n"
  },
  {
    "path": "Chap6/tcpaccept.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpaccept.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\ntcp:::accept-established\n{\n\t@num[args[2]->ip_saddr, args[4]->tcp_dport] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %-26s %-8s %8s\\n\", \"HOST\", \"PORT\", \"COUNT\");\n\tprinta(\"   %-26s %-8d %@8d\\n\", @num);\n}\n"
  },
  {
    "path": "Chap6/tcpacceptx.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpacceptx.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\ntcp:::accept-established\n{\n\t@num[args[2]->ip_saddr, args[4]->tcp_dport] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %-26s %-8s %8s\\n\", \"HOSTNAME\", \"PORT\", \"COUNT\");\n\tprinta(\"   %-26I %-8P %@8d\\n\", @num);\n}\n"
  },
  {
    "path": "Chap6/tcpbytes.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpbytes.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing TCP payload bytes... Hit Ctrl-C to end.\\n\");\n}\n\ntcp:::receive\n{\n\t@bytes[args[2]->ip_saddr, args[4]->tcp_dport] =\n\t    sum(args[2]->ip_plength - args[4]->tcp_offset);\n}\n\ntcp:::send\n{\n\t@bytes[args[2]->ip_daddr, args[4]->tcp_sport] =\n\t    sum(args[2]->ip_plength - args[4]->tcp_offset);\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-32s %-6s %16s\\n\", \"REMOTE\", \"LPORT\", \"BYTES\");\n\tprinta(\"  %-32s %-6d %@16d\\n\", @bytes);\n}\n"
  },
  {
    "path": "Chap6/tcpconnect.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpconnect.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\ntcp:::connect-established\n{\n\t@num[args[2]->ip_daddr, args[4]->tcp_dport] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %-26s %-8s %8s\\n\", \"HOST\", \"PORT\", \"COUNT\");\n\tprinta(\"   %-26s %-8d %@8d\\n\", @num);\n}\n"
  },
  {
    "path": "Chap6/tcpconnlat.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpconnlat.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\ntcp:::connect-request\n{\n\tstart[args[1]->cs_cid] = timestamp;\n}\n\ntcp:::connect-established\n/start[args[1]->cs_cid]/\n{\n\t@latency[\"Connect Latency (ns)\", args[2]->ip_daddr] =\n\t    quantize(timestamp - start[args[1]->cs_cid]);\n\tstart[args[1]->cs_cid] = 0;\n}\n"
  },
  {
    "path": "Chap6/tcpfbtwatch.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * tcpfbtwatch.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\n#define\tIPH_HDR_VERSION(ipha) \\\n\t((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length) >> 4)\n\n#define\tTCPS_SYN_RCVD   -1\n\n#define\tconn_tcp        conn_proto_priv.cp_tcp\n#define\tconn_lport      u_port.tcpu_ports.tcpu_lport\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s  %-24s %-24s %6s\\n\", \"TIME\", \"REMOTE\", \"LOCAL\", \"LPORT\");\n}\n\nfbt::tcp_rput_data:entry\n{\n\tself->connp = (conn_t *)arg0;\n\tself->tcp = self->connp->conn_tcp;\n\tself->mp = args[1];\n\tself->ipha = (ipha_t *)self->mp->b_rptr;\n\tself->in_tcp_rput_data = 1;\n}\n\nfbt::tcp_rput_data:entry\n/self->tcp->tcp_state == TCPS_SYN_RCVD && IPH_HDR_VERSION(self->ipha) == 4/\n{\n\tthis->src = inet_ntoa(&self->ipha->ipha_src);\n\tthis->dst = inet_ntoa(&self->ipha->ipha_dst);\n\tthis->lport = ntohs(self->connp->conn_lport);\n\tprintf(\"%-20Y  %-24s %-24s %6d\\n\", walltimestamp, this->src,\n\t    this->dst, this->lport);\n}\n\nfbt::tcp_find_pktinfo:return\n/self->in_tcp_rput_data && self->tcp->tcp_state == TCPS_SYN_RCVD &&\n\tIPH_HDR_VERSION(self->ipha) == 6/\n{\n\tthis->mp = args[1];\n\tthis->ip6h = (struct ip6_hdr *)this->mp->b_rptr;\n\tthis->src = inet_ntoa6(&this->ip6h->ip6_src);\n\tthis->dst = inet_ntoa6(&this->ip6h->ip6_dst);\n\tthis->lport = ntohs(self->connp->conn_lport);\n\tprintf(\"%-20Y  %-24s %-24s %6d\\n\", walltimestamp, this->src,\n\t    this->dst, this->lport);\n}\n\nfbt::tcp_rput_data:return\n{\n\tself->connp = 0; self->tcp = 0; self->mp = 0;\n\tself->ipha = 0; self->in_tcp_rput_data = 0;\n}\n"
  },
  {
    "path": "Chap6/tcpio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpio.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-3s %15s:%-5s      %15s:%-5s %6s %s\\n\", \"CPU\",\n\t    \"LADDR\", \"LPORT\", \"RADDR\", \"RPORT\", \"BYTES\", \"FLAGS\");\n}\n\ntcp:::send\n{\n\tthis->length = args[2]->ip_plength - args[4]->tcp_offset;\n\tprintf(\"%-3d %15s:%-5d  ->  %15s:%-5d %6d (\", cpu,\n\t    args[2]->ip_saddr, args[4]->tcp_sport,\n\t    args[2]->ip_daddr, args[4]->tcp_dport, this->length);\n}\n\ntcp:::receive\n{\n\tthis->length = args[2]->ip_plength - args[4]->tcp_offset;\n\tprintf(\"%-3d %15s:%-5d  <-  %15s:%-5d %6d (\", cpu,\n\t    args[2]->ip_daddr, args[4]->tcp_dport,\n\t    args[2]->ip_saddr, args[4]->tcp_sport, this->length);\n}\n\ntcp:::send,\ntcp:::receive\n{\n\tprintf(\"%s\", args[4]->tcp_flags & TH_FIN ? \"FIN|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_SYN ? \"SYN|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_RST ? \"RST|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_PUSH ? \"PUSH|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_ACK ? \"ACK|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_URG ? \"URG|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_ECE ? \"ECE|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_CWR ? \"CWR|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags == 0 ? \"null \" : \"\");\n\tprintf(\"\\b)\\n\");\n}\n"
  },
  {
    "path": "Chap6/tcpioshort.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpioshort.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\ntcp:::send, tcp:::receive\n{\n\tprintf(\"%15s:%-5d  ->  %15s:%-5d %d bytes\",\n\t    args[2]->ip_saddr, args[4]->tcp_sport,\n\t    args[2]->ip_daddr, args[4]->tcp_dport,\n\t    args[2]->ip_plength);\n}\n"
  },
  {
    "path": "Chap6/tcpnmap.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpnmap.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing for possible nmap scans... Hit Ctrl-C to end.\\n\");\n}\n\ntcp:::accept-refused\n{\n\t@num[\"TCP_connect()_scan\", args[2]->ip_daddr] = count();\n}\n\ntcp:::receive\n/args[4]->tcp_flags == 0/\n{\n\t@num[\"TCP_null_scan\", args[2]->ip_saddr] = count();\n}\n\ntcp:::receive\n/args[4]->tcp_flags == (TH_URG|TH_PUSH|TH_FIN)/\n{\n\t@num[\"TCP_Xmas_scan\", args[2]->ip_saddr] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"Possible scan events:\\n\\n\");\n\tprintf(\"   %-24s %-28s %8s\\n\", \"TYPE\", \"HOST\", \"COUNT\");\n\tprinta(\"   %-24s %-28s %@8d\\n\", @num);\n}\n"
  },
  {
    "path": "Chap6/tcpsize.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpsize.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\ntcp:::receive\n{\n\t@bytes[args[2]->ip_saddr, args[4]->tcp_dport] =\n\t    quantize(args[2]->ip_plength - args[4]->tcp_offset);\n}\n\ntcp:::send\n{\n\t@bytes[args[2]->ip_daddr, args[4]->tcp_sport] =\n\t    quantize(args[2]->ip_plength - args[4]->tcp_offset);\n}\n"
  },
  {
    "path": "Chap6/tcpsnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpsnoop.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%6s %6s %15s:%-5s      %15s:%-5s %6s %s\\n\",\n\t    \"TIME\", \"PID\", \"LADDR\", \"PORT\", \"RADDR\", \"PORT\", \"BYTES\", \"FLAGS\");\n}\n\ntcp:::send\n{\n\tthis->length = args[2]->ip_plength - args[4]->tcp_offset;\n\tprintf(\"%6d %6d %15s:%-5d  ->  %15s:%-5d %6d (\",\n\t    timestamp/1000, args[1]->cs_pid, args[2]->ip_saddr,\n\t    args[4]->tcp_sport, args[2]->ip_daddr, args[4]->tcp_dport,\n\t    this->length);\n}\n\ntcp:::receive\n{\n\tthis->length = args[2]->ip_plength - args[4]->tcp_offset;\n\tprintf(\"%6d %6d %15s:%-5d  <-  %15s:%-5d %6d (\",\n\t    timestamp/1000, args[1]->cs_pid, args[2]->ip_daddr,\n\t    args[4]->tcp_dport, args[2]->ip_saddr, args[4]->tcp_sport,\n\t    this->length);\n}\n\ntcp:::send,\ntcp:::receive\n{\n\tprintf(\"%s\", args[4]->tcp_flags & TH_FIN ? \"FIN|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_SYN ? \"SYN|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_RST ? \"RST|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_PUSH ? \"PUSH|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_ACK ? \"ACK|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_URG ? \"URG|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_ECE ? \"ECE|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags & TH_CWR ? \"CWR|\" : \"\");\n\tprintf(\"%s\", args[4]->tcp_flags == 0 ? \"null \" : \"\");\n\tprintf(\"\\b)\\n\");\n}\n"
  },
  {
    "path": "Chap6/tcpsnoop_snv.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * tcpsnoop_snv.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\n#include <sys/file.h>\n#include <inet/common.h>\n#include <sys/byteorder.h>\n\n/*\n * Print header\n */\ndtrace:::BEGIN\n{\n\t/* print main headers */\n\tprintf(\"%5s %6s %-15s %5s %2s %-15s %5s %5s %s\\n\",\n\t    \"UID\", \"PID\", \"LADDR\", \"LPORT\", \"DR\", \"RADDR\", \"RPORT\",\n\t    \"SIZE\", \"CMD\");\n}\n\n/*\n * TCP Process inbound connections\n *\n * 0x00200000 has been hardcoded. It was SS_TCP_FAST_ACCEPT, but was\n * renamed to SS_DIRECT around build 31.\n */\nfbt:sockfs:sotpi_accept:entry\n/(arg1 & FREAD) && (arg1 & FWRITE) && (args[0]->so_state & 0x00200000)/\n{\n\tself->sop = args[0];\n}\n\nfbt:sockfs:sotpi_create:return\n/self->sop/\n{\n\tself->nsop = (struct sonode *)arg1;\n}\n\nfbt:sockfs:sotpi_accept:return\n/self->nsop/\n{\n\tthis->tcpp = (tcp_t *)self->nsop->so_priv;\n\tself->connp = (conn_t *)this->tcpp->tcp_connp;\n\ttname[(int)self->connp] = execname;\n\ttpid[(int)self->connp] = pid;\n\ttuid[(int)self->connp] = uid;\n}\n\nfbt:sockfs:sotpi_accept:return\n{\n\tself->nsop = 0;\n\tself->sop = 0;\n}\n\n/*\n * TCP Process outbound connections\n */\nfbt:ip:tcp_connect:entry\n{\n\tthis->tcpp = (tcp_t *)arg0;\n\tself->connp = (conn_t *)this->tcpp->tcp_connp;\n\ttname[(int)self->connp] = execname;\n\ttpid[(int)self->connp] = pid;\n\ttuid[(int)self->connp] = uid;\n}\n\n/*\n * TCP Data translations\n */\nfbt:sockfs:sotpi_accept:return,\nfbt:ip:tcp_connect:return\n/self->connp/\n{\n\t/* fetch ports */\n#if defined(_BIG_ENDIAN)\n\tself->lport = self->connp->u_port.tcpu_ports.tcpu_lport;\n\tself->fport = self->connp->u_port.tcpu_ports.tcpu_fport;\n#else\n\tself->lport = BSWAP_16(self->connp->u_port.tcpu_ports.tcpu_lport);\n\tself->fport = BSWAP_16(self->connp->u_port.tcpu_ports.tcpu_fport);\n#endif\n\n\t/* fetch IPv4 addresses */\n\tthis->fad12 =\n\t    (int)self->connp->connua_v6addr.connua_faddr._S6_un._S6_u8[12];\n\tthis->fad13 =\n\t    (int)self->connp->connua_v6addr.connua_faddr._S6_un._S6_u8[13];\n\tthis->fad14 =\n\t    (int)self->connp->connua_v6addr.connua_faddr._S6_un._S6_u8[14];\n\tthis->fad15 =\n\t    (int)self->connp->connua_v6addr.connua_faddr._S6_un._S6_u8[15];\n\tthis->lad12 =\n\t    (int)self->connp->connua_v6addr.connua_laddr._S6_un._S6_u8[12];\n\tthis->lad13 =\n\t    (int)self->connp->connua_v6addr.connua_laddr._S6_un._S6_u8[13];\n\tthis->lad14 =\n\t    (int)self->connp->connua_v6addr.connua_laddr._S6_un._S6_u8[14];\n\tthis->lad15 =\n\t    (int)self->connp->connua_v6addr.connua_laddr._S6_un._S6_u8[15];\n\n\t/* convert type for use with lltostr() */\n\tthis->fad12 = this->fad12 < 0 ? 256 + this->fad12 : this->fad12;\n\tthis->fad13 = this->fad13 < 0 ? 256 + this->fad13 : this->fad13;\n\tthis->fad14 = this->fad14 < 0 ? 256 + this->fad14 : this->fad14;\n\tthis->fad15 = this->fad15 < 0 ? 256 + this->fad15 : this->fad15;\n\tthis->lad12 = this->lad12 < 0 ? 256 + this->lad12 : this->lad12;\n\tthis->lad13 = this->lad13 < 0 ? 256 + this->lad13 : this->lad13;\n\tthis->lad14 = this->lad14 < 0 ? 256 + this->lad14 : this->lad14;\n\tthis->lad15 = this->lad15 < 0 ? 256 + this->lad15 : this->lad15;\n\n\t/* stringify addresses */\n\tself->faddr = strjoin(lltostr(this->fad12), \".\");\n\tself->faddr = strjoin(self->faddr, strjoin(lltostr(this->fad13), \".\"));\n\tself->faddr = strjoin(self->faddr, strjoin(lltostr(this->fad14), \".\"));\n\tself->faddr = strjoin(self->faddr, lltostr(this->fad15 + 0));\n\tself->laddr = strjoin(lltostr(this->lad12), \".\");\n\tself->laddr = strjoin(self->laddr, strjoin(lltostr(this->lad13), \".\"));\n\tself->laddr = strjoin(self->laddr, strjoin(lltostr(this->lad14), \".\"));\n\tself->laddr = strjoin(self->laddr, lltostr(this->lad15 + 0));\n\n\t/* fix direction and save values */\n\ttladdr[(int)self->connp] = self->laddr;\n\ttfaddr[(int)self->connp] = self->faddr;\n\ttlport[(int)self->connp] = self->lport;\n\ttfport[(int)self->connp] = self->fport;\n\n\t/* all systems go */\n\ttok[(int)self->connp] = 1;\n}\n\n/*\n * TCP Clear connp\n */\nfbt:ip:tcp_get_conn:return\n{\n\t/* Q_TO_CONN */\n\tthis->connp = (conn_t *)arg1;\n\ttok[(int)this->connp] = 0;\n\ttpid[(int)this->connp] = 0;\n\ttuid[(int)this->connp] = 0;\n\ttname[(int)this->connp] = 0;\n}\n\n/*\n * TCP Process \"port closed\"\n */\nfbt:ip:tcp_xmit_early_reset:entry\n{\n\tthis->queuep = args[7]->tcps_g_q;\n\tthis->connp = (conn_t *)this->queuep->q_ptr;\n\tthis->tcpp = (tcp_t *)this->connp->conn_tcp;\n\n\t/* split addresses */\n\tthis->ipha = (ipha_t *)args[1]->b_rptr;\n\tthis->fad15 = (this->ipha->ipha_src & 0xff000000) >> 24;\n\tthis->fad14 = (this->ipha->ipha_src & 0x00ff0000) >> 16;\n\tthis->fad13 = (this->ipha->ipha_src & 0x0000ff00) >> 8;\n\tthis->fad12 = (this->ipha->ipha_src & 0x000000ff);\n\tthis->lad15 = (this->ipha->ipha_dst & 0xff000000) >> 24;\n\tthis->lad14 = (this->ipha->ipha_dst & 0x00ff0000) >> 16;\n\tthis->lad13 = (this->ipha->ipha_dst & 0x0000ff00) >> 8;\n\tthis->lad12 = (this->ipha->ipha_dst & 0x000000ff);\n\n\t/* stringify addresses */\n\tself->faddr = strjoin(lltostr(this->fad12), \".\");\n\tself->faddr = strjoin(self->faddr, strjoin(lltostr(this->fad13), \".\"));\n\tself->faddr = strjoin(self->faddr, strjoin(lltostr(this->fad14), \".\"));\n\tself->faddr = strjoin(self->faddr, lltostr(this->fad15 + 0));\n\tself->laddr = strjoin(lltostr(this->lad12), \".\");\n\tself->laddr = strjoin(self->laddr, strjoin(lltostr(this->lad13), \".\"));\n\tself->laddr = strjoin(self->laddr, strjoin(lltostr(this->lad14), \".\"));\n\tself->laddr = strjoin(self->laddr, lltostr(this->lad15 + 0));\n\n\tself->reset = 1;\n}\n\n/*\n * TCP Fetch \"port closed\" ports\n */\nfbt:ip:tcp_xchg:entry\n/self->reset/\n{\n#if defined(_BIG_ENDIAN)\n\tself->lport = (uint16_t)arg0;\n\tself->fport = (uint16_t)arg1;\n#else\n\tself->lport = BSWAP_16((uint16_t)arg0);\n\tself->fport = BSWAP_16((uint16_t)arg1);\n#endif\n\tself->lport = BE16_TO_U16(arg0);\n\tself->fport = BE16_TO_U16(arg1);\n}\n\n/*\n * TCP Print \"port closed\"\n */\nfbt:ip:tcp_xmit_early_reset:return\n{\n\tself->name = \"<closed>\";\n\tself->pid = 0;\n\tself->uid = 0;\n\tself->size = 54;        /* should check trailers */\n\tself->dir = \"<-\";\n\tprintf(\"%5d %6d %-15s %5d %2s %-15s %5d %5d %s\\n\",\n\t    self->uid, self->pid, self->laddr, self->lport, self->dir,\n\t    self->faddr, self->fport, self->size, self->name);\n\tself->dir = \"->\";\n\tprintf(\"%5d %6d %-15s %5d %2s %-15s %5d %5d %s\\n\",\n\t    self->uid, self->pid, self->laddr, self->lport, self->dir,\n\t    self->faddr, self->fport, self->size, self->name);\n\tself->reset = 0;\n\tself->size = 0;\n\tself->name = 0;\n}\n\n/*\n * TCP Process Write\n */\nfbt:ip:tcp_send_data:entry\n{\n\tself->conn_p = (conn_t *)args[0]->tcp_connp;\n}\n\nfbt:ip:tcp_send_data:entry\n/tok[(int)self->conn_p]/\n{\n\tself->dir = \"->\";\n\tself->size = msgdsize(args[2]) + 14;    /* should check trailers */\n\tself->uid = tuid[(int)self->conn_p];\n\tself->laddr = tladdr[(int)self->conn_p];\n\tself->faddr = tfaddr[(int)self->conn_p];\n\tself->lport = tlport[(int)self->conn_p];\n\tself->fport = tfport[(int)self->conn_p];\n\tself->ok = 2;\n\n\t/* follow inetd -> in.* transitions */\n\tself->name = pid && (tname[(int)self->conn_p] == \"inetd\") ?\n\t    execname : tname[(int)self->conn_p];\n\tself->pid = pid && (tname[(int)self->conn_p] == \"inetd\") ?\n\t    pid : tpid[(int)self->conn_p];\n\ttname[(int)self->conn_p] = self->name;\n\ttpid[(int)self->conn_p] = self->pid;\n}\n\n/*\n * TCP Process Read\n */\nfbt:ip:tcp_rput_data:entry\n{\n\tself->conn_p = (conn_t *)arg0;\n\tself->size = msgdsize(args[1]) + 14;    /* should check trailers */\n}\n\nfbt:ip:tcp_rput_data:entry\n/tok[(int)self->conn_p]/\n{\n\tself->dir = \"<-\";\n\tself->uid = tuid[(int)self->conn_p];\n\tself->laddr = tladdr[(int)self->conn_p];\n\tself->faddr = tfaddr[(int)self->conn_p];\n\tself->lport = tlport[(int)self->conn_p];\n\tself->fport = tfport[(int)self->conn_p];\n\tself->ok = 2;\n\n\t/* follow inetd -> in.* transitions */\n\tself->name = pid && (tname[(int)self->conn_p] == \"inetd\") ?\n\t    execname : tname[(int)self->conn_p];\n\tself->pid = pid && (tname[(int)self->conn_p] == \"inetd\") ?\n\t    pid : tpid[(int)self->conn_p];\n\ttname[(int)self->conn_p] = self->name;\n\ttpid[(int)self->conn_p] = self->pid;\n}\n\n/*\n * TCP Complete printing outbound handshake\n */\nfbt:ip:tcp_connect:return\n/self->connp/\n{\n\tself->name = tname[(int)self->connp];\n\tself->pid = tpid[(int)self->connp];\n\tself->uid = tuid[(int)self->connp];\n\tself->size = 54;        /* should check trailers */\n\tself->dir = \"->\";\n\t/* this packet occured before connp was fully established */\n\tprintf(\"%5d %6d %-15s %5d %2s %-15s %5d %5d %s\\n\",\n\t    self->uid, self->pid, self->laddr, self->lport, self->dir,\n\t    self->faddr, self->fport, self->size, self->name);\n}\n\n/*\n * TCP Complete printing inbound handshake\n */\nfbt:sockfs:sotpi_accept:return\n/self->connp/\n{\n\tself->name = tname[(int)self->connp];\n\tself->pid = tpid[(int)self->connp];\n\tself->uid = tuid[(int)self->connp];\n\tself->size = 54;        /* should check trailers */\n\t/* these packets occured before connp was fully established */\n\tself->dir = \"<-\";\n\tprintf(\"%5d %6d %-15s %5d %2s %-15s %5d %5d %s\\n\",\n\t    self->uid, self->pid, self->laddr, self->lport, self->dir,\n\t    self->faddr, self->fport, self->size, self->name);\n\tself->dir = \"->\";\n\tprintf(\"%5d %6d %-15s %5d %2s %-15s %5d %5d %s\\n\",\n\t    self->uid, self->pid, self->laddr, self->lport, self->dir,\n\t    self->faddr, self->fport, self->size, self->name);\n\tself->dir = \"<-\";\n\tprintf(\"%5d %6d %-15s %5d %2s %-15s %5d %5d %s\\n\",\n\t    self->uid, self->pid, self->laddr, self->lport, self->dir,\n\t    self->faddr, self->fport, self->size, self->name);\n}\n\n/*\n * Print output\n */\nfbt:ip:tcp_send_data:entry,\nfbt:ip:tcp_rput_data:entry\n/self->ok == 2/\n{\n\t/* print output line */\n\tprintf(\"%5d %6d %-15s %5d %2s %-15s %5d %5d %s\\n\",\n\t    self->uid, self->pid, self->laddr, self->lport, self->dir,\n\t    self->faddr, self->fport, self->size, self->name);\n}\n\n/*\n * TCP Clear connect variables\n */\nfbt:sockfs:sotpi_accept:return,\nfbt:ip:tcp_connect:return\n/self->connp/\n{\n\tself->faddr = 0;\n\tself->laddr = 0;\n\tself->fport = 0;\n\tself->lport = 0;\n\tself->connp = 0;\n\tself->name = 0;\n\tself->pid = 0;\n\tself->uid = 0;\n}\n\n/*\n * TCP Clear r/w variables\n */\nfbt:ip:tcp_send_data:entry,\nfbt:ip:tcp_rput_data:entry\n{\n\tself->ok = 0;\n\tself->dir = 0;\n\tself->uid = 0;\n\tself->pid = 0;\n\tself->size = 0;\n\tself->name = 0;\n\tself->lport = 0;\n\tself->fport = 0;\n\tself->laddr = 0;\n\tself->faddr = 0;\n\tself->conn_p = 0;\n}\n"
  },
  {
    "path": "Chap6/tcpstat.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpstat.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN                  { LINES = 20; line = 0; }\n\nprofile:::tick-1sec\n/--line <= 0/\n{\n\tprintf(\"  TCP bytes:  %6s %12s %12s %12s %12s\\n\",\n\t    \"out\", \"outRetrans\", \"in\", \"inDup\", \"inUnorder\");\n\tline = LINES;\n}\nmib:::tcpOutDataBytes, mib:::tcpRetransBytes, mib:::tcpInDataInorderBytes,\nmib:::tcpInDataDupBytes, mib:::tcpInDataUnorderBytes\n{\n\t/* some of these probes can return -1 */\n\tthis->bytes = (int)arg0 > 0 ? arg0 : 0;\n}\n\nmib:::tcpOutDataBytes           { @out = sum(this->bytes);   }\nmib:::tcpRetransBytes           { @outRe = sum(this->bytes); }\nmib:::tcpInDataInorderBytes     { @in = sum(this->bytes);    }\nmib:::tcpInDataDupBytes         { @inDup = sum(this->bytes); }\nmib:::tcpInDataUnorderBytes     { @inUn = sum(this->bytes);  }\n\nprofile:::tick-1sec\n{\n\tprinta(\"        %@12d %@12d %@12d %@12d %@12d\\n\",\n\t    @out, @outRe, @in, @inDup, @inUn);\n\tclear(@out); clear(@outRe); clear(@in); clear(@inDup); clear(@inUn);\n}\n"
  },
  {
    "path": "Chap6/tcpstate.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpstate.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\ndtrace:::BEGIN\n{\n\tprintf(\" %3s %12s  %-20s    %-20s\\n\", \"CPU\", \"DELTA(us)\", \"OLD\", \"NEW\");\n\tlast = timestamp;\n}\n\ntcp:::state-change\n{\n\tthis->elapsed = (timestamp - last) / 1000;\n\tprintf(\" %3d %12d  %-20s -> %-20s\\n\", cpu, this->elapsed,\n\t    tcp_state_string[args[5]->tcps_state],\n\t    tcp_state_string[args[3]->tcps_state]);\n\tlast = timestamp;\n}\n"
  },
  {
    "path": "Chap6/tcpwatch.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tcpwatch.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s  %-24s %-24s %6s\\n\", \"TIME\", \"REMOTE\", \"LOCAL\", \"LPORT\");\n}\n\ntcp:::accept-established\n{\n\tprintf(\"%-20Y  %-24s %-24s %6d\\n\", walltimestamp,\n\t    args[2]->ip_saddr, args[2]->ip_daddr, args[4]->tcp_dport);\n}\n"
  },
  {
    "path": "Chap6/udpio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * udpio.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-3s  %15s:%-5s      %15s:%-5s  %6s\\n\", \"CPU\",\n\t    \"LADDR\", \"PORT\", \"RADDR\", \"PORT\", \"IPLEN\");\n}\n\nudp:::send\n{\n\tprintf(\"%-3d  %15s:%-5d  ->  %15s:%-5d  %6d\\n\", cpu,\n\t    args[2]->ip_saddr, args[4]->udp_sport,\n\t    args[2]->ip_daddr, args[4]->udp_dport, args[2]->ip_plength);\n}\n\nudp:::receive\n{\n\tprintf(\"%-3d  %15s:%-5d  <-  %15s:%-5d  %6d\\n\", cpu,\n\t    args[2]->ip_daddr, args[4]->udp_dport,\n\t    args[2]->ip_saddr, args[4]->udp_sport, args[2]->ip_plength);\n}\n"
  },
  {
    "path": "Chap6/udpstat.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * udpstat.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tLINES = 20; line = 0;\n}\n\nprofile:::tick-1sec\n/--line <= 0/\n{\n\tprintf(\"  UDP:    %12s %12s %12s %12s %12s\\n\", \"out(bytes)\",\n\t    \"outErrors\", \"in(bytes)\", \"inErrors\", \"noPort\");\n\tline = LINES;\n}\n\nmib:::udp*InDatagrams   { @in = sum(arg0);      }\nmib:::udp*OutDatagrams  { @out = sum(arg0);     }\nmib:::udpInErrors       { @inErr = sum(arg0);   }\nmib:::udpInCksumErrs    { @inErr = sum(arg0);   }\nmib:::udpOutErrors      { @outErr = sum(arg0);  }\nmib:::udpNoPorts        { @noPort = sum(arg0);  }\n\nprofile:::tick-1sec\n{\n\tprinta(\"          %@12d %@12d %@12d %@12d %@12d\\n\",\n\t    @out, @outErr, @in, @inErr, @noPort);\n\tclear(@out); clear(@outErr); clear(@in); clear(@inErr); clear(@noPort);\n}\n"
  },
  {
    "path": "Chap6/xdrshow.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * xdrshow.d\n *\n * Example script from Chapter 6 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing XDR calls... Hit Ctrl-C to end.\\n\");\n}\n\nfbt::xdr_*:entry\n{\n\t@num[execname, func(caller), probefunc] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\" %-12s %-28s %-25s %9s\\n\", \"PROCESS\", \"CALLER\", \"XDR_FUNCTION\",\n\t    \"COUNT\");\n\tprinta(\" %-12.12s %-28a %-25s %@9d\\n\", @num);\n}\n"
  },
  {
    "path": "Chap7/cifserrors.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cifserrors.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\t/*\n\t * These are some of over 500 NT_STATES_* error codes defined in\n\t * uts/common/smbsrv/ntstatus.h.  For more detail see MSDN and\n\t * ntstatus.h in the MS DDK.\n\t */\n\tntstatus[0] = \"SUCCESS\";\n\tntstatus[1] = \"UNSUCCESSFUL\";\n\tntstatus[2] = \"NOT_IMPLEMENTED\";\n\tntstatus[5] = \"ACCESS_VIOLATION\";\n\tntstatus[15] = \"NO_SUCH_FILE\";\n\tntstatus[17] = \"END_OF_FILE\";\n\tntstatus[23] = \"NO_MEMORY\";\n\tntstatus[29] = \"ILLEGAL_INSTRUCTION\";\n\tntstatus[34] = \"ACCESS_DENIED\";\n\tntstatus[50] = \"DISK_CORRUPT_ERROR\";\n\tntstatus[61] = \"DATA_ERROR\";\n\tntstatus[62] = \"CRC_ERROR\";\n\tntstatus[68] = \"QUOTA_EXCEEDED\";\n\tntstatus[127] = \"DISK_FULL\";\n\tntstatus[152] = \"FILE_INVALID\";\n\tntstatus[186] = \"FILE_IS_A_DIRECTORY\";\n\tntstatus[258] = \"FILE_CORRUPT_ERROR\";\n\tntstatus[259] = \"NOT_A_DIRECTORY\";\n\tntstatus[291] = \"FILE_DELETED\";\n\t/* ...etc... */\n\n\tprintf(\" %-24s %3s %-19s %-16s %s\\n\", \"CIFS EVENT\", \"ERR\", \"CODE\",\n\t    \"CLIENT\", \"PATHNAME\");\n}\n\nsmb:::op-*-start, smb:::op-*-done\n/(this->sr = (struct smb_request *)arg0) && this->sr->smb_error.status != 0/\n{\n\tthis->err = this->sr->smb_error.status;\n\tthis->str = ntstatus[this->err] != NULL ? ntstatus[this->err] : \"?\";\n\t    printf(\" %-24s %3d %-19s %-16s %s\\n\", probename, this->err,\n\tthis->str, args[0]->ci_remote, args[1]->soi_curpath);\n}\n"
  },
  {
    "path": "Chap7/cifsfbtnofile.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cifsfbtnofile.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\t/* a few likely codes are included from ntstatus.h */\n\tntstatus[0] = \"SUCCESS\";\n\tntstatus[1] = \"UNSUCCESSFUL\";\n\tntstatus[15] = \"NO_SUCH_FILE\";\n\tntstatus[186] = \"FILE_IS_A_DIR\";\n\n\tprintf(\" %-16s %3s %-13s %s\\n\", \"CLIENT\", \"ERR\", \"ERROR\", \"PATHNAME\");\n}\n\nfbt::smb*find_first*:entry  { self->in_find_first = 1; }\nfbt::smb*find_first*:return { self->in_find_first = 0; }\n\n/* assume smb_odir_open() checks relevant path during find_entries */\nfbt::smb_odir_open:entry\n/self->in_find_first/\n{\n\tself->sr = args[0];\n\tself->path = args[1];\n}\n\n/* assume smbsr_set_error() will set relevant error during find_entries */\nfbt::smbsr_set_error:entry\n/self->in_find_first/\n{\n\tself->err = args[1]->status;\n}\n\n/* if an error was previously seen during find_entries, print cached details */\nfbt::smb*find_entries:return\n/self->sr && self->err/\n{\n\tthis->str = ntstatus[self->err] != NULL ? ntstatus[self->err] : \"?\";\n\tthis->remote = self->sr->session->ipaddr.a_family == AF_INET ?\n\t    inet_ntoa(&self->sr->session->ipaddr.au_addr.au_ipv4) :\n\tinet_ntoa6(&self->sr->session->ipaddr.au_addr.au_ipv6);\n\tprintf(\" %-16s %3d %-13s %s%s\\n\", this->remote, self->err, this->str,\n\t    self->sr->tid_tree->t_sharename, stringof(self->path));\n}\n\nfbt::smb*find_entries:return\n/self->sr/\n{\n\tself->sr = 0; self->path = 0; self->err = 0;\n}\n"
  },
  {
    "path": "Chap7/cifsfileio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cifsfileio.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nsmb:::op-Read-done, smb:::op-ReadX-done\n{\n\t@readbytes[args[1]->soi_curpath] = sum(args[2]->soa_count);\n}\n\nsmb:::op-Write-done, smb:::op-WriteX-done\n{\n\t@writebytes[args[1]->soi_curpath] = sum(args[2]->soa_count);\n}\n\ndtrace:::END\n{\n\tprintf(\"\\n%12s %12s  %s\\n\", \"Rbytes\", \"Wbytes\", \"Pathname\");\n\tprinta(\"%@12d %@12d  %s\\n\", @readbytes, @writebytes);\n}\n"
  },
  {
    "path": "Chap7/cifsops.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cifsops.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing CIFS operations... Interval 5 secs.\\n\");\n}\n\nsmb:::op-*\n{\n\t@ops[args[0]->ci_remote, probename] = count();\n}\n\nprofile:::tick-5sec,\ndtrace:::END\n{\n\tprintf(\"\\n   %-32s %-30s %8s\\n\", \"Client\", \"Operation\", \"Count\");\n\tprinta(\"   %-32s %-30s %@8d\\n\", @ops);\n\ttrunc(@ops);\n}\n"
  },
  {
    "path": "Chap7/cifsrwsnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cifsrwsnoop.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-16s %-18s %2s %-10s %6s %s\\n\", \"TIME(us)\",\n\t    \"CLIENT\", \"OP\", \"OFFSET(KB)\", \"BYTES\", \"PATHNAME\");\n}\n\nsmb:::op-Read-done, smb:::op-ReadX-done\n{\n\tthis->dir = \"R\";\n}\n\nsmb:::op-Write-done, smb:::op-WriteX-done\n{\n\tthis->dir = \"W\";\n}\n\nsmb:::op-Read-done, smb:::op-ReadX-done,\nsmb:::op-Write-done, smb:::op-WriteX-done\n{\n\tprintf(\"%-16d %-18s %2s %-10d %6d %s\\n\", timestamp / 1000,\n\t    args[0]->ci_remote, this->dir, args[2]->soa_offset / 1024,\n\t    args[2]->soa_count, args[1]->soi_curpath);\n}\n"
  },
  {
    "path": "Chap7/cifsrwtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * cifsrwtime.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ninline int TOP_FILES = 10;\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nsmb:::op-Read-start, smb:::op-ReadX-start,\nsmb:::op-Write-start, smb:::op-WriteX-start\n{\n\t/* currently the done event fires in the same thread as start */\n\tself->start = timestamp;\n}\n\nsmb:::op-Read-done, smb:::op-ReadX-done   { this->dir = \"read\"; }\nsmb:::op-Write-done, smb:::op-WriteX-done { this->dir = \"write\"; }\n\nsmb:::op-Read-done, smb:::op-ReadX-done,\nsmb:::op-Write-done, smb:::op-WriteX-done\n/self->start/\n{\n\tthis->elapsed = timestamp - self->start;\n\t@rw[this->dir] = quantize(this->elapsed / 1000);\n\t@host[args[0]->ci_remote] = sum(this->elapsed);\n\t@file[args[1]->soi_curpath] = sum(this->elapsed);\n\tself->start = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"CIFS read/write distributions (us):\\n\");\n\tprinta(@rw);\n\n\tprintf(\"\\nCIFS read/write by host (total us):\\n\");\n\tnormalize(@host, 1000);\n\tprinta(@host);\n\n\tprintf(\"\\nCIFS read/write top %d files (total us):\\n\", TOP_FILES);\n\tnormalize(@file, 1000);\n\ttrunc(@file, TOP_FILES);\n\tprinta(@file);\n}\n"
  },
  {
    "path": "Chap7/dnsgetname.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * dnsgetname.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ntypedef struct dns_name {\n\tunsigned int\t\t\tmagic;\n\tunsigned char *\t\t\tndata;\n\t/* truncated */\n} dns_name_t;\n\npid$target::getname:entry\n{\n\tself->arg0 = arg0;\n}\n\npid$target::getname:return\n/self->arg0/\n{\n\tthis->name = (dns_name_t *)copyin(self->arg0, sizeof (dns_name_t));\n\tprintf(\"%s\\n\", copyinstr((uintptr_t)this->name->ndata));\n\tself->arg0 = 0;\n}\n"
  },
  {
    "path": "Chap7/fcerror.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * fcerror.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %-12s %-12s %-12s %-12s\\n\", \"TIME\", \"STATE\", \"REASON\",\n\t    \"ACTION\", \"EXPLANATION\");\n}\n\nfbt::fctl_pkt_error:entry\n{\n\tself->state = args[1];\n\tself->reason = args[2];\n\tself->action = args[3];\n\tself->expln = args[4];\n}\n\nfbt::fctl_pkt_error:entry\n/self->state/\n{\n\tprintf(\"%-20Y %-12s %-12s %-12s %-12s\\n\", walltimestamp,\n\t    stringof(*self->state), stringof(*self->reason),\n\t    stringof(*self->action), stringof(*self->expln));\n\n\tself->state = 0; self->reason = 0; self->action = 0; self->expln = 0;\n}\n"
  },
  {
    "path": "Chap7/fcwho.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * fcwho.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing FC... Hit Ctrl-C to end.\\n\");\n}\n\nfc:::\n{\n\t@events[args[0]->ci_remote, probename] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %-26s %14s %8s\\n\", \"REMOTE IP\", \"FC EVENT\", \"COUNT\");\n\tprinta(\"   %-26s %14s %@8d\\n\", @events);\n}\n"
  },
  {
    "path": "Chap7/ftpdfileio.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * ftpdfileio.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nftp*:::transfer-done\n{\n\t@[args[1]->fti_cmd, args[1]->fti_pathname] = sum(args[1]->fti_nbytes);\n}\n\ndtrace:::END\n{\n\tprintf(\"\\n%8s %12s  %s\\n\", \"DIR\", \"BYTES\", \"PATHNAME\");\n\tprinta(\"%8s %@12d  %s\\n\", @);\n}\n"
  },
  {
    "path": "Chap7/ftpdxfer.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * ftpdxfer.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %-8s %9s %-5s %-6s %s\\n\", \"CLIENT\", \"USER\", \"LAT(us)\",\n\t    \"DIR\", \"BYTES\", \"PATH\");\n}\n\nftp*:::transfer-start\n{\n\tself->start = timestamp;\n}\n\nftp*:::transfer-done\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\tprintf(\"%-20s %-8s %9d %-5s %-6d %s\\n\", args[0]->ci_remote,\n\t    args[1]->fti_user, this->delta, args[1]->fti_cmd,\n\t    args[1]->fti_nbytes, args[1]->fti_pathname);\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap7/getaddrinfo.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * getaddrinfo.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s  %-12s %s\\n\", \"TIME\", \"LATENCY(ms)\", \"HOST\");\n}\n\npid$target::getaddrinfo:entry\n{\n\tself->host = copyinstr(arg0);\n\tself->start = timestamp;\n}\n\npid$target::getaddrinfo:return\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000000;\n\tprintf(\"%-20Y  %-12d %s\\n\", walltimestamp, this->delta, self->host);\n\tself->host = 0;\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap7/httpclients.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * httpclients.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing... output every 10 seconds, or Ctrl-C.\\n\");\n}\n\nhttp*:::request-done\n{\n\t@rbytes[args[0]->ci_remote] = sum(args[1]->hri_bytesread);\n\t@wbytes[args[0]->ci_remote] = sum(args[1]->hri_byteswritten);\n}\n\nprofile:::tick-10sec,\ndtrace:::END\n{\n\tnormalize(@rbytes, 1024);\n\tnormalize(@wbytes, 1024);\n\tprintf(\"\\n %-32s %10s %10s\\n\", \"HTTP CLIENT\", \"FROM(KB)\", \"TO(KB)\");\n\tprinta(\" %-32s %@10d %@10d\\n\", @rbytes, @wbytes);\n\ttrunc(@rbytes);\n\ttrunc(@wbytes);\n}\n"
  },
  {
    "path": "Chap7/httpdurls.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * httpdurls.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ninline string WEB_SERVER_PROCESS_NAME = \"httpd\";\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing GET from %s processes... Hit Ctrl-C to end.\\n\",\n\t    WEB_SERVER_PROCESS_NAME);\n}\n\nsyscall::read:entry\n/execname == WEB_SERVER_PROCESS_NAME/\n{\n\tself->buf = arg1;\n}\n\nsyscall::read:return\n/self->buf && arg1 > 10/\n{\n\tthis->req = (char *)copyin(self->buf, arg1);\n\tthis->get = strstr(this->req, \"GET\") != NULL;\n}\n\nsyscall::read:return\n/self->buf && this->get/\n{\n\tthis->line = strtok(this->req, \"\\r\");\n\tthis->word0 = this->line != NULL ? strtok(this->line, \" \") : \"\";\n\tthis->word1 = this->line != NULL ? strtok(NULL, \" \") : \"\";\n\tthis->word2 = this->line != NULL ? strtok(NULL, \" \") : \"\";\n}\n\nsyscall::read:return\n/this->word0 != NULL && this->word1 != NULL && this->word2 != NULL &&\n\tthis->word0 == \"GET\"/\n{\n\t@[stringof(this->word2), stringof(this->word1)] = count();\n}\n\nsyscall::read:return\n{\n\tself->buf = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-10s %-54s %10s\\n\", \"PROTOCOL\", \"URL\", \"COUNT\");\n\tprinta(\"  %-10s %-54s %@10d\\n\", @);\n}\n"
  },
  {
    "path": "Chap7/httperrors.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * httperrors.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing HTTP errors... Hit Ctrl-C for report.\\n\");\n}\n\nhttp*:::request-done\n/args[1]->hri_respcode >= 400 && args[1]->hri_respcode < 600/\n{\n\t@[args[0]->ci_remote, args[1]->hri_respcode,\n\t    args[1]->hri_method, args[1]->hri_uri] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"%8s  %-16s %-4s %-6s %s\\n\", \"COUNT\", \"CLIENT\", \"CODE\",\n\t    \"METHOD\", \"URI\");\n\tprinta(\"%@8d  %-16s %-4d %-6s %s\\n\", @);\n}\n"
  },
  {
    "path": "Chap7/httpio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * httpio.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing HTTP... Hit Ctrl-C for report.\\n\");\n}\n\nhttp*:::request-done\n{\n\t@[\"received bytes\"] = quantize(args[1]->hri_bytesread);\n\t@[\"sent bytes\"] = quantize(args[1]->hri_byteswritten);\n}\n"
  },
  {
    "path": "Chap7/iscsicmds.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iscsicmds.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nstring scsi_cmd[uchar_t];\n\ndtrace:::BEGIN\n{\n\t/*\n\t * The following was generated from the SCSI_CMDS_KEY_STRINGS\n\t * definitions in /usr/include/sys/scsi/generic/commands.h using sed.\n\t */\n\tscsi_cmd[0x00] = \"test_unit_ready\";\n\tscsi_cmd[0x01] = \"rezero/rewind\";\n\tscsi_cmd[0x03] = \"request_sense\";\n\tscsi_cmd[0x04] = \"format\";\n\tscsi_cmd[0x05] = \"read_block_limits\";\n\tscsi_cmd[0x07] = \"reassign\";\n\tscsi_cmd[0x08] = \"read\";\n\tscsi_cmd[0x0a] = \"write\";\n\tscsi_cmd[0x0b] = \"seek\";\n\tscsi_cmd[0x0f] = \"read_reverse\";\n\tscsi_cmd[0x10] = \"write_file_mark\";\n\tscsi_cmd[0x11] = \"space\";\n\tscsi_cmd[0x12] = \"inquiry\";\n\tscsi_cmd[0x13] = \"verify\";\n\tscsi_cmd[0x14] = \"recover_buffer_data\";\n\tscsi_cmd[0x15] = \"mode_select\";\n\tscsi_cmd[0x16] = \"reserve\";\n\tscsi_cmd[0x17] = \"release\";\n\tscsi_cmd[0x18] = \"copy\";\n\tscsi_cmd[0x19] = \"erase_tape\";\n\tscsi_cmd[0x1a] = \"mode_sense\";\n\tscsi_cmd[0x1b] = \"load/start/stop\";\n\tscsi_cmd[0x1c] = \"get_diagnostic_results\";\n\tscsi_cmd[0x1d] = \"send_diagnostic_command\";\n\tscsi_cmd[0x1e] = \"door_lock\";\n\tscsi_cmd[0x23] = \"read_format_capacity\";\n\tscsi_cmd[0x25] = \"read_capacity\";\n\tscsi_cmd[0x28] = \"read(10)\";\n\tscsi_cmd[0x2a] = \"write(10)\";\n\tscsi_cmd[0x2b] = \"seek(10)\";\n\tscsi_cmd[0x2e] = \"write_verify\";\n\tscsi_cmd[0x2f] = \"verify(10)\";\n\tscsi_cmd[0x30] = \"search_data_high\";\n\tscsi_cmd[0x31] = \"search_data_equal\";\n\tscsi_cmd[0x32] = \"search_data_low\";\n\tscsi_cmd[0x33] = \"set_limits\";\n\tscsi_cmd[0x34] = \"read_position\";\n\tscsi_cmd[0x35] = \"synchronize_cache\";\n\tscsi_cmd[0x37] = \"read_defect_data\";\n\tscsi_cmd[0x39] = \"compare\";\n\tscsi_cmd[0x3a] = \"copy_verify\";\n\tscsi_cmd[0x3b] = \"write_buffer\";\n\tscsi_cmd[0x3c] = \"read_buffer\";\n\tscsi_cmd[0x3e] = \"read_long\";\n\tscsi_cmd[0x3f] = \"write_long\";\n\tscsi_cmd[0x44] = \"report_densities/read_header\";\n\tscsi_cmd[0x4c] = \"log_select\";\n\tscsi_cmd[0x4d] = \"log_sense\";\n\tscsi_cmd[0x55] = \"mode_select(10)\";\n\tscsi_cmd[0x56] = \"reserve(10)\";\n\tscsi_cmd[0x57] = \"release(10)\";\n\tscsi_cmd[0x5a] = \"mode_sense(10)\";\n\tscsi_cmd[0x5e] = \"persistent_reserve_in\";\n\tscsi_cmd[0x5f] = \"persistent_reserve_out\";\n\tscsi_cmd[0x80] = \"write_file_mark(16)\";\n\tscsi_cmd[0x81] = \"read_reverse(16)\";\n\tscsi_cmd[0x83] = \"extended_copy\";\n\tscsi_cmd[0x88] = \"read(16)\";\n\tscsi_cmd[0x8a] = \"write(16)\";\n\tscsi_cmd[0x8c] = \"read_attribute\";\n\tscsi_cmd[0x8d] = \"write_attribute\";\n\tscsi_cmd[0x8f] = \"verify(16)\";\n\tscsi_cmd[0x91] = \"space(16)\";\n\tscsi_cmd[0x92] = \"locate(16)\";\n\tscsi_cmd[0x9e] = \"service_action_in(16)\";\n\tscsi_cmd[0x9f] = \"service_action_out(16)\";\n\tscsi_cmd[0xa0] = \"report_luns\";\n\tscsi_cmd[0xa2] = \"security_protocol_in\";\n\tscsi_cmd[0xa3] = \"maintenance_in\";\n\tscsi_cmd[0xa4] = \"maintenance_out\";\n\tscsi_cmd[0xa8] = \"read(12)\";\n\tscsi_cmd[0xa9] = \"service_action_out(12)\";\n\tscsi_cmd[0xaa] = \"write(12)\";\n\tscsi_cmd[0xab] = \"service_action_in(12)\";\n\tscsi_cmd[0xac] = \"get_performance\";\n\tscsi_cmd[0xAF] = \"verify(12)\";\n\tscsi_cmd[0xb5] = \"security_protocol_out\";\n\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\niscsi:::scsi-command\n{\n\tthis->code = *args[2]->ic_cdb;\n\tthis->cmd = scsi_cmd[this->code] != NULL ?\n\t    scsi_cmd[this->code] : lltostr(this->code);\n\t@[args[0]->ci_remote, this->cmd] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"  %-24s %-36s  %s\\n\", \"iSCSI CLIENT\", \"SCSI COMMAND\", \"COUNT\");\n\tprinta(\"  %-24s %-36s  %@d\\n\", @);\n}\n"
  },
  {
    "path": "Chap7/iscsirwsnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iscsirwsnoop.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-16s %-18s %2s %-8s %6s\\n\", \"TIME(us)\", \"CLIENT\", \"OP\",\n\t    \"BYTES\", \"LUN\");\n}\n\niscsi*:::data-send\n{\n\tprintf(\"%-16d %-18s %2s %-8d %6d\\n\", timestamp / 1000,\n\t    args[0]->ci_remote, \"R\", args[1]->ii_datalen, args[1]->ii_lun);\n}\n\niscsi*:::data-receive\n{\n\tprintf(\"%-16d %-18s %2s %-8d %6d\\n\", timestamp / 1000,\n\t    args[0]->ci_remote, \"W\", args[1]->ii_datalen, args[1]->ii_lun);\n}\n"
  },
  {
    "path": "Chap7/iscsirwsnoopsdt.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iscsirwsnoopsdt.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-16s %-18s %2s %-8s %6s\\n\", \"TIME(us)\", \"CLIENT\", \"OP\",\n\t    \"BYTES\", \"LUN\");\n}\n\niscsi:::xfer-start\n{\n\tprintf(\"%-16d %-18s %2s %-8d %6d\\n\", timestamp / 1000,\n\t    args[0]->ci_remote, arg8 ? \"R\" : \"W\", args[2]->xfer_len,\n\t    args[1]->ii_lun);\n}\n"
  },
  {
    "path": "Chap7/iscsirwtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iscsirwtime.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ninline int TOP_TARGETS = 10;\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing iSCSI target... Hit Ctrl-C to end.\\n\");\n}\n\niscsi:::xfer-start\n{\n\tstart[arg1] = timestamp;\n}\n\niscsi:::xfer-done\n/start[arg1] != 0/\n{\n\tthis->elapsed = timestamp - start[arg1];\n\t@rw[arg8 ? \"read\" : \"write\"] = quantize(this->elapsed / 1000);\n\t@host[args[0]->ci_remote] = sum(this->elapsed);\n\t@targ[args[1]->ii_target] = sum(this->elapsed);\n\tstart[arg1] = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"iSCSI read/write distributions (us):\\n\");\n\tprinta(@rw);\n\n\tprintf(\"\\niSCSI read/write by client (total us):\\n\");\n\tnormalize(@host, 1000);\n\tprinta(@host);\n\n\tprintf(\"\\niSCSI read/write top %d targets (total us):\\n\", TOP_TARGETS);\n\tnormalize(@targ, 1000);\n\ttrunc(@targ, TOP_TARGETS);\n\tprinta(@targ);\n}\n"
  },
  {
    "path": "Chap7/iscsiterr.d",
    "content": "#!/usr/sbin/dtrace -Cs\n/*\n * iscsiterr.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ntypedef enum idm_status {\n\tIDM_STATUS_SUCCESS = 0,\n\tIDM_STATUS_FAIL,\n\tIDM_STATUS_NORESOURCES,\n\tIDM_STATUS_REJECT,\n\tIDM_STATUS_IO,\n\tIDM_STATUS_ABORTED,\n\tIDM_STATUS_SUSPENDED,\n\tIDM_STATUS_HEADER_DIGEST,\n\tIDM_STATUS_DATA_DIGEST,\n\tIDM_STATUS_PROTOCOL_ERROR,\n\tIDM_STATUS_LOGIN_FAIL\n} idm_status_t;\n\ndtrace:::BEGIN\n{\n\tstatus[IDM_STATUS_FAIL] = \"FAIL\";\n\tstatus[IDM_STATUS_NORESOURCES] = \"NORESOURCES\";\n\tstatus[IDM_STATUS_REJECT] = \"REJECT\";\n\tstatus[IDM_STATUS_IO] = \"IO\";\n\tstatus[IDM_STATUS_ABORTED] = \"ABORTED\";\n\tstatus[IDM_STATUS_SUSPENDED] = \"SUSPENDED\";\n\tstatus[IDM_STATUS_HEADER_DIGEST] = \"HEADER_DIGEST\";\n\tstatus[IDM_STATUS_DATA_DIGEST] = \"DATA_DIGEST\";\n\tstatus[IDM_STATUS_PROTOCOL_ERROR] = \"PROTOCOL_ERROR\";\n\tstatus[IDM_STATUS_LOGIN_FAIL] = \"LOGIN_FAIL\";\n\n\tprintf(\"%-20s  %-20s %s\\n\", \"TIME\", \"CLIENT\", \"ERROR\");\n}\n\nfbt::idm_pdu_complete:entry\n/arg1 != IDM_STATUS_SUCCESS/\n{\n\tthis->ic = args[0]->isp_ic;\n\tthis->remote = (this->ic->ic_raddr.ss_family == AF_INET) ?\n\t    inet_ntoa((ipaddr_t *)&((struct sockaddr_in *)&\n\tthis->ic->ic_raddr)->sin_addr) :\n\t    inet_ntoa6(&((struct sockaddr_in6 *)&\n\tthis->ic->ic_raddr)->sin6_addr);\n\n\tthis->err = status[arg1] != NULL ? status[arg1] : lltostr(arg1);\n\tprintf(\"%-20Y  %-20s %s\\n\", walltimestamp, this->remote, this->err);\n}\n"
  },
  {
    "path": "Chap7/iscsiwho.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * iscsiwho.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing iSCSI... Hit Ctrl-C to end.\\n\");\n}\n\niscsi*:::\n{\n\t@events[args[0]->ci_remote, probename] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %-26s %14s %8s\\n\", \"REMOTE IP\", \"iSCSI EVENT\", \"COUNT\");\n\tprinta(\"   %-26s %14s %@8d\\n\", @events);\n}\n"
  },
  {
    "path": "Chap7/ldapsyslog.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * ldapsyslog.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN { printf(\"Tracing PID %d...\\n\", $target); }\n\npid$target::syslog:entry\n{\n\tself->in_syslog = 1;\n}\n\npid$target::strlen:entry\n/self->in_syslog/\n{\n\tself->buf = arg0;\n}\n\npid$target::syslog:return\n/self->buf/\n{\n\ttrace(copyinstr(self->buf));\n\tself->in_syslog = 0;\n\tself->buf = 0;\n}\n"
  },
  {
    "path": "Chap7/nfsv3commit.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3commit.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\n/* From /usr/include/nfs/nfs.h */\ninline int UNSTABLE = 0;\nint last[string];\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing NFSv3 writes and commits... Hit Ctrl-C to end.\\n\");\n}\n\nnfsv3:::op-write-start\n/args[2]->stable == UNSTABLE/\n{\n\t@write[args[1]->noi_curpath] = sum(args[2]->count);\n}\n\nnfsv3:::op-write-start\n/args[2]->stable != UNSTABLE/\n{\n\t@syncwrite[args[1]->noi_curpath] = sum(args[2]->count);\n}\n\nnfsv3:::op-commit-start\n/(this->last = last[args[1]->noi_curpath])/\n{\n\tthis->delta = (timestamp - this->last) / 1000;\n\t@time[args[1]->noi_curpath] = quantize(this->delta);\n}\n\nnfsv3:::op-commit-start\n{\n\t@committed[args[1]->noi_curpath] = sum(args[2]->count);\n\t@commit[args[1]->noi_curpath] = quantize(args[2]->count / 1024);\n\tlast[args[1]->noi_curpath] = timestamp;\n}\n\ndtrace:::END\n{\n\tnormalize(@write, 1024);\n\tnormalize(@syncwrite, 1024);\n\tnormalize(@committed, 1024);\n\tprintf(\"\\nCommited vs uncommited written Kbytes by path:\\n\\n\");\n\tprintf(\" %-10s %-10s %-10s %s\\n\", \"WRITE\", \"SYNCWRITE\", \"COMMITTED\",\n\t    \"PATH\");\n\tprinta(\" %@-10d %@-10d %@-10d %s\\n\", @write, @syncwrite, @committed);\n\tprintf(\"\\n\\nCommit Kbytes by path:\\n\");\n\tprinta(@commit);\n\tprintf(\"\\nTime between commits (us) by path:\\n\");\n\tprinta(@time);\n}\n"
  },
  {
    "path": "Chap7/nfsv3disk.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3disk.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tinterval = 5;\n\tprintf(\"Tracing... Interval %d secs.\\n\", interval);\n\ttick = interval;\n}\n\n/* NFSv3 read/write */\nnfsv3:::op-read-done { @nfsrb = sum(args[2]->res_u.ok.data.data_len); }\nnfsv3:::op-write-done { @nfswb = sum(args[2]->res_u.ok.count); }\n\n/* Disk read/write */\nio:::done /args[0]->b_flags & B_READ/ { @diskrb = sum(args[0]->b_bcount); }\nio:::done /args[0]->b_flags & B_WRITE/ { @diskwb = sum(args[0]->b_bcount); }\n\n/* Filesystem hit rate: ZFS */\nsdt:zfs::arc-hit { @fshit = count(); }\nsdt:zfs::arc-miss { @fsmiss = count(); }\n\nprofile:::tick-1sec\n/--tick == 0/\n{\n\tnormalize(@nfsrb, 1024 * interval);\n\tnormalize(@nfswb, 1024 * interval);\n\tnormalize(@diskrb, 1024 * interval);\n\tnormalize(@diskwb, 1024 * interval);\n\tnormalize(@fshit, interval);\n\tnormalize(@fsmiss, interval);\n\tprintf(\"\\n   %10s %10s %10s %10s    %10s %10s\\n\", \"NFS kr/s\",\n\t    \"ZFS hit/s\", \"ZFS miss/s\", \"Disk kr/s\", \"NFS kw/s\", \"Disk kw/s\");\n\tprinta(\"   %@10d %@10d %@10d %@10d    %@10d %@10d\\n\", @nfsrb, @fshit,\n\t    @fsmiss, @diskrb, @nfswb, @diskwb);\n\ttrunc(@nfsrb); trunc(@nfswb); trunc(@diskrb); trunc(@diskwb);\n\ttrunc(@fshit); trunc(@fsmiss);\n\ttick = interval;\n}\n"
  },
  {
    "path": "Chap7/nfsv3errors.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3errors.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\t/* See NFS3ERR_* in /usr/include/nfs/nfs.h */\n\tnfs3err[0] = \"NFS3_OK\";\n\tnfs3err[1] = \"PERM\";\n\tnfs3err[2] = \"NOENT\";\n\tnfs3err[5] = \"IO\";\n\tnfs3err[6] = \"NXIO\";\n\tnfs3err[13] = \"ACCES\";\n\tnfs3err[17] = \"EXIST\";\n\tnfs3err[18] = \"XDEV\";\n\tnfs3err[19] = \"NODEV\";\n\tnfs3err[20] = \"NOTDIR\";\n\tnfs3err[21] = \"ISDIR\";\n\tnfs3err[22] = \"INVAL\";\n\tnfs3err[27] = \"FBIG\";\n\tnfs3err[28] = \"NOSPC\";\n\tnfs3err[30] = \"ROFS\";\n\tnfs3err[31] = \"MLINK\";\n\tnfs3err[63] = \"NAMETOOLONG\";\n\tnfs3err[66] = \"NOTEMPTY\";\n\tnfs3err[69] = \"DQUOT\";\n\tnfs3err[70] = \"STALE\";\n\tnfs3err[71] = \"REMOTE\";\n\tnfs3err[10001] = \"BADHANDLE\";\n\tnfs3err[10002] = \"NOT_SYNC\";\n\tnfs3err[10003] = \"BAD_COOKIE\";\n\tnfs3err[10004] = \"NOTSUPP\";\n\tnfs3err[10005] = \"TOOSMALL\";\n\tnfs3err[10006] = \"SERVERFAULT\";\n\tnfs3err[10007] = \"BADTYPE\";\n\tnfs3err[10008] = \"JUKEBOX\";\n\n\tprintf(\" %-18s %5s %-12s %-16s %s\\n\", \"NFSv3 EVENT\", \"ERR\", \"CODE\",\n\t    \"CLIENT\", \"PATHNAME\");\n}\n\nnfsv3:::op-*-done\n/args[2]->status != 0/\n{\n\tthis->err = args[2]->status;\n\tthis->str = nfs3err[this->err] != NULL ? nfs3err[this->err] : \"?\";\n\t    printf(\" %-18s %5d %-12s %-16s %s\\n\", probename, this->err,\n\tthis->str, args[0]->ci_remote, args[1]->noi_curpath);\n}\n"
  },
  {
    "path": "Chap7/nfsv3fbtrws.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3fbtrws.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-16s %-18s %2s %-10s %6s %s\\n\", \"TIME(us)\",\n\t    \"CLIENT\", \"OP\", \"OFFSET(KB)\", \"BYTES\", \"PATHNAME\");\n}\n\nfbt::rfs3_read:entry\n{\n\tself->in_rfs3 = 1;\n\t/* args[0] is READ3args */\n\tself->offset = args[0]->offset / 1024;\n\tself->count = args[0]->count;\n\tself->req = args[3];\n\tself->dir = \"R\";\n}\n\nfbt::rfs3_write:entry\n{\n\tself->in_rfs3 = 1;\n\t/* args[0] is WRITE3args */\n\tself->offset = args[0]->offset / 1024;\n\tself->count = args[0]->count;\n\tself->req = args[3];\n\tself->dir = \"W\";\n}\n\n/* trace nfs3_fhtovp() to retrieve the vnode_t */\nfbt::nfs3_fhtovp:return\n/self->in_rfs3/\n{\n\tthis->vp = args[1];\n\tthis->socket =\n\t    (struct sockaddr_in *)self->req->rq_xprt->xp_xpc.xpc_rtaddr.buf;\n\t/* DTrace 1.0: no inet functions, no this->strings */\n\tthis->a = (uint8_t *)&this->socket->sin_addr.S_un.S_addr;\n\tself->addr1 = strjoin(lltostr(this->a[0] + 0ULL), strjoin(\".\",\n\t    strjoin(lltostr(this->a[1] + 0ULL), \".\")));\n\tself->addr2 = strjoin(lltostr(this->a[2] + 0ULL), strjoin(\".\",\n\t    lltostr(this->a[3] + 0ULL)));\n\tself->address = strjoin(self->addr1, self->addr2);\n\n\tprintf(\"%-16d %-18s %2s %-10d %6d %s\\n\", timestamp / 1000,\n\t    self->address, self->dir, self->offset, self->count,\n\t    this->vp->v_path != NULL ? stringof(this->vp->v_path) : \"<?>\");\n\n\tself->addr1 = 0;\n\tself->addr2 = 0;\n\tself->address = 0;\n\tself->dir = 0;\n\tself->req = 0;\n\tself->offset = 0;\n\tself->count = 0;\n\tself->in_rfs3 = 0;\n}\n"
  },
  {
    "path": "Chap7/nfsv3fileio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3fileio.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nnfsv3:::op-read-done\n{\n\t@readbytes[args[1]->noi_curpath] = sum(args[2]->res_u.ok.data.data_len);\n}\n\nnfsv3:::op-write-done\n{\n\t@writebytes[args[1]->noi_curpath] = sum(args[2]->res_u.ok.count);\n}\n\ndtrace:::END\n{\n\tprintf(\"\\n%12s %12s  %s\\n\", \"Rbytes\", \"Wbytes\", \"Pathname\");\n\tprinta(\"%@12d %@12d  %s\\n\", @readbytes, @writebytes);\n}\n"
  },
  {
    "path": "Chap7/nfsv3ops.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3ops.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing NFSv3 operations... Interval 5 secs.\\n\");\n}\n\nnfsv3:::op-*-start\n{\n\t@ops[args[0]->ci_remote, probename] = count();\n}\n\nprofile:::tick-5sec,\ndtrace:::END\n{\n\tprintf(\"\\n   %-32s %-28s %8s\\n\", \"Client\", \"Operation\", \"Count\");\n\tprinta(\"   %-32s %-28s %@8d\\n\", @ops);\n\ttrunc(@ops);\n}\n"
  },
  {
    "path": "Chap7/nfsv3rwsnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3rwsnoop.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-16s %-18s %2s %-10s %6s %s\\n\", \"TIME(us)\",\n\t    \"CLIENT\", \"OP\", \"OFFSET(KB)\", \"BYTES\", \"PATHNAME\");\n}\n\nnfsv3:::op-read-start\n{\n\tprintf(\"%-16d %-18s %2s %-10d %6d %s\\n\", timestamp / 1000,\n\t    args[0]->ci_remote, \"R\", args[2]->offset / 1024,\n\t    args[2]->count, args[1]->noi_curpath);\n}\n\nnfsv3:::op-write-start\n{\n\tprintf(\"%-16d %-18s %2s %-10d %6d %s\\n\", timestamp / 1000,\n\t    args[0]->ci_remote, \"W\", args[2]->offset / 1024,\n\t    args[2]->data.data_len, args[1]->noi_curpath);\n}\n"
  },
  {
    "path": "Chap7/nfsv3rwtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3rwtime.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ninline int TOP_FILES = 10;\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nnfsv3:::op-read-start,\nnfsv3:::op-write-start\n{\n\tstart[args[1]->noi_xid] = timestamp;\n}\n\nnfsv3:::op-read-done,\nnfsv3:::op-write-done\n/start[args[1]->noi_xid] != 0/\n{\n\tthis->elapsed = timestamp - start[args[1]->noi_xid];\n\t@rw[probename == \"op-read-done\" ? \"read\" : \"write\"] =\n\t    quantize(this->elapsed / 1000);\n\t@host[args[0]->ci_remote] = sum(this->elapsed);\n\t@file[args[1]->noi_curpath] = sum(this->elapsed);\n\tstart[args[1]->noi_xid] = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"NFSv3 read/write distributions (us):\\n\");\n\tprinta(@rw);\n\n\tprintf(\"\\nNFSv3 read/write by host (total us):\\n\");\n\tnormalize(@host, 1000);\n\tprinta(@host);\n\n\tprintf(\"\\nNFSv3 read/write top %d files (total us):\\n\", TOP_FILES);\n\tnormalize(@file, 1000);\n\ttrunc(@file, TOP_FILES);\n\tprinta(@file);\n}\n"
  },
  {
    "path": "Chap7/nfsv3syncwrite.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv3syncwrite.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\t/* See /usr/include/nfs/nfs.h */\n\tstable_how[0] = \"Unstable\";\n\tstable_how[1] = \"Data_Sync\";\n\tstable_how[2] = \"File_Sync\";\n\tprintf(\"Tracing NFSv3 writes and commits... Hit Ctrl-C to end.\\n\");\n}\n\nnfsv3:::op-write-start\n{\n\t@[\"write\", stable_how[args[2]->stable], args[1]->noi_curpath] = count();\n}\n\nnfsv3:::op-commit-start\n{\n\t@[\"commit\", \"-\", args[1]->noi_curpath] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\" %-7s %-10s %-10s %s\\n\", \"OP\", \"TYPE\", \"COUNT\", \"PATH\");\n\tprinta(\" %-7s %-10s %@-10d %s\\n\", @);\n}\n"
  },
  {
    "path": "Chap7/nfsv4commit.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv4commit.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\n/* From /usr/include/nfs/nfs4_kprot.h */\ninline int UNSTABLE = 0;\nint last[string];\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing NFSv4 writes and commits... Hit Ctrl-C to end.\\n\");\n}\n\nnfsv4:::op-write-start\n/args[2]->stable == UNSTABLE/\n{\n\t@write[args[1]->noi_curpath] = sum(args[2]->data_len);\n}\n\nnfsv4:::op-write-start\n/args[2]->stable != UNSTABLE/\n{\n\t@syncwrite[args[1]->noi_curpath] = sum(args[2]->data_len);\n}\n\nnfsv4:::op-commit-start\n/(this->last = last[args[1]->noi_curpath])/\n{\n\tthis->delta = (timestamp - this->last) / 1000;\n\t@time[args[1]->noi_curpath] = quantize(this->delta);\n}\n\nnfsv4:::op-commit-start\n{\n\t@committed[args[1]->noi_curpath] = sum(args[2]->count);\n\t@commit[args[1]->noi_curpath] = quantize(args[2]->count / 1024);\n\tlast[args[1]->noi_curpath] = timestamp;\n}\n\ndtrace:::END\n{\n\tnormalize(@write, 1024);\n\tnormalize(@syncwrite, 1024);\n\tnormalize(@committed, 1024);\n\tprintf(\"\\nCommited vs uncommited written Kbytes by path:\\n\\n\");\n\tprintf(\" %-10s %-10s %-10s %s\\n\", \"WRITE\", \"SYNCWRITE\", \"COMMITTED\",\n\t    \"PATH\");\n\tprinta(\" %@-10d %@-10d %@-10d %s\\n\", @write, @syncwrite, @committed);\n\tprintf(\"\\n\\nCommit Kbytes by path:\\n\");\n\tprinta(@commit);\n\tprintf(\"\\nTime between commits (us) by path:\\n\");\n\tprinta(@time);\n}\n"
  },
  {
    "path": "Chap7/nfsv4deleg.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv4deleg.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tdeleg[0] = \"none\";\n\tdeleg[1] = \"read\";\n\tdeleg[2] = \"write\";\n\tdeleg[-1] = \"any\";\n\n\tprintf(\"Tracing NFSv4 delegation events...\\n\");\n\tprintf(\"%-21s %-20s %s\\n\", \"TIME\", \"EVENT\", \"DETAILS\");\n}\n\nfbt::rfs4_grant_delegation:entry\n{\n\tthis->path = stringof(args[1]->rs_finfo->rf_vp->v_path);\n\tthis->client = args[1]->rs_owner->ro_client->rc_clientid;\n\tthis->type = deleg[arg0] != NULL ? deleg[arg0] : \"<?>\";\n\t    printf(\"%-21Y %-20s %-8s %s\\n\", walltimestamp, \"Grant Delegation\",\n\tthis->type, this->path);\n}\n\nfbt::rfs4_recall_deleg:entry\n{\n\tthis->path = stringof(args[0]->rf_vp->v_path);\n\tprintf(\"%-21Y %-20s %-8s %s\\n\", walltimestamp, \"Recall Delegation\",\n\t    \".\", this->path);\n}\n\nfbt::rfs4_deleg_state_expiry:entry\n{\n\tthis->dsp = (rfs4_deleg_state_t *)arg0;\n\tthis->path = stringof(this->dsp->rds_finfo->rf_vp->v_path);\n\tprintf(\"%-21Y %-20s %-8s %s\\n\", walltimestamp, \"Delegation Expiry\",\n\t    \".\", this->path);\n}\n"
  },
  {
    "path": "Chap7/nfsv4errors.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv4errors.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\t/* See NFS4ERR_* in /usr/include/nfs/nfs4_kprot.h */\n\tnfs4err[0] = \"NFS4_OK\";\n\tnfs4err[1] = \"PERM\";\n\tnfs4err[2] = \"NOENT\";\n\tnfs4err[5] = \"IO\";\n\tnfs4err[6] = \"NXIO\";\n\tnfs4err[13] = \"ACCESS\";\n\tnfs4err[17] = \"EXIST\";\n\tnfs4err[18] = \"XDEV\";\n\tnfs4err[20] = \"NOTDIR\";\n\tnfs4err[21] = \"ISDIR\";\n\tnfs4err[22] = \"INVAL\";\n\tnfs4err[27] = \"FBIG\";\n\tnfs4err[28] = \"NOSPC\";\n\tnfs4err[30] = \"ROFS\";\n\tnfs4err[31] = \"MLINK\";\n\tnfs4err[63] = \"NAMETOOLONG\";\n\tnfs4err[66] = \"NOTEMPTY\";\n\tnfs4err[69] = \"DQUOT\";\n\tnfs4err[70] = \"STALE\";\n\tnfs4err[10001] = \"BADHANDLE\";\n\tnfs4err[10003] = \"BAD_COOKIE\";\n\tnfs4err[10004] = \"NOTSUPP\";\n\tnfs4err[10005] = \"TOOSMALL\";\n\tnfs4err[10006] = \"SERVERFAULT\";\n\tnfs4err[10007] = \"BADTYPE\";\n\tnfs4err[10008] = \"DELAY\";\n\tnfs4err[10009] = \"SAME\";\n\tnfs4err[10010] = \"DENIED\";\n\tnfs4err[10011] = \"EXPIRED\";\n\tnfs4err[10012] = \"LOCKED\";\n\tnfs4err[10013] = \"GRACE\";\n\tnfs4err[10014] = \"FHEXPIRED\";\n\tnfs4err[10015] = \"SHARE_DENIED\";\n\tnfs4err[10016] = \"WRONGSEC\";\n\tnfs4err[10017] = \"CLID_INUSE\";\n\tnfs4err[10018] = \"RESOURCE\";\n\tnfs4err[10019] = \"MOVED\";\n\tnfs4err[10020] = \"NOFILEHANDLE\";\n\tnfs4err[10021] = \"MINOR_VERS_MISMATCH\";\n\tnfs4err[10022] = \"STALE_CLIENTID\";\n\tnfs4err[10023] = \"STALE_STATEID\";\n\tnfs4err[10024] = \"OLD_STATEID\";\n\tnfs4err[10025] = \"BAD_STATEID\";\n\tnfs4err[10026] = \"BAD_SEQID\";\n\tnfs4err[10027] = \"NOT_SAME\";\n\tnfs4err[10028] = \"LOCK_RANGE\";\n\tnfs4err[10029] = \"SYMLINK\";\n\tnfs4err[10030] = \"RESTOREFH\";\n\tnfs4err[10031] = \"LEASE_MOVED\";\n\tnfs4err[10032] = \"ATTRNOTSUPP\";\n\tnfs4err[10033] = \"NO_GRACE\";\n\tnfs4err[10034] = \"RECLAIM_BAD\";\n\tnfs4err[10035] = \"RECLAIM_CONFLICT\";\n\tnfs4err[10036] = \"BADXDR\";\n\tnfs4err[10037] = \"LOCKS_HELD\";\n\tnfs4err[10038] = \"OPENMODE\";\n\tnfs4err[10039] = \"BADOWNER\";\n\tnfs4err[10040] = \"BADCHAR\";\n\tnfs4err[10041] = \"BADNAME\";\n\tnfs4err[10042] = \"BAD_RANGE\";\n\tnfs4err[10043] = \"LOCK_NOTSUPP\";\n\tnfs4err[10044] = \"OP_ILLEGAL\";\n\tnfs4err[10045] = \"DEADLOCK\";\n\tnfs4err[10046] = \"FILE_OPEN\";\n\tnfs4err[10047] = \"ADMIN_REVOKED\";\n\tnfs4err[10048] = \"CB_PATH_DOWN\";\n\n\tprintf(\" %-18s %5s %-12s %-16s %s\\n\", \"NFSv4 EVENT\", \"ERR\", \"CODE\",\n\t    \"CLIENT\", \"PATHNAME\");\n}\n\nnfsv4:::op-*-done\n/args[2]->status != 0 && args[2]->status != 10009/\n{\n\tthis->err = args[2]->status;\n\tthis->str = nfs4err[this->err] != NULL ? nfs4err[this->err] : \"?\";\n\tprintf(\" %-18s %5d %-12s %-16s %s\\n\", probename, this->err,\n\t    this->str, args[0]->ci_remote, args[1]->noi_curpath);\n}\n"
  },
  {
    "path": "Chap7/nfsv4fileio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv4fileio.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nnfsv4:::op-read-done\n{\n\t@readbytes[args[1]->noi_curpath] = sum(args[2]->data_len);\n}\n\nnfsv4:::op-write-done\n{\n\t@writebytes[args[1]->noi_curpath] = sum(args[2]->count);\n}\n\ndtrace:::END\n{\n\tprintf(\"\\n%12s %12s  %s\\n\", \"Rbytes\", \"Wbytes\", \"Pathname\");\n\tprinta(\"%@12d %@12d  %s\\n\", @readbytes, @writebytes);\n}\n"
  },
  {
    "path": "Chap7/nfsv4ops.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv4ops.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\ttrace(\"Tracing NFSv4 operations... Interval 5 secs.\\n\");\n}\n\nnfsv4:::op-*-start\n{\n\t@ops[args[0]->ci_remote, probename] = count();\n}\n\nprofile:::tick-5sec,\ndtrace:::END\n{\n\tprintf(\"\\n   %-32s %-28s %8s\\n\", \"Client\", \"Operation\", \"Count\");\n\tprinta(\"   %-32s %-28s %@8d\\n\", @ops);\n\ttrunc(@ops);\n}\n"
  },
  {
    "path": "Chap7/nfsv4rwsnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv4rwsnoop.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-16s %-18s %2s %-10s %6s %s\\n\", \"TIME(us)\",\n\t    \"CLIENT\", \"OP\", \"OFFSET(KB)\", \"BYTES\", \"PATHNAME\");\n}\n\nnfsv4:::op-read-start\n{\n\tprintf(\"%-16d %-18s %2s %-10d %6d %s\\n\", timestamp / 1000,\n\t    args[0]->ci_remote, \"R\", args[2]->offset / 1024,\n\t    args[2]->count, args[1]->noi_curpath);\n}\n\nnfsv4:::op-write-start\n{\n\tprintf(\"%-16d %-18s %2s %-10d %6d %s\\n\", timestamp / 1000,\n\t    args[0]->ci_remote, \"W\", args[2]->offset / 1024,\n\t    args[2]->data_len, args[1]->noi_curpath);\n}\n"
  },
  {
    "path": "Chap7/nfsv4rwtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv4rwtime.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ninline int TOP_FILES = 10;\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nnfsv4:::op-read-start,\nnfsv4:::op-write-start\n{\n\tstart[args[1]->noi_xid] = timestamp;\n}\n\nnfsv4:::op-read-done,\nnfsv4:::op-write-done\n/start[args[1]->noi_xid] != 0/\n{\n\tthis->elapsed = timestamp - start[args[1]->noi_xid];\n\t@rw[probename == \"op-read-done\" ? \"read\" : \"write\"] =\n\t    quantize(this->elapsed / 1000);\n\t@host[args[0]->ci_remote] = sum(this->elapsed);\n\t@file[args[1]->noi_curpath] = sum(this->elapsed);\n\tstart[args[1]->noi_xid] = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"NFSv4 read/write distributions (us):\\n\");\n\tprinta(@rw);\n\n\tprintf(\"\\nNFSv4 read/write by host (total us):\\n\");\n\tnormalize(@host, 1000);\n\tprinta(@host);\n\n\tprintf(\"\\nNFSv4 read/write top %d files (total us):\\n\", TOP_FILES);\n\tnormalize(@file, 1000);\n\ttrunc(@file, TOP_FILES);\n\tprinta(@file);\n}\n"
  },
  {
    "path": "Chap7/nfsv4syncwrite.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nfsv4syncwrite.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\t/* See /usr/include/nfs/nfs4_kprot.h */\n\tstable_how[0] = \"Unstable\";\n\tstable_how[1] = \"Data_Sync\";\n\tstable_how[2] = \"File_Sync\";\n\tprintf(\"Tracing NFSv4 writes and commits... Hit Ctrl-C to end.\\n\");\n}\n\nnfsv4:::op-write-start\n{\n\t@[\"write\", stable_how[args[2]->stable], args[1]->noi_curpath] = count();\n}\n\nnfsv4:::op-commit-start\n{\n\t@[\"commit\", \"-\", args[1]->noi_curpath] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\" %-7s %-10s %-10s %s\\n\", \"OP\", \"TYPE\", \"COUNT\", \"PATH\");\n\tprinta(\" %-7s %-10s %@-10d %s\\n\", @);\n}\n"
  },
  {
    "path": "Chap7/nismatch.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * nismatch.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s  %-16s %-16s %s\\n\", \"TIME\", \"DOMAIN\", \"MAP\", \"KEY\");\n}\n\npid$target::ypset_current_map:entry\n{\n\tself->map = copyinstr(arg0);\n\tself->domain = copyinstr(arg1);\n}\n\npid$target::finddatum:entry\n/self->map != NULL/\n{\n\tprintf(\"%-20Y  %-16s %-16s %S\\n\", walltimestamp, self->domain,\n\t    self->map, copyinstr(arg1));\n}\n"
  },
  {
    "path": "Chap7/proftpdcmd.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * proftpdcmd.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %10s  %s\\n\", \"TIME\", \"LAT(us)\", \"FTP CMD\");\n}\n\n/* on this proftpd version, pr_netio_telnet_gets() returns the FTP cmd */\npid$target:proftpd:pr_netio_telnet_gets:return\n{\n\tself->cmd = copyinstr(arg1);\n\tself->start = timestamp;\n}\n\npid$target:proftpd:pr_netio_telnet_gets:entry\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\t/* self->cmd already contains \"\\r\\n\" */\n\tprintf(\"%-20Y %10d  %s\", walltimestamp, this->delta, self->cmd);\n\tself->start = 0;\n\tself->cmd = 0;\n}\n"
  },
  {
    "path": "Chap7/proftpdio.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * proftpdio.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tinterval = 5;\n\tprintf(\"Tracing... Output every %d seconds.\\n\", interval);\n\tprintf(\"  FTPD %4s %8s %8s %8s %8s %10s\\n\",\n\t    \"r/s\", \"w/s\", \"kr/s\", \"kw/s\", \"cmd/s\", \"cmd_t(ms)\");\n\ttick = interval;\n\t@readb = sum(0);\t\t/* trigger output */\n}\n\npid$target:proftpd:pr_netio_read:return\n/arg1 > 0/\n{\n\t@writes = count();\n\t@writeb = sum(arg1);\n}\n\npid$target:proftpd:pr_netio_write:entry\n/arg2 > 0/\n{\n\t@reads = count();\n\t@readb = sum(arg2);\n}\n\npid$target:proftpd:pr_netio_telnet_gets:return\n{\n\t@cmds = count();\n\tself->start = timestamp;\n}\n\npid$target:proftpd:pr_netio_telnet_gets:entry\n{\n\tthis->delta = (timestamp - self->start) / 1000000;\n\t@svct = avg(this->delta);\n}\n\nprofile:::tick-1sec\n/--tick == 0/\n{\n\tnormalize(@reads, interval);\n\tnormalize(@readb, interval * 1024);\n\tnormalize(@writes, interval);\n\tnormalize(@writeb, interval * 1024);\n\tnormalize(@cmds, interval);\n\n\tprinta(\"   %@8d %@8d %@8d %@8d %@8d %@10d\\n\",\n\t@reads, @writes, @readb, @writeb, @cmds, @svct);\n\n\tclear(@reads); clear(@readb); clear(@writes); clear(@writeb);\n\tclear(@cmds); clear(@svct);\n\ttick = interval;\n}\n"
  },
  {
    "path": "Chap7/proftpdtime.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * proftpdtime.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\n/* on this proftpd version, pr_netio_telnet_gets() returns the FTP cmd */\npid$target:proftpd:pr_netio_telnet_gets:return\n{\n\tself->cmd = copyinstr(arg1);\n\tself->start = timestamp;\n}\n\npid$target:proftpd:pr_netio_telnet_gets:entry\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000000;\n\t@[self->cmd] = lquantize(this->delta, 0, 1000, 10);\n\tself->start = 0;\n\tself->cmd = 0;\n}\n\ndtrace:::END\n{\n\tprintf(\"FTP command times (ms):\\n\");\n\tprinta(@);\n}\n"
  },
  {
    "path": "Chap7/scpwatcher.d",
    "content": "#!/usr/sbin/dtrace -qs\n/*\n * scpwatcher.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\ninline int stdout = 1;\n\nsyscall::write:entry\n/execname == \"scp\" && arg0 == stdout/\n{\n\tprintf(\"%s\\n\", copyinstr(arg1));\n}\n"
  },
  {
    "path": "Chap7/scsicmds.d",
    "content": "scsi_cmd[0x00] = \"test_unit_ready\";\n/*\n * scsicmds.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\nscsi_cmd[0x01] = \"rezero/rewind\";\nscsi_cmd[0x03] = \"request_sense\";\nscsi_cmd[0x04] = \"format\";\nscsi_cmd[0x05] = \"read_block_limits\";\nscsi_cmd[0x07] = \"reassign\";\nscsi_cmd[0x08] = \"read\";\nscsi_cmd[0x0a] = \"write\";\nscsi_cmd[0x0b] = \"seek\";\nscsi_cmd[0x0f] = \"read_reverse\";\nscsi_cmd[0x10] = \"write_file_mark\";\nscsi_cmd[0x11] = \"space\";\nscsi_cmd[0x12] = \"inquiry\";\nscsi_cmd[0x13] = \"verify\";\nscsi_cmd[0x14] = \"recover_buffer_data\";\nscsi_cmd[0x15] = \"mode_select\";\nscsi_cmd[0x16] = \"reserve\";\nscsi_cmd[0x17] = \"release\";\nscsi_cmd[0x18] = \"copy\";\nscsi_cmd[0x19] = \"erase_tape\";\nscsi_cmd[0x1a] = \"mode_sense\";\nscsi_cmd[0x1b] = \"load/start/stop\";\nscsi_cmd[0x1c] = \"get_diagnostic_results\";\nscsi_cmd[0x1d] = \"send_diagnostic_command\";\nscsi_cmd[0x1e] = \"door_lock\";\nscsi_cmd[0x23] = \"read_format_capacity\";\nscsi_cmd[0x25] = \"read_capacity\";\nscsi_cmd[0x28] = \"read(10)\";\nscsi_cmd[0x2a] = \"write(10)\";\nscsi_cmd[0x2b] = \"seek(10)\";\nscsi_cmd[0x2e] = \"write_verify\";\nscsi_cmd[0x2f] = \"verify(10)\";\nscsi_cmd[0x30] = \"search_data_high\";\nscsi_cmd[0x31] = \"search_data_equal\";\nscsi_cmd[0x32] = \"search_data_low\";\nscsi_cmd[0x33] = \"set_limits\";\nscsi_cmd[0x34] = \"read_position\";\nscsi_cmd[0x35] = \"synchronize_cache\";\nscsi_cmd[0x37] = \"read_defect_data\";\nscsi_cmd[0x39] = \"compare\";\nscsi_cmd[0x3a] = \"copy_verify\";\nscsi_cmd[0x3b] = \"write_buffer\";\nscsi_cmd[0x3c] = \"read_buffer\";\nscsi_cmd[0x3e] = \"read_long\";\nscsi_cmd[0x3f] = \"write_long\";\nscsi_cmd[0x44] = \"report_densities/read_header\";\nscsi_cmd[0x4c] = \"log_select\";\nscsi_cmd[0x4d] = \"log_sense\";\nscsi_cmd[0x55] = \"mode_select(10)\";\nscsi_cmd[0x56] = \"reserve(10)\";\nscsi_cmd[0x57] = \"release(10)\";\nscsi_cmd[0x5a] = \"mode_sense(10)\";\nscsi_cmd[0x5e] = \"persistent_reserve_in\";\nscsi_cmd[0x5f] = \"persistent_reserve_out\";\nscsi_cmd[0x80] = \"write_file_mark(16)\";\nscsi_cmd[0x81] = \"read_reverse(16)\";\nscsi_cmd[0x83] = \"extended_copy\";\nscsi_cmd[0x88] = \"read(16)\";\nscsi_cmd[0x8a] = \"write(16)\";\nscsi_cmd[0x8c] = \"read_attribute\";\nscsi_cmd[0x8d] = \"write_attribute\";\nscsi_cmd[0x8f] = \"verify(16)\";\nscsi_cmd[0x91] = \"space(16)\";\nscsi_cmd[0x92] = \"locate(16)\";\nscsi_cmd[0x9e] = \"service_action_in(16)\";\nscsi_cmd[0x9f] = \"service_action_out(16)\";\nscsi_cmd[0xa0] = \"report_luns\";\nscsi_cmd[0xa2] = \"security_protocol_in\";\nscsi_cmd[0xa3] = \"maintenance_in\";\nscsi_cmd[0xa4] = \"maintenance_out\";\nscsi_cmd[0xa8] = \"read(12)\";\nscsi_cmd[0xa9] = \"service_action_out(12)\";\nscsi_cmd[0xaa] = \"write(12)\";\nscsi_cmd[0xab] = \"service_action_in(12)\";\nscsi_cmd[0xac] = \"get_performance\";\nscsi_cmd[0xAF] = \"verify(12)\";\nscsi_cmd[0xb5] = \"security_protocol_out\";\n"
  },
  {
    "path": "Chap7/sshcipher.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sshcipher.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing PID %d ... Hit Ctrl-C for report.\\n\", $target);\n}\n\npid$target:libcrypto*:*crypt*:entry\n{\n\tself->crypt_start[probefunc] = vtimestamp;\n}\n\npid$target:libcrypto*:*crypt*:return\n/self->crypt_start[probefunc]/\n{\n\tthis->oncpu = vtimestamp - self->crypt_start[probefunc];\n\t@cpu[probefunc, \"CPU (ns):\"] = quantize(this->oncpu);\n\t@totals[\"encryption (ns)\"] = sum(this->oncpu);\n\tself->crypt_start[probefunc] = 0;\n}\n\ndtrace:::END\n{\n\tprinta(@cpu); printa(@totals);\n}\n"
  },
  {
    "path": "Chap7/sshcipher2.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sshcipher2.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing PID %d ... Hit Ctrl-C for report.\\n\", $target);\n}\n\npid$target:libcrypto*:*crypt*:entry\n{\n\tself->crypt_start[probefunc] = vtimestamp;\n}\n\npid$target:libcrypto*:*crypt*:return\n/self->crypt_start[probefunc]/\n{\n\tthis->oncpu = vtimestamp - self->crypt_start[probefunc];\n\t@cpu[probefunc, \"CPU (ns):\"] = quantize(this->oncpu);\n\t@totals[\"encryption (ns)\"] = sum(this->oncpu);\n\tself->crypt_start[probefunc] = 0;\n}\npid$target:libz*:inflate:entry,\npid$target:libz*:deflate:entry\n{\n\tself->compress_start = vtimestamp;\n}\n\npid$target:libz*:inflate:return,\npid$target:libz*:deflate:return\n/self->compress_start/\n{\n\tthis->oncpu = vtimestamp - self->compress_start;\n\t@cpu[probefunc, \"CPU (ns):\"] = quantize(this->oncpu);\n\t@totals[\"compression (ns)\"] = sum(this->oncpu);\n\tself->compress_start = 0;\n}\n\ndtrace:::END\n{\n\tprinta(@cpu); printa(@totals);\n}\n"
  },
  {
    "path": "Chap7/sshcipher3.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sshcipher3.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing PID %d ... Hit Ctrl-C for report.\\n\", $target);\n}\n\npid$target:libcrypto*:*crypt*:entry\n{\n\tself->crypt_start[probefunc] = vtimestamp;\n}\n\npid$target:libcrypto*:*crypt*:return\n/self->crypt_start[probefunc]/\n{\n\tthis->oncpu = vtimestamp - self->crypt_start[probefunc];\n\t@cpu[probefunc, \"CPU (ns):\"] = quantize(this->oncpu);\n\t@totals[\"encryption (ns)\"] = sum(this->oncpu);\n\tself->crypt_start[probefunc] = 0;\n}\npid$target:libz*:inflate:entry,\npid$target:libz*:deflate:entry\n{\n\tself->compress_start = vtimestamp;\n}\n\npid$target:libz*:inflate:return,\npid$target:libz*:deflate:return\n/self->compress_start/\n{\n\tthis->oncpu = vtimestamp - self->compress_start;\n\t@cpu[probefunc, \"CPU (ns):\"] = quantize(this->oncpu);\n\t@totals[\"compression (ns)\"] = sum(this->oncpu);\n\tself->compress_start = 0;\n}\n\npid$target:ssh:cipher_crypt:entry\n{\n\t@bytes[\"cipher average buffer size (bytes)\"] = avg(arg3);\n\t@totals[\"cipher total (bytes)\"] = sum(arg3);\n}\n\ndtrace:::END\n{\n\tprinta(@cpu); printa(@bytes); printa(@totals);\n}\n"
  },
  {
    "path": "Chap7/sshconnect.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * sshconnect.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN { trace(\"Tracing next ssh connect...\\n\"); }\n\n/*\n * Tracing begins here: ssh process executed\n */\nproc:::exec-success\n/execname == \"ssh\"/\n{\n\tself->start = timestamp;\n\tself->vstart = vtimestamp;\n}\nsyscall:::entry\n/self->start/\n{\n\tself->syscall = timestamp;\n\tself->arg = \"\";\n}\n\n/*\n * Include syscall argument details when potentially interesting\n */\nsyscall::read*:entry,\nsyscall::ioctl*:entry,\nsyscall::door*:entry,\nsyscall::recv*:entry\n/self->start/\n{\n\tself->arg = fds[arg0].fi_pathname;\n}\n\n/*\n * Measure network I/O as pollsys/select->read() time after connect()\n */\nsyscall::connect:entry\n/self->start && !self->socket/\n{\n\tself->socket = arg0;\n\tself->connect = 1;\n\tself->vconnect = vtimestamp;\n}\nsyscall::pollsys:entry,\nsyscall::select:entry\n/self->connect/\n{\n\tself->wait = timestamp;\n}\nsyscall::read*:return\n/self->wait/\n{\n\t@network = sum(timestamp - self->wait);\n\tself->wait = 0;\n}\n\nsyscall:::return\n/self->syscall/\n{\n\t@time[probefunc, self->arg] = sum(timestamp - self->syscall);\n\tself->syscall = 0; self->network = 0; self->arg = 0;\n}\n\n/*\n * Tracing ends here: writing of the \"Password:\" prompt (10 chars)\n */\nsyscall::write*:entry\n/self->connect && arg0 != self->socket && arg2 == 10 &&\n\tstringof(copyin(arg1, 10)) == \"Password: \"/\n{\n\ttrunc(@time, 5);\n\tnormalize(@time, 1000000);\n\tnormalize(@network, 1000000);\n\tthis->oncpu1 = (self->vconnect - self->vstart) / 1000000;\n\tthis->oncpu2 = (vtimestamp - self->vconnect) / 1000000;\n\tthis->elapsed = (timestamp - self->start) / 1000000;\n\n\tprintf(\"\\nProcess     : %s\\n\", curpsinfo->pr_psargs);\n\tprintf(\"Elapsed     : %d ms\\n\", this->elapsed);\n\tprintf(\"on-CPU pre  : %d ms\\n\", this->oncpu1);\n\tprintf(\"on-CPU post : %d ms\\n\", this->oncpu2);\n\tprinta(\"Network I/O : %@d ms\\n\", @network);\n\tprintf(\"\\nTop 5 syscall times\\n\");\n\tprinta(\"%@8d ms : %s %s\\n\", @time);\n\n\texit(0);\n}\n\nproc:::exit\n/self->start/\n{\n\tprintf(\"\\nssh process aborted: %s\\n\", curpsinfo->pr_psargs);\n\ttrunc(@time); trunc(@network); exit(0);\n}\n"
  },
  {
    "path": "Chap7/sshdactivity.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sshdactivity.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option defaultargs\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s  %-8s %-8s %-8.8s %s\\n\", \"TIME\", \"UID\", \"PID\",\n\t    \"ACTION\", \"ARGS\");\n\tmy_sshd = $1;\n}\n\nsyscall::write*:entry\n/execname == \"sshd\" && fds[arg0].fi_fs == \"sockfs\" && pid != my_sshd/\n{\n\tprintf(\"%-20Y  %-8d %-8d %-8.8s %d bytes\\n\", walltimestamp, uid, pid,\n\t    probefunc, arg2);\n}\n\nsyscall::accept*:return\n/execname == \"sshd\"/\n{\n\tprintf(\"%-20Y  %-8d %-8d %-8.8s %s\\n\", walltimestamp, uid, pid,\n\t    probefunc, \"CONNECTION STARTED\");\n}\n"
  },
  {
    "path": "Chap7/tnftpdcmd.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * tnftpdcmd.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s %10s  %s\\n\", \"TIME\", \"LAT(us)\", \"FTP CMD\");\n}\n\npid$target:ftpd:getline:return\n/arg1 && arg1 != 1/\n{\n\tself->line = copyinstr(arg1);\n\tself->start = timestamp;\n}\n\npid$target:ftpd:getline:entry\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\t/* self->line already contains \"\\r\\n\" */\n\tprintf(\"%-20Y %10d  %s\", walltimestamp, this->delta, self->line);\n\tself->start = 0;\n\tself->line = 0;\n}\n"
  },
  {
    "path": "Chap7/weblatency.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * weblatency.d\n *\n * Example script from Chapter 7 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\n/* browser's execname */\ninline string BROWSER = \"mozilla-bin\";\n\n/* maximum expected hostname length + \"GET http://\" */\ninline int MAX_REQ = 64;\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\n/*\n * Trace brower request\n *\n * This is achieved by matching writes for the browser's execname that\n * start with \"GET\", and then timing from the return of the write to\n * the return of the next read in the same thread. Various stateful flags\n * are used: self->fd, self->read.\n *\n * For performance reasons, I'd like to only process writes that follow a\n * connect(), however this approach fails to process keepalives.\n */\nsyscall::write:entry\n/execname == BROWSER/\n{\n\tself->buf = arg1;\n\tself->fd = arg0 + 1;\n\tself->nam = \"\";\n}\n\nsyscall::write:return\n/self->fd/\n{\n\tthis->str = (char *)copyin(self->buf, MAX_REQ);\n\tthis->str[4] = '\\0';\n\tself->fd = stringof(this->str) == \"GET \" ? self->fd : 0;\n}\n\nsyscall::write:return\n/self->fd/\n{\n\t/* fetch browser request */\n\tthis->str = (char *)copyin(self->buf, MAX_REQ);\n\tthis->str[MAX_REQ] = '\\0';\n\n\t/*\n\t * This unrolled loop strips down a URL to it's hostname.\n\t * We ought to use strtok(), but it's not available on Sol 10 3/05,\n\t * so instead I used dirname(). It's not pretty - it's done so that\n\t * this works on all Sol 10 versions.\n\t */\n\tself->req = stringof(this->str);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->req = dirname(self->req);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->req = dirname(self->req);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->req = dirname(self->req);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->req = dirname(self->req);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->req = dirname(self->req);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->req = dirname(self->req);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->req = dirname(self->req);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->req = dirname(self->req);\n\tself->nam = strlen(self->req) > 15 ? self->req : self->nam;\n\tself->nam = basename(self->nam);\n\n\t/* start the timer */\n\tstart[pid, self->fd - 1] = timestamp;\n\thost[pid, self->fd - 1] = self->nam;\n\tself->buf = 0;\n\tself->fd  = 0;\n\tself->req = 0;\n\tself->nam = 0;\n}\n\n/* this one wasn't a GET */\nsyscall::write:return\n/self->buf/\n{\n\tself->buf = 0;\n\tself->fd  = 0;\n}\n\nsyscall::read:entry\n/execname == BROWSER && start[pid, arg0]/\n{\n\tself->fd = arg0 + 1;\n}\n\n/*\n * Record host details\n */\nsyscall::read:return\n/self->fd/\n{\n\t/* fetch details */\n\tself->host = stringof(host[pid, self->fd - 1]);\n\tthis->start = start[pid, self->fd - 1];\n\n\t/* save details */\n\t@Avg[self->host] = avg((timestamp - this->start)/1000000);\n\t@Max[self->host] = max((timestamp - this->start)/1000000);\n\t@Num[self->host] = count();\n\n\t/* clear vars */\n\tstart[pid, self->fd - 1] = 0;\n\thost[pid, self->fd - 1] = 0;\n\tself->host = 0;\n\tself->fd = 0;\n}\n\n/*\n * Output report\n */\ndtrace:::END\n{\n\tprintf(\"%-32s %11s\\n\", \"HOST\", \"NUM\");\n\tprinta(\"%-32s %@11d\\n\", @Num);\n\n\tprintf(\"\\n%-32s %11s\\n\", \"HOST\", \"AVGTIME(ms)\");\n\tprinta(\"%-32s %@11d\\n\", @Avg);\n\n\tprintf(\"\\n%-32s %11s\\n\", \"HOST\", \"MAXTIME(ms)\");\n\tprinta(\"%-32s %@11d\\n\", @Max);\n}\n"
  },
  {
    "path": "Chap8/j_calls.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * j_calls.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nhotspot*:::method-entry\n{\n\tthis->class = (char *)copyin(arg1, arg2 + 1);\n\tthis->class[arg2] = '\\0';\n\tthis->method = (char *)copyin(arg3, arg4 + 1);\n\tthis->method[arg4] = '\\0';\n\tthis->name = strjoin(strjoin(stringof(this->class), \".\"),\n\t    stringof(this->method));\n\t@calls[pid, \"method\", this->name] = count();\n}\n\nhotspot*:::object-alloc\n{\n\tthis->class = (char *)copyin(arg1, arg2 + 1);\n\tthis->class[arg2] = '\\0';\n\t@calls[pid, \"oalloc\", stringof(this->class)] = count();\n}\n\nhotspot*:::class-loaded\n{\n\tthis->class = (char *)copyin(arg0, arg1 + 1);\n\tthis->class[arg1] = '\\0';\n\t@calls[pid, \"cload\", stringof(this->class)] = count();\n}\n\nhotspot*:::thread-start\n{\n\tthis->thread = (char *)copyin(arg0, arg1 + 1);\n\tthis->thread[arg1] = '\\0';\n\t@calls[pid, \"thread\", stringof(this->thread)] = count();\n}\n\nhotspot*:::method-compile-begin\n{\n\tthis->class = (char *)copyin(arg0, arg1 + 1);\n\tthis->class[arg1] = '\\0';\n\tthis->method = (char *)copyin(arg2, arg3 + 1);\n\tthis->method[arg3] = '\\0';\n\tthis->name = strjoin(strjoin(stringof(this->class), \".\"),\n\t    stringof(this->method));\n\t@calls[pid, \"mcompile\", this->name] = count();\n}\n\nhotspot*:::compiled-method-load\n{\n\tthis->class = (char *)copyin(arg0, arg1 + 1);\n\tthis->class[arg1] = '\\0';\n\tthis->method = (char *)copyin(arg2, arg3 + 1);\n\tthis->method[arg3] = '\\0';\n\tthis->name = strjoin(strjoin(stringof(this->class), \".\"),\n\t    stringof(this->method));\n\t@calls[pid, \"mload\", this->name] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\" %6s %-8s %-52s %8s\\n\", \"PID\", \"TYPE\", \"NAME\", \"COUNT\");\n\tprinta(\" %6d %-8s %-52s %@8d\\n\", @calls);\n}\n"
  },
  {
    "path": "Chap8/j_calltime.d",
    "content": "#!/usr/sbin/dtrace -CZs\n/*\n * j_calltime.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#define\tTOP\t10\t\t/* default output truncation */\n#define\tB_FALSE\t0\n\n#pragma D option quiet\n#pragma D option defaultargs\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n\ttop = $1 != 0 ? $1 : TOP;\n}\n\nhotspot*:::method-entry\n{\n\tself->depth[arg0]++;\n\tself->exclude[arg0, self->depth[arg0]] = 0;\n\tself->method[arg0, self->depth[arg0]] = timestamp;\n}\n\nhotspot*:::method-return\n/self->method[arg0, self->depth[arg0]]/\n{\n\tthis->elapsed_incl = timestamp - self->method[arg0, self->depth[arg0]];\n\tthis->elapsed_excl = this->elapsed_incl -\n\t    self->exclude[arg0, self->depth[arg0]];\n\tself->method[arg0, self->depth[arg0]] = 0;\n\tself->exclude[arg0, self->depth[arg0]] = 0;\n\n\tthis->class = (char *)copyin(arg1, arg2 + 1);\n\tthis->class[arg2] = '\\0';\n\tthis->method = (char *)copyin(arg3, arg4 + 1);\n\tthis->method[arg4] = '\\0';\n\tthis->name = strjoin(strjoin(stringof(this->class), \".\"),\n\t    stringof(this->method));\n\n\t@num[pid, \"method\", this->name] = count();\n\t@num[0, \"total\", \"-\"] = count();\n\t@types_incl[pid, \"method\", this->name] = sum(this->elapsed_incl);\n\t@types_excl[pid, \"method\", this->name] = sum(this->elapsed_excl);\n\t@types_excl[0, \"total\", \"-\"] = sum(this->elapsed_excl);\n\n\tself->depth[arg0]--;\n\tself->exclude[arg0, self->depth[arg0]] += this->elapsed_incl;\n}\n\nhotspot*:::gc-begin\n{\n\tself->gc = timestamp;\n\tself->full = (boolean_t)arg0;\n}\n\nhotspot*:::gc-end\n/self->gc/\n{\n\tthis->elapsed = timestamp - self->gc;\n\tself->gc = 0;\n\n\t@num[pid, \"gc\", self->full == B_FALSE ? \"GC\" : \"Full GC\"] = count();\n\t@types[pid, \"gc\", self->full == B_FALSE ? \"GC\" : \"Full GC\"] =\n\t    sum(this->elapsed);\n\tself->full = 0;\n}\n\ndtrace:::END\n{\n\ttrunc(@num, top);\n\tprintf(\"\\nTop %d counts,\\n\", top);\n\tprintf(\"   %6s %-10s %-48s %8s\\n\", \"PID\", \"TYPE\", \"NAME\", \"COUNT\");\n\tprinta(\"   %6d %-10s %-48s %@8d\\n\", @num);\n\n\ttrunc(@types, top);\n\tnormalize(@types, 1000);\n\tprintf(\"\\nTop %d elapsed times (us),\\n\", top);\n\tprintf(\"   %6s %-10s %-48s %8s\\n\", \"PID\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %6d %-10s %-48s %@8d\\n\", @types);\n\n\ttrunc(@types_excl, top);\n\tnormalize(@types_excl, 1000);\n\tprintf(\"\\nTop %d exclusive method elapsed times (us),\\n\", top);\n\tprintf(\"   %6s %-10s %-48s %8s\\n\", \"PID\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %6d %-10s %-48s %@8d\\n\", @types_excl);\n\n\ttrunc(@types_incl, top);\n\tnormalize(@types_incl, 1000);\n\tprintf(\"\\nTop %d inclusive method elapsed times (us),\\n\", top);\n\tprintf(\"   %6s %-10s %-48s %8s\\n\", \"PID\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %6d %-10s %-48s %@8d\\n\", @types_incl);\n}\n"
  },
  {
    "path": "Chap8/j_flow.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * j_flow.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n/* increasing bufsize can reduce drops */\n#pragma D option bufsize=16m\n#pragma D option quiet\n#pragma D option switchrate=10\n\nself int depth[int];\n\ndtrace:::BEGIN\n{\n\tprintf(\"%3s %6s %-16s -- %s\\n\", \"C\", \"PID\", \"TIME(us)\", \"CLASS.METHOD\");\n}\n\nhotspot*:::method-entry\n{\n\tthis->class = (char *)copyin(arg1, arg2 + 1);\n\tthis->class[arg2] = '\\0';\n\tthis->method = (char *)copyin(arg3, arg4 + 1);\n\tthis->method[arg4] = '\\0';\n\n\tprintf(\"%3d %6d %-16d %*s-> %s.%s\\n\", cpu, pid, timestamp / 1000,\n\t    self->depth[arg0] * 2, \"\", stringof(this->class),\n\tstringof(this->method));\n\tself->depth[arg0]++;\n}\n\nhotspot*:::method-return\n{\n\tthis->class = (char *)copyin(arg1, arg2 + 1);\n\tthis->class[arg2] = '\\0';\n\tthis->method = (char *)copyin(arg3, arg4 + 1);\n\tthis->method[arg4] = '\\0';\n\n\tself->depth[arg0] -= self->depth[arg0] > 0 ? 1 : 0;\n\tprintf(\"%3d %6d %-16d %*s<- %s.%s\\n\", cpu, pid, timestamp / 1000,\n\t    self->depth[arg0] * 2, \"\", stringof(this->class),\n\tstringof(this->method));\n}\n"
  },
  {
    "path": "Chap8/j_thread.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * j_thread.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-20s  %6s/%-5s -- %s\\n\", \"TIME\", \"PID\", \"TID\", \"THREAD\");\n}\n\nhotspot*:::thread-start\n{\n\tthis->thread = (char *)copyin(arg0, arg1 + 1);\n\tthis->thread[arg1] = '\\0';\n\tprintf(\"%-20Y  %6d/%-5d => %s\\n\", walltimestamp, pid, tid,\n\t    stringof(this->thread));\n}\n\nhotspot*:::thread-stop\n{\n\tthis->thread = (char *)copyin(arg0, arg1 + 1);\n\tthis->thread[arg1] = '\\0';\n\tprintf(\"%-20Y  %6d/%-5d <= %s\\n\", walltimestamp, pid, tid,\n\t    stringof(this->thread));\n}\n"
  },
  {
    "path": "Chap8/js_calls.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * js_calls.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing JavaScript... Hit Ctrl-C to end.\\n\");\n}\n\njavascript*:::function-entry\n{\n\tthis->name = copyinstr(arg2);\n\t@calls[basename(copyinstr(arg0)), \"func\", this->name] = count();\n}\n\njavascript*:::execute-start\n{\n\tthis->filename = basename(copyinstr(arg0));\n\t@calls[this->filename, \"exec\", \".\"] = count();\n}\n\njavascript*:::object-create-start\n{\n\tthis->name = copyinstr(arg1);\n\tthis->filename = basename(copyinstr(arg0));\n\t@calls[this->filename, \"obj-new\", this->name] = count();\n}\n\njavascript*:::object-finalize\n{\n\tthis->name = copyinstr(arg1);\n\t@calls[\"<null>\", \"obj-free\", this->name] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\" %-24s %-10s %-30s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"CALLS\");\n\tprinta(\" %-24s %-10s %-30s %@8d\\n\", @calls);\n}\n"
  },
  {
    "path": "Chap8/js_calltime.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * js_calltime.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\njavascript*:::function-entry\n{\n\tself->depth++;\n\tself->exclude[self->depth] = 0;\n\tself->function[self->depth] = timestamp;\n}\n\njavascript*:::function-return\n/self->function[self->depth]/\n{\n\tthis->elapsed_incl = timestamp - self->function[self->depth];\n\tthis->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];\n\tself->function[self->depth] = 0;\n\tself->exclude[self->depth] = 0;\n\tthis->file = basename(copyinstr(arg0));\n\tthis->name = copyinstr(arg2);\n\n\t@num[this->file, \"func\", this->name] = count();\n\t@num[\"-\", \"total\", \"-\"] = count();\n\t@types_incl[this->file, \"func\", this->name] = sum(this->elapsed_incl);\n\t@types_excl[this->file, \"func\", this->name] = sum(this->elapsed_excl);\n\t@types_excl[\"-\", \"total\", \"-\"] = sum(this->elapsed_excl);\n\n\tself->depth--;\n\tself->exclude[self->depth] += this->elapsed_incl;\n}\n\njavascript*:::object-create-start\n{\n\tself->object = timestamp;\n}\n\njavascript*:::object-create-done\n/self->object/\n{\n\tthis->elapsed = timestamp - self->object;\n\tself->object = 0;\n\tthis->file = basename(copyinstr(arg0));\n\tthis->name = copyinstr(arg1);\n\n\t@num[this->file, \"obj-new\", this->name] = count();\n\t@num[\"-\", \"total\", \"-\"] = count();\n\t@types[this->file, \"obj-new\", this->name] = sum(this->elapsed);\n\t@types[\"-\", \"total\", \"-\"] = sum(this->elapsed);\n\n\tself->exclude[self->depth] += this->elapsed;\n}\n\ndtrace:::END\n{\n\tprintf(\"\\nCount,\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"COUNT\");\n\tprinta(\"   %-20.20s %-10s %-32s %@8d\\n\", @num);\n\n\tnormalize(@types, 1000);\n\tprintf(\"\\nElapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20.20s %-10s %-32s %@8d\\n\", @types);\n\n\tnormalize(@types_excl, 1000);\n\tprintf(\"\\nExclusive function elapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20.20s %-10s %-32s %@8d\\n\", @types_excl);\n\n\tnormalize(@types_incl, 1000);\n\tprintf(\"\\nInclusive function elapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20.20s %-10s %-32s %@8d\\n\", @types_incl);\n}\n"
  },
  {
    "path": "Chap8/js_flowinfo.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * js_flowinfo.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\nself int depth;\n\ndtrace:::BEGIN\n{\n\tprintf(\"%3s %6s %10s  %16s:%-4s %-8s -- %s\\n\", \"C\", \"PID\", \"DELTA(us)\",\n\t    \"FILE\", \"LINE\", \"TYPE\", \"FUNC\");\n}\n\njavascript*:::function-info,\njavascript*:::function-return\n/self->last == 0/\n{\n\tself->last = timestamp;\n}\n\njavascript*:::function-info\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tprintf(\"%3d %6d %10d  %16s:%-4d %-8s %*s-> %s\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg4)), arg5, \"func\",\n\tself->depth * 2, \"\", copyinstr(arg2));\n\tself->depth++;\n\tself->last = timestamp;\n}\n\njavascript*:::function-return\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%3d %6d %10d  %16s:-    %-8s %*s<- %s\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), \"func\", self->depth * 2,\n\t    \"\", copyinstr(arg2));\n\tself->last = timestamp;\n}\n"
  },
  {
    "path": "Chap8/php_calls.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * php_calls.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing PHP... Hit Ctrl-C to end.\\n\");\n}\n\nphp*:::function-entry\n{\n\t@funcs[basename(copyinstr(arg1)), copyinstr(arg0)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\" %-32s %-32s %8s\\n\", \"FILE\", \"FUNC\", \"CALLS\");\n\tprinta(\" %-32s %-32s %@8d\\n\", @funcs);\n}\n"
  },
  {
    "path": "Chap8/php_flowinfo.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * php_flowinfo.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\nself int depth;\n\ndtrace:::BEGIN\n{\n\tprintf(\"%s %6s/%-4s %10s  %16s:%-4s %-8s -- %s\\n\", \"C\", \"PID\", \"TID\",\n\t    \"DELTA(us)\", \"FILE\", \"LINE\", \"TYPE\", \"FUNC\");\n}\n\nphp*:::function-entry,\nphp*:::function-return\n/self->last == 0/\n{\n\tself->last = timestamp;\n}\n\nphp*:::function-entry\n/arg0/\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tprintf(\"%d %6d/%-4d %10d  %16s:%-4d %-8s %*s-> %s\\n\", cpu, pid, tid,\n\t    this->delta, basename(copyinstr(arg1)), arg2, \"func\",\n\t    self->depth * 2, \"\", copyinstr(arg0));\n\tself->depth++;\n\tself->last = timestamp;\n}\n\nphp*:::function-return\n/arg0/\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%d %6d/%-4d %10d  %16s:%-4d %-8s %*s<- %s\\n\", cpu, pid, tid,\n\t    this->delta, basename(copyinstr(arg1)), arg2, \"func\",\n\tself->depth * 2, \"\", copyinstr(arg0));\n\tself->last = timestamp;\n}\n"
  },
  {
    "path": "Chap8/pl_calls.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * pl_calls.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing Perl... Hit Ctrl-C to end.\\n\");\n}\n\nperl*:::sub-entry\n{\n\t@subs[pid, basename(copyinstr(arg1)), copyinstr(arg0)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"%-6s %-30s %-30s %8s\\n\", \"PID\", \"FILE\", \"SUB\", \"CALLS\");\n\tprinta(\"%-6d %-30s %-30s %@8d\\n\", @subs);\n}\n"
  },
  {
    "path": "Chap8/pl_calltime.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * pl_calltime.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nperl*:::sub-entry\n{\n\tself->depth++;\n\tself->exclude[self->depth] = 0;\n\tself->sub[self->depth] = timestamp;\n}\n\nperl*:::sub-return\n/self->sub[self->depth]/\n{\n\tthis->elapsed_incl = timestamp - self->sub[self->depth];\n\tthis->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];\n\tself->sub[self->depth] = 0;\n\tself->exclude[self->depth] = 0;\n\tthis->file = basename(copyinstr(arg1));\n\tthis->name = copyinstr(arg0);\n\n\t@num[this->file, \"sub\", this->name] = count();\n\t@num[\"-\", \"total\", \"-\"] = count();\n\t@types_incl[this->file, \"sub\", this->name] = sum(this->elapsed_incl);\n\t@types_excl[this->file, \"sub\", this->name] = sum(this->elapsed_excl);\n\t@types_excl[\"-\", \"total\", \"-\"] = sum(this->elapsed_excl);\n\n\tself->depth--;\n\tself->exclude[self->depth] += this->elapsed_incl;\n}\n\ndtrace:::END\n{\n\tprintf(\"\\nCount,\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"COUNT\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @num);\n\n\tnormalize(@types_excl, 1000);\n\tprintf(\"\\nExclusive subroutine elapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @types_excl);\n\n\tnormalize(@types_incl, 1000);\n\tprintf(\"\\nInclusive subroutine elapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @types_incl);\n}\n"
  },
  {
    "path": "Chap8/pl_flowinfo.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * pl_flowinfo.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\nself int depth;\n\ndtrace:::BEGIN\n{\n\tprintf(\"%s %6s %10s  %16s:%-4s %-8s -- %s\\n\", \"C\", \"PID\", \"DELTA(us)\",\n\t    \"FILE\", \"LINE\", \"TYPE\", \"SUB\");\n}\n\nperl*:::sub-entry,\nperl*:::sub-return\n/self->last == 0/\n{\n\tself->last = timestamp;\n}\n\nperl*:::sub-entry\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tprintf(\"%d %6d %10d  %16s:%-4d %-8s %*s-> %s\\n\", cpu, pid, this->delta,\n\t    basename(copyinstr(arg1)), arg2, \"sub\", self->depth * 2, \"\",\n\t    copyinstr(arg0));\n\tself->depth++;\n\tself->last = timestamp;\n}\n\nperl*:::sub-return\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%d %6d %10d  %16s:%-4d %-8s %*s<- %s\\n\", cpu, pid, this->delta,\n\t    basename(copyinstr(arg1)), arg2, \"sub\", self->depth * 2, \"\",\n\tcopyinstr(arg0));\n\tself->last = timestamp;\n}\n"
  },
  {
    "path": "Chap8/pl_who.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * pl_who.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nperl*:::sub-entry\n{\n\t@lines[pid, uid, copyinstr(arg1)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %6s %6s %6s %s\\n\", \"PID\", \"UID\", \"SUBS\", \"FILE\");\n\tprinta(\"   %6d %6d %@6d %s\\n\", @lines);\n}\n"
  },
  {
    "path": "Chap8/py_calls.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * py_calls.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing Python... Hit Ctrl-C to end.\\n\");\n}\n\npython*:::function-entry\n{\n\t@funcs[pid, basename(copyinstr(arg0)), copyinstr(arg1)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"%-6s %-30s %-30s %8s\\n\", \"PID\", \"FILE\", \"FUNC\", \"CALLS\");\n\tprinta(\"%-6d %-30s %-30s %@8d\\n\", @funcs);\n}\n"
  },
  {
    "path": "Chap8/py_calltime.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * py_calltime.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\npython*:::function-entry\n{\n\tself->depth++;\n\tself->exclude[self->depth] = 0;\n\tself->function[self->depth] = timestamp;\n}\n\npython*:::function-return\n/self->function[self->depth]/\n{\n\tthis->elapsed_incl = timestamp - self->function[self->depth];\n\tthis->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];\n\tself->function[self->depth] = 0;\n\tself->exclude[self->depth] = 0;\n\tthis->file = basename(copyinstr(arg0));\n\tthis->name = copyinstr(arg1);\n\n\t@num[this->file, \"func\", this->name] = count();\n\t@num[\"-\", \"total\", \"-\"] = count();\n\t@types_incl[this->file, \"func\", this->name] = sum(this->elapsed_incl);\n\t@types_excl[this->file, \"func\", this->name] = sum(this->elapsed_excl);\n\t@types_excl[\"-\", \"total\", \"-\"] = sum(this->elapsed_excl);\n\n\tself->depth--;\n\tself->exclude[self->depth] += this->elapsed_incl;\n}\n\ndtrace:::END\n{\n\tprintf(\"\\nCount,\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"COUNT\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @num);\n\n\tnormalize(@types_excl, 1000);\n\tprintf(\"\\nExclusive function elapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @types_excl);\n\n\tnormalize(@types_incl, 1000);\n\tprintf(\"\\nInclusive function elapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @types_incl);\n}\n"
  },
  {
    "path": "Chap8/py_flowinfo.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * py_flowinfo.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\nself int depth;\n\ndtrace:::BEGIN\n{\n\tprintf(\"%s %6s %10s  %16s:%-4s %-8s -- %s\\n\", \"C\", \"PID\", \"DELTA(us)\",\n\t    \"FILE\", \"LINE\", \"TYPE\", \"FUNC\");\n}\n\npython*:::function-entry,\npython*:::function-return\n/self->last == 0/\n{\n\tself->last = timestamp;\n}\n\npython*:::function-entry\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tprintf(\"%d %6d %10d  %16s:%-4d %-8s %*s-> %s\\n\", cpu, pid, this->delta,\n\t    basename(copyinstr(arg0)), arg2, \"func\", self->depth * 2, \"\",\n\t    copyinstr(arg1));\n\tself->depth++;\n\tself->last = timestamp;\n}\n\npython*:::function-return\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%d %6d %10d  %16s:%-4d %-8s %*s<- %s\\n\", cpu, pid, this->delta,\n\t    basename(copyinstr(arg0)), arg2, \"func\", self->depth * 2, \"\",\n\t    copyinstr(arg1));\n\tself->last = timestamp;\n}\n"
  },
  {
    "path": "Chap8/py_who.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * py_who.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\npython*:::function-entry\n{\n\t@lines[pid, uid, copyinstr(arg0)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %6s %6s %6s %s\\n\", \"PID\", \"UID\", \"FUNCS\", \"FILE\");\n\tprinta(\"   %6d %6d %@6d %s\\n\", @lines);\n}\n"
  },
  {
    "path": "Chap8/rb_calls.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * rb_calls.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing Ruby... Hit Ctrl-C to end.\\n\");\n}\n\nruby*:::function-entry\n{\n\t@funcs[pid, basename(copyinstr(arg2)), copyinstr(arg0),\n\t    copyinstr(arg1)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"%-6s %-28.28s %-16s %-16s %8s\\n\", \"PID\", \"FILE\", \"CLASS\",\n\t    \"METHOD\", \"CALLS\");\n\tprinta(\"%-6d %-28.28s %-16s %-16s %@8d\\n\", @funcs);\n}\n"
  },
  {
    "path": "Chap8/rb_calltime.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * rb_calltime.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nruby*:::function-entry\n{\n\tself->depth++;\n\tself->exclude[self->depth] = 0;\n\tself->function[self->depth] = timestamp;\n}\n\nruby*:::function-return\n/self->function[self->depth]/\n{\n\tthis->elapsed_incl = timestamp - self->function[self->depth];\n\tthis->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];\n\tself->function[self->depth] = 0;\n\tself->exclude[self->depth] = 0;\n\tthis->file = basename(copyinstr(arg2));\n\tthis->name = strjoin(strjoin(copyinstr(arg0), \"::\"), copyinstr(arg1));\n\n\t@num[this->file, \"func\", this->name] = count();\n\t@num[\"-\", \"total\", \"-\"] = count();\n\t@types_incl[this->file, \"func\", this->name] = sum(this->elapsed_incl);\n\t@types_excl[this->file, \"func\", this->name] = sum(this->elapsed_excl);\n\t@types_excl[\"-\", \"total\", \"-\"] = sum(this->elapsed_excl);\n\n\tself->depth--;\n\tself->exclude[self->depth] += this->elapsed_incl;\n}\n\nruby*:::object-create-start\n{\n\tself->object = timestamp;\n}\n\nruby*:::object-create-done\n/self->object/\n{\n\tthis->elapsed = timestamp - self->object;\n\tself->object = 0;\n\tthis->file = basename(copyinstr(arg1));\n\tthis->file = this->file != NULL ? this->file : \".\";\n\tthis->name = copyinstr(arg0);\n\n\t@num[this->file, \"obj-new\", this->name] = count();\n\t@types[this->file, \"obj-new\", this->name] = sum(this->elapsed);\n\n\tself->exclude[self->depth] += this->elapsed;\n}\n\nruby*:::gc-begin\n{\n\tself->gc = timestamp;\n}\n\nruby*:::gc-end\n/self->gc/\n{\n\tthis->elapsed = timestamp - self->gc;\n\tself->gc = 0;\n\t@num[\".\", \"gc\", \"-\"] = count();\n\t@types[\".\", \"gc\", \"-\"] = sum(this->elapsed);\n\tself->exclude[self->depth] += this->elapsed;\n}\n\ndtrace:::END\n{\n\tprintf(\"\\nCount,\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"COUNT\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @num);\n\n\tnormalize(@types, 1000);\n\tprintf(\"\\nElapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @types);\n\n\tnormalize(@types_excl, 1000);\n\tprintf(\"\\nExclusive function elapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @types_excl);\n\n\tnormalize(@types_incl, 1000);\n\tprintf(\"\\nInclusive function elapsed times (us),\\n\");\n\tprintf(\"   %-20s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"TOTAL\");\n\tprinta(\"   %-20s %-10s %-32s %@8d\\n\", @types_incl);\n}\n"
  },
  {
    "path": "Chap8/rb_flowinfo.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * rb_flowinfo.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\nself int depth;\n\ndtrace:::BEGIN\n{\n\tprintf(\"%s %6s %10s  %16s:%-4s %-8s -- %s\\n\", \"C\", \"PID\", \"DELTA(us)\",\n\t    \"FILE\", \"LINE\", \"TYPE\", \"NAME\");\n}\n\nruby*:::function-entry,\nruby*:::function-return\n/self->last == 0/\n{\n\tself->last = timestamp;\n}\n\nruby*:::function-entry\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tthis->name = strjoin(strjoin(copyinstr(arg0), \"::\"), copyinstr(arg1));\n\tprintf(\"%d %6d %10d  %16s:%-4d %-8s %*s-> %s\\n\", cpu, pid, this->delta,\n\t    basename(copyinstr(arg2)), arg3, \"method\", self->depth * 2, \"\",\n\t    this->name);\n\tself->depth++;\n\tself->last = timestamp;\n}\n\nruby*:::function-return\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tthis->name = strjoin(strjoin(copyinstr(arg0), \"::\"), copyinstr(arg1));\n\tprintf(\"%d %6d %10d  %16s:%-4d %-8s %*s<- %s\\n\", cpu, pid, this->delta,\n\t    basename(copyinstr(arg2)), arg3, \"method\", self->depth * 2, \"\",\n\tthis->name);\n\tself->last = timestamp;\n}\n"
  },
  {
    "path": "Chap8/rb_who.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * rb_who.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nruby*:::line\n{\n\t@lines[pid, uid, copyinstr(arg0)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %6s %6s %10s %s\\n\", \"PID\", \"UID\", \"LINES\", \"FILE\");\n\tprinta(\"   %6d %6d %@10d %s\\n\", @lines);\n}\n"
  },
  {
    "path": "Chap8/sh_calls.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * sh_calls.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nsh*:::function-entry\n{\n\t@calls[basename(copyinstr(arg0)), \"func\", copyinstr(arg1)] = count();\n}\n\nsh*:::builtin-entry\n{\n\t@calls[basename(copyinstr(arg0)), \"builtin\", copyinstr(arg1)] = count();\n}\n\nsh*:::command-entry\n{\n\t@calls[basename(copyinstr(arg0)), \"cmd\", copyinstr(arg1)] = count();\n}\n\nsh*:::subshell-entry\n/arg1 != 0/\n{\n\t@calls[basename(copyinstr(arg0)), \"subsh\", \"-\"] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\" %-22s %-10s %-32s %8s\\n\", \"FILE\", \"TYPE\", \"NAME\", \"COUNT\");\n\tprinta(\" %-22s %-10s %-32s %@8d\\n\", @calls);\n}\n"
  },
  {
    "path": "Chap8/sh_flowinfo.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * sh_flowinfo.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\nself int depth;\n\ndtrace:::BEGIN\n{\n\tself->depth = 0;\n\tprintf(\"%3s %6s %10s  %16s:%-4s %-8s -- %s\\n\", \"C\", \"PID\", \"DELTA(us)\",\n\t    \"FILE\", \"LINE\", \"TYPE\", \"NAME\");\n}\n\nsh*:::function-entry,\nsh*:::function-return,\nsh*:::builtin-entry,\nsh*:::builtin-return,\nsh*:::command-entry,\nsh*:::command-return,\nsh*:::subshell-entry,\nsh*:::subshell-return\n/self->last == 0/\n{\n\tself->last = timestamp;\n}\n\nsh*:::function-entry\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tprintf(\"%3d %6d %10d  %16s:%-4d %-8s %*s-> %s\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), arg2, \"func\",\n\t    self->depth * 2, \"\", copyinstr(arg1));\n\tself->depth++;\n\tself->last = timestamp;\n}\n\nsh*:::function-return\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%3d %6d %10d  %16s:-    %-8s %*s<- %s\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), \"func\", self->depth * 2,\n\t    \"\", copyinstr(arg1));\n\tself->last = timestamp;\n}\n\nsh*:::builtin-entry\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tprintf(\"%3d %6d %10d  %16s:%-4d %-8s %*s-> %s\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), arg2, \"builtin\",\n\t    self->depth * 2, \"\", copyinstr(arg1));\n\tself->depth++;\n\tself->last = timestamp;\n}\n\nsh*:::builtin-return\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%3d %6d %10d  %16s:-    %-8s %*s<- %s\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), \"builtin\",\n\tself->depth * 2, \"\", copyinstr(arg1));\n\tself->last = timestamp;\n}\n\nsh*:::command-entry\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tprintf(\"%3d %6d %10d  %16s:%-4d %-8s %*s-> %s\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), arg2, \"cmd\",\n\t    self->depth * 2, \"\", copyinstr(arg1));\n\tself->depth++;\n\tself->last = timestamp;\n}\n\nsh*:::command-return\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%3d %6d %10d  %16s:-    %-8s %*s<- %s\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), \"cmd\",\n\t    self->depth * 2, \"\", copyinstr(arg1));\n\tself->last = timestamp;\n}\n\nsh*:::subshell-entry\n/arg1 != 0/\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tprintf(\"%3d %6d %10d  %16s:-    %-8s %*s-> pid %d\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), \"subsh\",\n\t    self->depth * 2, \"\", arg1);\n\tself->depth++;\n\tself->last = timestamp;\n}\n\nsh*:::subshell-return\n/self->last/\n{\n\tthis->delta = (timestamp - self->last) / 1000;\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%3d %6d %10d  %16s:-    %-8s %*s<- = %d\\n\", cpu, pid,\n\t    this->delta, basename(copyinstr(arg0)), \"subsh\",\n\t    self->depth * 2, \"\", arg1);\n\tself->last = timestamp;\n}\n"
  },
  {
    "path": "Chap8/sh_who.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * sh_who.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nsh*:::line\n{\n\t@lines[pid, uid, copyinstr(arg0)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %6s %6s %6s %s\\n\", \"PID\", \"UID\", \"LINES\", \"FILE\");\n\tprinta(\"   %6d %6d %@6d %s\\n\", @lines);\n}\n"
  },
  {
    "path": "Chap8/tcl_calls.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * tcl_calls.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing Tcl... Hit Ctrl-C to end.\\n\");\n}\n\ntcl*:::proc-entry\n{\n\t@calls[pid, \"proc\", copyinstr(arg0)] = count();\n}\n\ntcl*:::cmd-entry\n{\n\t@calls[pid, \"cmd\", copyinstr(arg0)] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\" %6s %-8s %-52s %8s\\n\", \"PID\", \"TYPE\", \"NAME\", \"COUNT\");\n\tprinta(\" %6d %-8s %-52s %@8d\\n\", @calls);\n}\n"
  },
  {
    "path": "Chap8/tcl_procflow.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * tcl_procflow.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10\n\nself int depth;\n\ndtrace:::BEGIN\n{\n\tprintf(\"%3s %6s %-16s -- %s\\n\", \"C\", \"PID\", \"TIME(us)\", \"PROCEDURE\");\n}\n\ntcl*:::proc-entry\n{\n\tprintf(\"%3d %6d %-16d %*s-> %s\\n\", cpu, pid, timestamp / 1000,\n\tself->depth * 2, \"\", copyinstr(arg0));\n\tself->depth++;\n}\n\ntcl*:::proc-return\n{\n\tself->depth -= self->depth > 0 ? 1 : 0;\n\tprintf(\"%3d %6d %-16d %*s<- %s\\n\", cpu, pid, timestamp / 1000,\n\t    self->depth * 2, \"\", copyinstr(arg0));\n}\n"
  },
  {
    "path": "Chap8/tcl_who.d",
    "content": "#!/usr/sbin/dtrace -Zs\n/*\n * tcl_who.d\n *\n * Example script from Chapter 8 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing Tcl... Hit Ctrl-C to end.\\n\");\n}\n\ntcl*:::cmd-entry\n{\n\t@calls[pid, uid, curpsinfo->pr_psargs] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"   %6s %6s %6s %-55s\\n\", \"PID\", \"UID\", \"CMDS\", \"ARGS\");\n\tprinta(\"   %6d %6d %@6d %-55.55s\\n\", @calls);\n}\n"
  },
  {
    "path": "Chap9/kill.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * kill.d\n *\n * Example script from Chapter 9 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-6s %12s %6s %-8s %s\\n\",\n\t    \"FROM\", \"COMMAND\", \"SIG\", \"TO\", \"RESULT\");\n}\n\nsyscall::kill:entry\n{\n\tself->target = (int)arg0;\n\tself->signal = arg1;\n}\n\nsyscall::kill:return\n{\n\tprintf(\"%-6d %12s %6d %-8d %d\\n\",\n\t    pid, execname, self->signal, self->target, (int)arg0);\n\tself->target = 0;\n\tself->signal = 0;\n}\n"
  },
  {
    "path": "Chap9/procsnoop.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * procsnoop.d\n *\n * Example script from Chapter 9 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n#pragma D option switchrate=10hz\n\ndtrace:::BEGIN\n{\n\tprintf(\"%-8s %5s %6s %6s %s\\n\", \"TIME(ms)\", \"UID\", \"PID\", \"PPID\",\n\t    \"COMMAND\");\n\tstart = timestamp;\n}\n\nproc:::exec-success\n{\n\tprintf(\"%-8d %5d %6d %6d %s\\n\", (timestamp - start) / 1000000,\n\t    uid, pid, ppid, curpsinfo->pr_psargs);\n}\n"
  },
  {
    "path": "Chap9/sigdist.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * sigdist.d\n *\n * Example script from Chapter 9 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\ndtrace:::BEGIN\n{\n\tprintf(\"Tracing... Hit Ctrl-C to end.\\n\");\n}\n\nproc:::signal-send\n{\n\t@Count[execname, stringof(args[1]->pr_fname), args[2]] = count();\n}\n\ndtrace:::END\n{\n\tprintf(\"%16s %16s %6s %6s\\n\", \"SENDER\", \"RECIPIENT\", \"SIG\", \"COUNT\");\n\tprinta(\"%16s %16s %6d %6@d\\n\", @Count);\n}\n"
  },
  {
    "path": "Chap9/threaded.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * threaded.d\n *\n * Example script from Chapter 9 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\n#pragma D option quiet\n\nprofile:::profile-101\n/pid != 0/\n{\n\t@sample[pid, execname] = lquantize(tid, 0, 128, 1);\n}\n\nprofile:::tick-1sec\n{\n\tprintf(\"%Y,\\n\", walltimestamp);\n\tprinta(\"\\n @101hz   PID: %-8d CMD: %s\\n%@d\", @sample);\n\tprintf(\"\\n\");\n\ttrunc(@sample);\n}\n"
  },
  {
    "path": "Chap9/uoffcpu.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * uoffcpu.d\n *\n * Example script from Chapter 9 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nsched:::off-cpu\n/execname == $$1/\n{\n\tself->start = timestamp;\n}\n\nsched:::on-cpu\n/self->start/\n{\n\tthis->delta = (timestamp - self->start) / 1000;\n\t@[\"off-cpu (us):\", ustack()] = quantize(this->delta);\n\tself->start = 0;\n}\n"
  },
  {
    "path": "Chap9/uoncpu.d",
    "content": "#!/usr/sbin/dtrace -s\n/*\n * uoncpu.d\n *\n * Example script from Chapter 9 of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n * \n * See the book for the script description and warnings. Many of these are\n * provided as example solutions, and will need changes to work on your OS.\n */\n\nprofile:::profile-1001\n/execname == $$1/\n{\n\t@[\"\\n  on-cpu (count @1001hz):\", ustack()] = count();\n}\n"
  },
  {
    "path": "README.md",
    "content": "DTrace book scripts\n===================\n\nScripts from \"DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro, Prentice Hall, 2011.\nISBN-10: 0132091518, ISBN-13: 978-0132091510\n\nThis is a copy of the scripts published on http://dtracebook.com, and is a static collection to support the book.\n\nSee the book for descriptions of these scripts, examples, and any related warnings.\n\nWARNING: These scripts are not tools that are expected to work. They are examples of solving problems, but are often tied to the kernel version they were written for. You can treat them as starting points: they embody an idea, approach, and presentation for an observability problem. Their implementation details will likely need adjusting to work correctly on your OS. This is explained, in detail, in the book, which should help you use and update the scripts as needed.\n\nThe hardest part of using DTrace is knowing what to do with it. That is what these scripts provide -- proven usage ideas. Even if they don't work on your current kernel version, they still help with the hardest problem faced by new users of DTrace, showing by example what can be done. The nature of dynamic tracing (the DTrace fbt and pid providers) means that writing tools that work across every OS, now, and in the future, is not possible.\n\nIf you repurpose a script (in the same way that a reader of a textbook might reuse an example), I'd ask that you please identify the origin in the script; eg, in the header:\n\n```\n * Based on a script from Chapter X of the book: DTrace: Dynamic Tracing in\n * Oracle Solaris, Mac OS X, and FreeBSD\", by Brendan Gregg and Jim Mauro,\n * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.\n```\n\nThanks to [Mike Harsch](https://github.com/mharsch) for transcribing and testing these scripts.\n"
  }
]