DTrace is an incredible tool. It basically lets you do profiling of a live application with no performance penatly. I'm writing a Python that needed some profiling, and I found the "normal" techniques like the profile/cProfile module very lacking. Luckily, Mac OSX comes with DTrace and it even works with Python. The only snag is that it's hard to find how to use the darn thing. I finally figured it out, so I figured it pass on the knowledge.
So, here's how you use dtrace on your python application in Mac OSX:
- Get DTraceToolkit.
- Edit Python/py_cputime.d by replacing "function-entry" with "entry" and "function-return" with "exit".
- Call "sudo dtrace -s Python/py_cputime.d"
- Let it sit there a while and hit ctrl-c.
- Enjoy the results
I can only assume you have to edit the file because of some difference between Solaris and OSX. You can try files other than py_cputime.d, but you might have to edit them too. Not all of them work, but most do.
The last thing to know is that you have to use the python that comes with OSX. A custom-built python doesn't seem to work.
Hope that helps!