I'm using cProfile to profile my Python program. Based upon this talk I was under the impression that KCacheGrind could parse and display the output from cProfile.
However, when I go to import the file, KCacheGrind just displays an 'Unknown File Format' error in the status bar and sits there displaying nothing.
Is there something special I need to do before my profiling stats are compatible with KCacheGrind?
...
if profile:
import cProfile
profileFileName = 'Profiles/pythonray_' + time.strftime('%Y%m%d_%H%M%S') + '.profile'
profile = cProfile.Profile()
profile.run('pilImage = camera.render(scene, samplePattern)')
profile.dump_stats(profileFileName)
profile.print_stats()
else:
pilImage = camera.render(scene, samplePattern)
...
Package Versions
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.