These instructions assume you have already installed Python 2.7
Generates python and qcachegrind profile files
- Run:
sudo pip install profilestats
To profile any python function, decorate it like so:
from profilestats import profile
@profile
def myFunc():
# your code
Pros:
- Identical interface for people used to profiling C/C++ applications in kcachegrind
- Well tested because of its wide usage
Cons:
- Long installation procedure which requires xcode and macports as prerequisites
- Functions will have extremely long names in the display because the full module path is included with the function. Also, functions are not sortable by class or by file because
profilestats
does not include this information properly.
- Download and install Qt 4.x using the installer from: http://qt-project.org/downloads
- Download and extract kcachegrind (which contains qcachegrind) from: http://kcachegrind.sourceforge.net/html/Download.html
- Open a terminal in the extracted directory
- Run:
qmake -spec 'macx-g++'
- Run:
make
- In the
qcachegrind
folder, moveqcachegrind.app
to yourApplications
folder, or a subfolder - Run:
sudo pip install profilehooks
- Run:
sudo port install graphviz
- Symlink
dot
:sudo ln -s /opt/local/bin/dot /usr/bin/dot
- Symlink
twopi
:sudo ln -s /opt/local/bin/dot /usr/bin/twopi
- profilestats will generate 2 files, one being
cachegrind.out.profilestats
which can be opened inside the application
Pros:
- Similar to qcachegrind
- Does not pollute GUI with long file names like qcachegrind
- Can view memory dumps
Cons:
- Not as feature-full as
qcachegrind
- Run:
sudo pip install RunSnakeRun
- Install wxPython from here: http://www.wxpython.org/download.php
- Make sure you get the "cocoa" release, which may still be in the "development release" section. This is required for running wxpython in 64 bit, which is the default mode for python OSX installs.
- Run:
python -c "from runsnakerun import runsnake; runsnake.main()" &
profilestats
will generate 2 files, one beingprofilestats.prof
which can be opened with any python profiling compatible tool, includingRunSnakeRun
Pros:
- Fancy web interface
- Easy install
Cons:
- The time graph takes a while to render for not-so-complex programs
- The time graph causes a memory leak (2.5GB in 20 seconds)
- Run:
sudo pip install snakeviz
Optionally:
- Open:
/Library/Python/2.7/site-packages/snakeviz/upload.py
- Search for
self._timeout = 10
and replace10
with the desired numbered of graph rendering timeout, in seconds
- Run:
snakeviz profilestats.prof
- Type Ctrl+C in the terminal to exit and stop the web server
Pros:
- No known bugs
- Simple graph layout which works
Cons:
- No longer maintained
- Run:
pip install pycallgraph
- Run:
pycallgraph file.py