Profiling Python Apps on Mac?

Robert Kern robert.kern at
Thu Jan 29 07:47:46 CET 2009

On 2009-01-28 13:14, RGK wrote:
> I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 &
> wxPython under OSX 10.4)
> As I make program architecture decisions, it would be nice to be able to
> profile the choices. Should I add that extra thread? Is this big-assed
> xml object I just created horribly bloated or kind of ordinary.
> Is there anything out there I should look into to if I want to see how
> those things are affecting my app? The closest I have is the widget
> iStat, but it's a very static low resolution view of what's really going
> on.

I have a script which provides a few conveniences over the builtin 
cProfile module. One of its modes of operation is to inject a decorator into the 
__builtins__. It will enable the profiler on entry to the method and disable it 
on exit. This lets you localize your profile results to just the part of your 
code that you are interested in. I found this especially useful in GUI apps 
which require user interaction to trigger the part of the code you are actually 
interesting in profiling. You don't want the interesting parts of your profile 
to be obscured by the GUI event loop waiting for your input.

You can get it as part of my line_profiler package (which you may also be 
interested in; cProfile profiles function calls, line_profiler profiles 
individual lines).

You can view the profile results interactively with "python -m pstats", RunSnakeRun, or pyprof2calltree if you manage to install 
kcachegrind on your system:

I don't recommend using hotshot because it is deprecated and slow to postprocess 
the data dumps. Also, I don't recommend using the plain profile module because 
it slows down your program rather more than cProfile. See the Python 
documentation for an overview of these modules:

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-list mailing list