python - 如何使用 python 的 guppy 打印所有行
问题描述
我正在使用 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.>
如何打印所有行?
解决方案
使用用于显示所有行的所有方法。
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)
推荐阅读
- python - 使用 Python 将数据帧保存到 Redshift 时出错
- r - 无法在 Ubuntu 18.04 LTS 上安装 rstanarm
- android - 当有人单击 Firebase 动态链接时,如何在选择器应用程序中显示我的应用程序?
- php - PHP/SQL:如何将列值连接/组合成一行
- sql - 使用视图更新原始表的值
- dart - 来自父小部件的 setState 不会更新子小部件的值
- python-3.x - 请问怎么修边框
- c# - 如何注册自定义 IStateSerializer 的正确方法
- kubernetes - 使用 NEG 时删除 Pod 会导致错误
- javascript - 选中父节点时如何在 Kendo TreeView 中触发子节点的 onCheck 事件