将cProfile结果与KCacheGrind一起使用 [英] Using cProfile results with KCacheGrind
问题描述
我正在使用cProfile来分析我的Python程序.根据此话题,我的印象是KCacheGrind可以解析并显示cProfile的输出. >
但是,当我要导入文件时,KCacheGrind只会在状态栏中显示未知文件格式"错误,而坐在那里什么也不显示.
在我的分析统计信息与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)
...
打包版本
- KCacheGrind 4.3.1
- Python 2.6.2
可以使用名为 lscallproftree
本文介绍了如何: CherryPy-CacheGrind
结果代码如下:
...
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)
...
如果有人知道不需要外部(即未随Python附带)模块执行此操作的方法,我仍然非常有兴趣了解它.
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
- KCacheGrind 4.3.1
- Python 2.6.2
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.
这篇关于将cProfile结果与KCacheGrind一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!