Permalink
Browse files

some ZFS DTrace scripts

  • Loading branch information...
1 parent 52c72bb commit 9d5da6eb7c426372132a274e86ddb1438e58aeef Brendan Gregg committed Aug 13, 2012
Showing with 473 additions and 0 deletions.
  1. +53 −0 fs/metaslab_free.d
  2. +71 −0 fs/spasync.d
  3. +60 −0 fs/zfsdist.d
  4. +81 −0 fs/zfsslower.d
  5. +74 −0 fs/zfsslowzone.d
  6. +87 −0 fs/zfswhozone.d
  7. +47 −0 fs/ziowait.d
View
@@ -0,0 +1,53 @@
+#!/usr/sbin/dtrace -s
+/*
+ * metaslab_free.d Show ZFS metaslab percent free on allocations.
+ *
+ * ZFS switches to a slower allocation algorithm when the free size in a
+ * metaslab (usually 16 Gbytes) is less than a percentage. The slower
+ * algorithm is best-fit instead of fast-fit.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing ZFS metaslab alloc. metaslab_df_free_pct = %d %%\n",
+ `metaslab_df_free_pct);
+}
+
+fbt::metaslab_df_alloc:entry
+{
+ this->pct = args[0]->sm_space * 100 / args[0]->sm_size;
+ @[this->pct] = count();
+}
+
+profile:::tick-1s
+{
+ printf("\n%Y free %%pct by allocations:", walltimestamp);
+ printa(@);
+ trunc(@);
+}
View
@@ -0,0 +1,71 @@
+#!/usr/sbin/dtrace -s
+/*
+ * spasync.d Trace ZFS spa_sync() with details.
+ *
+ * From Chap 5 in the DTrace book, and based on spasync.d from Ben, Roch, Matt.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ */
+
+#pragma D option quiet
+
+inline int MIN_MS = 1;
+
+dtrace:::BEGIN
+{
+ printf("Tracing ZFS spa_sync() slower than %d ms...\n", MIN_MS);
+ @bytes = sum(0);
+}
+
+fbt::spa_sync:entry
+/!self->start/
+{
+ in_spa_sync = 1;
+ self->start = timestamp;
+ self->spa = args[0];
+}
+
+io:::start
+/in_spa_sync/
+{
+ @io = count();
+ @bytes = sum(args[0]->b_bcount);
+}
+
+fbt::spa_sync:return
+/self->start && (this->ms = (timestamp - self->start) / 1000000) > MIN_MS/
+{
+ normalize(@bytes, 1048576);
+ printf("%-20Y %-10s %6d ms, ", walltimestamp,
+ stringof(self->spa->spa_name), this->ms);
+ printa("%@d MB %@d I/O\n", @bytes, @io);
+}
+
+fbt::spa_sync:return
+{
+ self->start = 0; self->spa = 0; in_spa_sync = 0;
+ clear(@bytes); clear(@io);
+}
+
View
@@ -0,0 +1,60 @@
+#!/usr/sbin/dtrace -s
+/*
+ * zfsdist.d Show ZFS/VFS latency distributions.
+ *
+ * Some common ZFS/VFS calls are traced (see below).
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ *
+ * TESTED: this fbt provider based script may only work on some OS versions.
+ * 121: ok
+ */
+
+fbt::zfs_read:entry,
+fbt::zfs_write:entry,
+fbt::zfs_readdir:entry,
+fbt::zfs_getattr:entry,
+fbt::zfs_setattr:entry
+{
+ self->start = timestamp;
+}
+
+fbt::zfs_read:return,
+fbt::zfs_write:return,
+fbt::zfs_readdir:return,
+fbt::zfs_getattr:return,
+fbt::zfs_setattr:return
+/self->start/
+{
+ this->time = timestamp - self->start;
+ @[probefunc, "time (ns)"] = quantize(this->time);
+ self->start = 0;
+}
+
+dtrace:::END
+{
+ printa(@);
+ trunc(@);
+}
View
@@ -0,0 +1,81 @@
+#!/usr/sbin/dtrace -s
+/*
+ * zfsslower.d show ZFS I/O taking longer than given ms.
+ *
+ * USAGE: zfsslower.d min_ms
+ * eg,
+ * zfsslower.d 100 # show I/O at least 100 ms
+ *
+ * This is from the DTrace book, chapter 5. It has been enhanced to include
+ * zfs_readdir() as well, which is shown in the "D" (direction) field as "D".
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ *
+ * TESTED: this fbt provider based script may only work on some OS versions.
+ * 121: ok
+ */
+
+#pragma D option quiet
+#pragma D option defaultargs
+#pragma D option switchrate=10hz
+
+dtrace:::BEGIN
+{
+ printf("%-20s %-16s %1s %4s %6s %s\n", "TIME", "PROCESS",
+ "D", "KB", "ms", "FILE");
+ min_ns = $1 * 1000000;
+}
+
+/* see uts/common/fs/zfs/zfs_vnops.c */
+
+fbt::zfs_read:entry, fbt::zfs_write:entry
+{
+ self->path = args[0]->v_path;
+ self->kb = args[1]->uio_resid / 1024;
+ self->start = timestamp;
+}
+
+fbt::zfs_readdir:entry
+{
+ self->path = args[0]->v_path;
+ self->kb = 0;
+ self->start = timestamp;
+}
+
+fbt::zfs_read:return, fbt::zfs_write:return, fbt::zfs_readdir:return
+/self->start && (timestamp - self->start) >= min_ns/
+{
+ this->iotime = (timestamp - self->start) / 1000000;
+ this->dir = probefunc == "zfs_read" ? "R" :
+ probefunc == "zfs_write" ? "W" : "D";
+ printf("%-20Y %-16s %1s %4d %6d %s\n", walltimestamp,
+ execname, this->dir, self->kb, this->iotime,
+ self->path != NULL ? stringof(self->path) : "<null>");
+}
+
+fbt::zfs_read:return, fbt::zfs_write:return, fbt::zfs_readdir:return
+{
+ self->path = 0; self->kb = 0; self->start = 0;
+}
View
@@ -0,0 +1,74 @@
+#!/usr/sbin/dtrace -s
+/*
+ * zfsslowzone.d Trace slow ZFS/VFS reads and writes.
+ *
+ * USAGE: zfsslowzone.d min_ms
+ * eg,
+ * zfsslowzone.d 50 # show I/O longer than 50 ms
+ *
+ * This traces at the VFS layer, so the latency shown is directly suffered
+ * by the application. The output is wide (sorry). This script is based
+ * on zfsslower.d from the DTrace book.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ *
+ * TESTED: this fbt provider based script may only work on some OS versions.
+ * 121: ok
+ */
+
+#pragma D option quiet
+#pragma D option defaultargs
+#pragma D option switchrate=10hz
+
+dtrace:::BEGIN
+{
+ printf("%-20s %-16s %-12s %1s %4s %6s %s\n", "TIME", "PROCESS",
+ "ZONE", "D", "KB", "ms", "FILE");
+ min_ns = $1 * 1000000;
+}
+
+/* see uts/common/fs/zfs/zfs_vnops.c */
+
+fbt::zfs_read:entry, fbt::zfs_write:entry
+{
+ self->path = args[0]->v_path;
+ self->kb = args[1]->uio_resid / 1024;
+ self->start = timestamp;
+}
+
+fbt::zfs_read:return, fbt::zfs_write:return
+/self->start && (timestamp - self->start) >= min_ns/
+{
+ this->iotime = (timestamp - self->start) / 1000000;
+ this->dir = probefunc == "zfs_read" ? "R" : "W";
+ printf("%-20Y %-16s %-12s %1s %4d %6d %s\n", walltimestamp,
+ execname, zonename, this->dir, self->kb, this->iotime,
+ self->path != NULL ? stringof(self->path) : "<null>");
+}
+
+fbt::zfs_read:return, fbt::zfs_write:return
+{
+ self->path = 0; self->kb = 0; self->start = 0;
+}
Oops, something went wrong.

0 comments on commit 9d5da6e

Please sign in to comment.