Eclipse 中的 Python 分析
这个问题是半基于这个问题的:
How can you profile a python script ?
我认为这对于我的一些程序来说是个好主意。 尽管可以按照上述答案中的说明从批处理文件进行分析,但我认为在 Eclipse 中提供此选项会更好。 同时,将我的整个程序变成一个函数并对其进行分析意味着我必须更改源代码?
如何配置 eclipse 以便能够在现有程序上运行 profile 命令?
欢迎任何提示或建议!
This questions is semi-based of this one here:
How can you profile a python script?
I thought that this would be a great idea to run on some of my programs. Although profiling from a batch file as explained in the aforementioned answer is possible, I think it would be even better to have this option in Eclipse. At the same time, making my entire program a function and profiling it would mean I have to alter the source code?
How can I configure eclipse such that I have the ability to run the profile command on my existing programs?
Any tips or suggestions are welcomed!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您遵循常见的 python 习惯用法来使所有代码(甚至“现有程序”)可作为模块导入,那么您可以完全按照您所描述的方式进行操作,而无需任何额外的麻烦。
这是我正在谈论的特定习惯用法,它使您的程序流程“颠倒”,因为一旦您的所有
__name__ == '__main__'
将被放置在文件的底部>def 已完成:根据我的经验,改造任何现有脚本以遵循此形式非常容易,最多可能几分钟。
由于让您对模块进行编程还有其他好处,因此您会发现大多数
python
脚本实际上都是这样做的。 这样做的一个好处是:您编写的任何python
都可以以模块形式使用,包括foo()
的cProfile
-ing。if you follow the common python idiom to make all your code, even the "existing programs", importable as modules, you could do exactly what you describe, without any additional hassle.
here is the specific idiom I am talking about, which turns your program's flow "upside-down" since the
__name__ == '__main__'
will be placed at the bottom of the file, once all yourdef
s are done:In my experience, it is quite easy to retrofit any existing scripts you have to follow this form, probably a couple minutes at most.
Since there are other benefits to having you program also a module, you'll find most
python
scripts out there actually do it this way. One benefit of doing it this way: anythingpython
you write is potentially useable in module form, includingcProfile
-ing of yourfoo()
.您始终可以创建单独的模块,只对其他模块中的特定内容进行分析。 您可以将此类模块组织在单独的包中。 这样您就不会更改现有的代码。
You can always make separate modules that do just profiling specific stuff in your other modules. You can organize modules like these in a separate package. That way you don't change your existing code.