正在运行的 Python 应用程序示例
我习惯于对基于 C 的应用程序进行采样,每隔几毫秒就会看到当时正在调用什么函数堆栈。
这让我可以看到应用程序的大部分时间都花在哪里,以便我可以对其进行优化。
然而,当使用 python 时,sample 就没那么有用了,因为它采样的是 python 解释器的 C 函数,而不是 python 代码本身。
python 有没有好用的采样工具?
I'm used to sampling C-based apps, which every few milliseconds sees what function stack is being called at that moment.
This allows me to see where most of the time is spent in an app so I can optimize it.
When using python, however, sample isn't so helpful, since it's sampling the C functions of the python interpreter, not the python code itself.
Is there a useful sampling tool for python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Python 包含一组内置的分析工具。 特别是,您可以从命令行在任意 python 脚本上运行 cProfile:
通过直接调用 API 可以获得更详细的用法。 请注意,cProfile 模块是在 Python 2.5 中添加的。 在早期版本中,您可以使用纯Python,但速度较慢的“profile”模块。
Python includes a built-in set of profiling tools. In particular, you can run cProfile on an arbitrary python script from the command-line:
Much more elaborate usage is available by calling the API directly. Note that the cProfile module was added in Python 2.5. In earlier versions, you can use the pure-Python, but slower "profile" module.