有没有办法找到 Python Kivy 中一个进程和整个程序使用的总内存。 IE。我可以通过某种方式找出答案:
- 程序使用的总内存?
- 对象处于事件状态并使用了多少内存?
谢谢!
最佳答案
Heapy是 Python 的内存分析器。像这样使用它:
>>> from guppy import hpy
>>> h = hpy()
>>> h.heap()
输出将是这样的:
Partition of a set of 1449133 objects. Total size = 102766644 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 985931 68 46300932 45 46300932 45 str
1 24681 2 22311624 22 68612556 67 dict of pkgcore.ebuild.ebuild_src.package
2 49391 3 21311864 21 89924420 88 dict (no owner)
3 115974 8 3776948 4 93701368 91 tuple
4 152181 11 3043616 3 96744984 94 long
5 36009 2 1584396 2 98329380 96 weakref.KeyedRef
6 11328 1 1540608 1 99869988 97 dict of pkgcore.ebuild.ebuild_src.ThrowAwayNameSpace
7 24702 2 889272 1 100759260 98 types.MethodType
8 11424 1 851840 1 101611100 99 list
9 24681 2 691068 1 102302168 100 pkgcore.ebuild.ebuild_src.package
<54 more rows. Type e.g. '_.more' to view.>
这“基本上是 ram 中可访问内容的快照”。我没有做太多 Kivy 开发,所以我从来没有抽出时间进行分析,但我认为这应该可行。
参见:
关于python - 在 Python Kivy 中查找程序使用的总内存的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22656583/