用于python memory profile 的几个工具,记录
meliae
- install:
pip install meliae
( cython needed ) - usage:
import meliae
from meliae import scanner
from meliae import loader
#dump python virtual-env memory log
scanner.dump_all_objects('/tmp/dump_env_py.txt')
#summarize the log data
dump_file = '/tmp/dump_api.txt'
om = loader.load(dump_file)
om.compute_parents()
om.collapse_instance_dicts()
print om.summarize()
#print om.compute_referrers()
p = om.get_all('DDOSTopSummary')
print p
print p[0]
print p[0].c
print p[0].p
- output :
checked 69954 / 69955 collapsed 0
Total 69955 objects, 220 types, Total size = 11.0MiB (11506131 bytes)
Index Count % Size % Cum Max Kind
0 30497 43 3019938 26 26 20623 str
1 1912 2 2084800 18 44 98584 dict
2 370 0 1106592 9 53 12624 module
3 1025 1 926600 8 62 904 type
4 7079 10 906112 7 69 128 code
5 7239 10 868680 7 77 120 function
6 5812 8 614976 5 82 38224 list
7 4032 5 307264 2 85 8056 tuple
8 55 0 178664 1 87 3416 Literal
9 285 0 145992 1 88 8424 set
10 1283 1 112904 0 89 88 weakref
11 1270 1 101600 0 90 80 wrapper_descriptor
12 1030 1 74160 0 90 72 builtin_function_or_method
13 2794 3 67056 0 91 24 int
14 20 0 59104 0 91 3416 Regex
15 39 0 57192 0 92 3416 And
16 741 1 53352 0 92 72 method_descriptor
17 610 0 52440 0 93 3644 unicode
18 723 1 52056 0 93 72 getset_descriptor
19 117 0 40248 0 94 344 WeakSet
- reference:
Author blog