如何确定函数的 CPU 和内存成本?
有人可以建议什么是最佳实践或合适的库来确定:
- Python 函数执行期间使用的CPU 周期数量?
- 同一 Python 函数使用的内存量?
我看过孔雀鱼和meliae,但仍然无法精细到功能级别?我错过了什么吗?
更新 提出这个问题是为了解决一个具体的情况,即场景是我们有一组分布式任务运行在云实例上,现在我们需要重新组织任务在集群内正确的实例类型上的放置,例如例如,高内存消耗的功能任务将被放置在更大的内存实例上,等等。当我指的是任务(celery-tasks)时,这些只是简单的函数,我们现在需要分析它们的执行使用情况。
谢谢。
Can someone suggest what would be the best practice or a suitable library to determine:
- Number of CPU cycles used during execution of a Python function?
- Amount of Memory used by the same Python function?
I had looked at guppy and meliae, but still can't get granular to the function level? Am I missing something?
UPDATE
The need for asking this question is to solve a specific situation which is, the scenario is that we have a set of distributed tasks running on cloud instances, and now we need to reorganize the placement of tasks on right instance types withing the cluster, for example high memory consuming functional tasks would be placed on larger memory instances and so on. When I mean tasks (celery-tasks), these are nothing but plain functions for which we need to now profile their execution usage.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想研究一下适用于 Python 的
CPU 分析器
:http://docs.python.org/library/profile.html
cProfile.run(command[, filename])
的示例输出此外,
内存
也需要分析器:开源分析器:PySizer 和 厚重
You may want to look into a
CPU profiler
for Python:http://docs.python.org/library/profile.html
Example output of
cProfile.run(command[, filename])
Also,
memory
needs a profiler too:open source profilers: PySizer and Heapy