Tips, Tricks
& Treats

A Quick Look at DTrace

Recently I heard about a technology called DTrace. What's it all about?

DTrace is a low-level instrumentation technology which found its way to the Mac some years ago. Basically, DTrace - short for dynamic tracing - is for the kernel like a thermometer for your steak: Every once in a while, you stick it inside the delicious thing called OS X and it let's you take a peek at what's going on inside. Only that it's always present, and it has various hooks into the system. DTrace can be programmed using the (not so) famous D language. Actually, Apples Developer tool Instruments uses DTrace, too. Outside of Instruments, you can make use of D scripts in Terminal by executing

sudo dtrace <name of script>

Beware the spelling, by the way: DTrace is the technology, Dtrace is the implementation (i.e. the command line tool). For the most complete info about DTrace, see Brendan Gregg's blog and his awesome DTrace book.

Now to the good part: OS X comes ready with a bunch of DTrace scripts, easily discernible by the extension ".d":

bitesize.d
cpu_profiler.d
cpuwalk.d
creatbyproc.d
dispqlen.d
filebyproc.d
hotspot.d
httpdstat.d
iofile.d
iofileb.d
kill.d
loads.d
newproc.d
pathopens.d
pidpersec.d
priclass.d
pridist.d
runocc.d
rwbypid.d
rwbytype.d
seeksize.d
setuids.d
sigdist.d
syscallbypid.d
syscallbyproc.d
syscallbysysc.d
timer_analyser.d
weblatency.d

Furthermore, there are some great tools inside /usr/bin based on DTrace like dtruss and opensnoop. I'll give some more information on these soon. (MacConfig)

Ad