我使用python的guppy是为了查看python程序中的堆使用情况。我有:
h = hpy
hp = h.heap()
print hp这是生成的输出:
Partition of a set of 339777 objects. Total size = 51680288 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 137974 41 17732032 34 17732032 34 str
1 93077 27 8342072 16 26074104 50 tuple
2 992 0 3428864 7 29502968 57 dict of module
3 23606 7 3021568 6 32524536 63 types.CodeType
4 23577 7 2829240 5 35353776 68 function
5 2815 1 2541648 5 37895424 73 type
6 2815 1 2513128 5 40408552 78 dict of type
7 2112 1 2067840 4 42476392 82 dict (no owner)
8 4495 1 1729792 3 44206184 86 unicode
9 4026 1 671376 1 44877560 87 list
<972 more rows. Type e.g. '_.more' to view.>如何打印所有行?
发布于 2020-11-08 15:01:54
使用用于显示所有行的all方法。
import decimal
from guppy import hpy
d = {
"int": 0,
"float": 0.0,
"dict": dict(),
"set": set(),
"tuple": tuple(),
"list": list(),
"str": "a",
"unicode": u"a",
"decimal": decimal.Decimal(0),
"object": object(),
}
hp = hpy()
heap = hp.heap()
print(heap.all)发布于 2019-10-08 20:34:21
使用python shell
python
然后粘贴您的代码
from guppy import hpy
h = hpy()
h.heap()
然后使用
_.more
来自同一个外壳。您将获得所有行。
发布于 2021-05-12 19:49:55
我使用了取自this model的代码,并且使用the documentation,我可以在自己的头脑中清楚地知道各种实体是什么。
最终的结果是,下面的代码打印出整个堆的报告,与通常一次只能获得10行的报告相同:
h = hpy()
identity_set = h.heap()
stats = identity_set.stat
print()
print("Index Count Size Cumulative Size Object Name")
for row in stats.get_rows():
print("%5d %5d %8d %8d %30s"%(row.index, row.count, row.size, row.cumulsize, row.name))https://stackoverflow.com/questions/55355925
复制相似问题