1 #!/usr/sbin/dtrace -s
2 /*
3 * ziosnoop.d
4 *
5 * Example script from Chapter 5 of the book: DTrace: Dynamic Tracing in
6 * Oracle Solaris, Mac OS X, and FreeBSD", by Brendan Gregg and Jim Mauro,
7 * Prentice Hall, 2011. ISBN-10: 0132091518. http://dtracebook.com.
8 *
9 * See the book for the script description and warnings. Many of these are
10 * provided as example solutions, and will need changes to work on your OS.
11 */
12
13 #pragma D option quiet
14 #pragma D option defaultargs
15 #pragma D option switchrate=10hz
16
17 dtrace:::BEGIN
18 {
19 start = timestamp;
20 printf("%-10s %-3s %-12s %-16s %s\n", "TIME(us)", "CPU",
21 "ZIO_EVENT", "ARG0", "INFO (see script)");
22 }
23
24 fbt::zfs_read:entry,
25 fbt::zfs_write:entry
26 { self->vp = args[0]; }
27
28 fbt::zfs_read:return,
29 fbt::zfs_write:return
30 { self->vp = 0; }
31
32 fbt::zio_create:return
33 /$1 || args[1]->io_type/
34 {
35 /* INFO: pool zio_type zio_flag bytes path */
36 printf("%-10d %-3d %-12s %-16x %s %d %x %d %s\n",
37 (timestamp - start) / 1000, cpu, "CREATED", arg1,
38 stringof(args[1]->io_spa->spa_name), args[1]->io_type,
39 args[1]->io_flags, args[1]->io_size, self->vp &&
40 self->vp->v_path ? stringof(self->vp->v_path) : "<null>");
41 }
42
43 fbt::zio_*:entry
44 /$1/
45 {
46 printf("%-10d %-3d %-12s %-16x\n", (timestamp - start) / 1000, cpu,
47 probefunc, arg0);
48 }
49
50 fbt::zio_done:entry
51 /$1 || args[0]->io_type/
52 {
53 /* INFO: io_error vdev_state vdev_path */
54 printf("%-10d %-3d %-12s %-16x %d %d %s\n", (timestamp - start) / 1000,
55 cpu, "DONE", arg0, args[0]->io_error,
56 args[0]->io_vd ? args[0]->io_vd->vdev_state : 0,
57 args[0]->io_vd && args[0]->io_vd->vdev_path ?
58 stringof(args[0]->io_vd->vdev_path) : "<null>");
59 }