Reputation: 1277
I am looking for away to profile and trace python code at the same time. I have seen the python trace and traceback classes and also seen the python Cprofiler and profiler classes.
The trace libraries do not include information on how long the function took to ran nor how much memory, the Cprofiler libraries does not show how long it took to run for each time that function was called nor does it show the flow path of the application like how trace does. What I am looking for is something similar to xdebug for php.
python <= 2.6
Thanks in advance
Upvotes: 2
Views: 2971
Reputation:
Have you looked into profile
, docs here
Also take a look here:
Visualizing Profiling Results
RunSnakeRun is a GUI tool by Mike Fletcher which visualizes profile dumps from cProfile using square maps. Function/method calls may be sorted according to various criteria, and source code may be displayed alongside the visualization and call statistics.
An example usage:
runsnake some_profile_dump.prof
Gprof2Dot is a python based tool that can transform profiling results output into a graph that can be converted into a PNG image or SVG.
A typical profiling session with python 2.5 looks like this (on older platforms you will need to use actual script instead of the -m option):
python -m cProfile -o stat.prof MYSCRIPY.PY [ARGS...]
python -m pbp.scripts.gprof2dot -f pstats -o stat.dot stat.prof
dot -ostat.png -Tpng stat.dot
PyCallGraph pycallgraph is a Python module that creates call graphs for Python programs. It generates a PNG file showing an modules's function calls and their link to other function calls, the amount of times a function was called and the time spent in that function.
Typical usage:
pycallgraph scriptname.py
PyProf2CallTree is a script to help visualize profiling data collected with the cProfile python module with the kcachegrind graphical calltree analyser.
Typical usage:
python -m cProfile -o stat.prof MYSCRIPY.PY [ARGS...]
python pyprof2calltree.py -i stat.prof -k
Upvotes: 1