2

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

asked Apr 3, 2013 at 2:44

1 Answer 1

1

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
answered Apr 3, 2013 at 3:42
Sign up to request clarification or add additional context in comments.

2 Comments

Unless i missed something in the profiler it shoes the number of times that function was called and how much usage took place but it does not show it for each time the function was called and what was called before it like a stack trace.
@WojonsTech Unfortunately, that is correct. The problem is that the profile module only stores the edges and nodes of the graph that tools like gprof2dot display. If A calls B and C, both B and C call D, and D calls E, it is usually impossible to know exactly how much of E's time was due to B vs. C. To get that additional information, a different profiler must be used.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.