运行Python代码时如何跟踪使用的虚拟内存? [英] How to keep track of virtual memory used when running Python code?

查看:358
本文介绍了运行Python代码时如何跟踪使用的虚拟内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python软件包,正在对所使用的虚拟内存进行基准测试.

I have a Python package I am benchmarking for virtual memory used.

目前,这还不是很准确.我提交脚本例如

At the moment, this isn't very precise. I submit the script e.g.

python script1.py

并查看执行所需的时间和资源.

and look at the time and resources used in order to execute.

是否有一些软件包/方法可以找出我的RAM瓶颈在哪里?我在考虑

Is there some package/method to find out where my RAM bottlenecks are? I'm thinking of a tool like

ram_used python script1.py 

可以跟踪使用了多少RAM.

that would keep track of how much RAM is used.

这样的东西存在吗?

推荐答案

是的-名为 memory_profiler .在将@profile装饰器添加到要分析的功能后,即可使用;

Yes, there is - It's called memory_profiler. Once you've gone through and added the @profile decorator to the functions you would like to profile, you can use;

python -m memory_profiler example.py

这篇关于运行Python代码时如何跟踪使用的虚拟内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆