OS X D-Trace disk I/O tools iotop and iosnoop leak dynamic variables?

While attempting to track down slowdowns on my home OS X machine, I did some research about the many tools that can be used to trace disk I/O activity.  There is an amazing tool in the OS X kernel called D-Trace that enables disk I/O monitoring scripts like iotop and iosnoop.  Where this all falls apart is that it appears that iotop and iosnooop leak dynamic variables.  D-trace has a limited space for dynamic variables so eventually the output of iotop and iosnoop grinds to a halt.


iotop is a wonderful tool for showing all the processes that are actively reading or writing to disk.  To run, just call “sudo iotop 5”.  See the man page for all the configuration extras.

Example iotop output

The problem with iotop, iosnoop, etc in OS X 10.6.7

Run ‘sudo iotop 5’, or ‘sudo iosnoop -e’ for a few minutes and you’ll notice this warning appear and the useful results from iotop or iosnoop come to a halt.

dtrace: 880 dynamic variable drops
dtrace: 751 dynamic variable drops
dtrace: 891 dynamic variable drops
dtrace: 684 dynamic variable drops
dtrace: 799 dynamic variable drops

A temporary workaround

Add the following lines to iotop, or create a separate iotop.big like me if you are paranoid.  This increases the dynamic variable storage for the iotop script and increases the rate of some kind of garbage collection.  Using this, I can run iotop longer than the two minutes before the change—long enough for my needs.  You can do the same thing with iosnoop or any other D-Trace script on your OS X machine.

— /usr/bin/iotop    2009-05-29 00:16:49.000000000 -0700
+++ /usr/bin/iotop.big    2011-06-28 01:05:07.000000000 -0700
@@ -172,6 +172,9 @@
# — Main Program, DTrace —
/usr/sbin/dtrace -n ‘
+#pragma D option dynvarsize=16m
+#pragma D option cleanrate=5000hz
* Command line arguments

Links to relevant resources

DTraceToolkit in MacOS X
[dtrace-discuss] iotop and dynamic variable drops

D-Trace Options and Tunables

This entry was posted in Techie and tagged , , , , , . Bookmark the permalink.

One Response to OS X D-Trace disk I/O tools iotop and iosnoop leak dynamic variables?

  1. lyneux says:

    Very helpful tip! Many thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s