Using cProfile results with KCacheGrind
It can be done using an external module called lscallproftree
This article explains how: CherryPy - CacheGrind
With my resulting code looking like so:
...
if profile:
import cProfile
import lsprofcalltree
profileFileName = 'Profiles/pythonray_' + time.strftime('%Y%m%d_%H%M%S') + '.profile'
profile = cProfile.Profile()
profile.run('pilImage = camera.render(scene, samplePattern)')
kProfile = lsprofcalltree.KCacheGrind(profile)
kFile = open (profileFileName, 'w+')
kProfile.output(kFile)
kFile.close()
profile.print_stats()
else:
pilImage = camera.render(scene, samplePattern)
...
If anyone knows a way to do this that doesn't require an external (ie. not shipped with Python) module, I'd still be very interested to hear about it.
How do I open python profile data with kCacheGrind?
with --kcachegrind , you can open it with QCachegrind(for Qt or KCachegrind for KDE env).
download it from http://kcachegrind.sourceforge.net/html/Home.html
How to understand the output of callgrind using Kcachegrind
Not necessarily.
main
is not the "real" entry point of your program, there is lot of stuff going on before and after, for example loading/unloading DLLs and the construction/destruction of globals (those which are dynamically initialized).
Those things take time, although normally negligible.
Note that there are flags for callgrind that allow to start the collection of statistics at the start of a function (for example main
) depending on what you are really interested in.
Related Topics
Can Anyone Explain Python's Relative Imports
Python - Download Images from Google Image Search
Can One Get Hierarchical Graphs from Networkx with Python 3
How to Get Tkinter Canvas to Dynamically Resize to Window Width
Django Query That Get Most Recent Objects from Different Categories
Python Super() Raises Typeerror
Unicodeencodeerror: 'Latin-1' Codec Can't Encode Character
How to Extract Text and Text Coordinates from a PDF File
Execute a Function After Flask Returns Response
Python Unittest.Testcase Execution Order
How Come a File Doesn't Get Written Until I Stop the Program
Python - How to Check List Monotonicity
How to Strip the Whitespace from Pandas Dataframe Headers
Matplotlib: How to Prevent X-Axis Labels from Overlapping