strace on Mac OS X Leopard
One of the most important tools for sysadmins and programmers working in the Linux/BSD environment is called strace. As it took me some time to find out where is “strace for Mac”, I thought it would be worth documenting here…
Making a long story short: in Tiger it was called ktrace, in Leopard it’s called dtrace, but it’s simpler if you just call dtruss.
Here are some examples directly from the dtruss man page:
dtruss df -h # run and examine the "df -h" command dtruss -p 1871 # examine PID 1871 dtruss -n tar # examine all processes called "tar"
For a more “real-life” example, please see this article: Why DTrace Makes Leopard a Must-Have Upgrade — you’ll even learn how to prevent Time Machine from consuming all your CPU.
UPDATE: Just after posting this I discovered that:
1. There’s a really cool GUI for DTrace called Instruments. After playing with it for just a few minutes I was able to detect that it was psyco that was causing Python 2.4 to segfault when running web2ldap. Now back to a little more tinkering to discover why…
2. Leopard/DTrace provides one command that I always wanted: iotop, to show which processes are responsible for the disk I/O (more dtrace commands here). Now to the question: is there a Linux version? The answer is: yes, and it’s written in Python (and requires a kernel >= 2.6.20).
blog








February 26th, 2008 at 21:19
Hey!
I’ve never found the correspondent for the “sample process” thing of activity monitor on terminal..
That’s pretty nice
March 12th, 2008 at 22:24
Is there a relation between this DTrace and Sun OS’s DTrace? If there is I will really envy your OS.
March 12th, 2008 at 22:27
You sun of a gun! It is the same:
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/dtrace.1.html#//apple_ref/doc/man/1/dtrace
You should be happy.
March 28th, 2008 at 18:07
$ sudo iotop
Tracing… Please wait.
dtrace: error on enabled probe ID 9 (ID 21762: profile:::tick-1sec): divide-by-zero in action #2 at DIF offset 28
One heck of a great command.
March 28th, 2008 at 18:32
@Andy: it used to work here, but seems like one of the last software updates broke it… I guarantee you it’s not my fault.
December 1st, 2010 at 05:02
Excellent post. First hit on googling “mac strace” and iotop is something I’ve also been yearning.
Many thanks.
December 2nd, 2010 at 15:20
Thanks for documenting this. This page is the number 1 google hit for “strace mac”.