Nick Bastin

Nick Bastin header image 2

Python, DTrace, OSX, Oh my!

September 6th, 2009 · No Comments

I’ve been poking around using dtrace on OS X (Snow Leopard) recently and have some interest in using it with Python. Apple provides probes in Python (although they have yet to make it upstream, for reasons that I can’t fathom, given that they’ve been available for years) but I’m having some issues with them.

There is the excellent DTraceToolkit from OpenSolaris which has some nice Python scripts (in $install-dir/Python/), but it appears that Apple’s dtrace is limited in some unfortunate ways (no #define support, for one). Also, when using ‘python$target:::’. dtrace sees probes, but fails to actually report on them – perhaps I don’t understand how to invoke dtrace properly?

I have:

python$target:::function-entry
{
@lines[pid, uid, copyinstr(arg0)] = count();
}

dtrace:::END
{
printf("\n %6s %6s %6s %s\n", "PID", "UID", "FUNCS", "FILE");
printa(" %6d %6d %@6d %s\n", @lines);
}

But all I get is:

sudo dtrace -s test.d -c "/usr/bin/python test.py"

dtrace: script 'test.d' matched 1 probe
dtrace: pid 20908 has exited
CPU ID FUNCTION:NAME
7 2 :END
PID UID FUNCS FILE

Which is troubling…. Even if I use python*:::function-entry, I still can’t seem to use -c:

sudo dtrace -s test.d -c "/usr/bin/python test.py"

dtrace: script 'test.d' matched 3 probes
dtrace: pid 20900 has exited
CPU ID FUNCTION:NAME
2 2 :END
PID UID FUNCS FILE

Scripts which use python*::: and don’t attempt to attach to a given process (via -c) seem to work fine, but that’s less than optimal.

Tags: Python · Software · Software Development

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.