Using Cprofile Results with Kcachegrind

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



Leave a reply



Submit