推荐哪种Python内存分析器?我想知道Python应用程序的内存使用情况,特别是想知道哪些代码块/部分或对象占用了大部分内存。谷歌搜索显示商业搜索是Python内存校验器(仅限窗户)。而开源的是化油器和海皮.我没有试过任何人,所以我想知道哪一个是最好的考虑:给出了大部分细节。我必须对我的代码做最少的或不做的更改。
3 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
from guppy import hpy h = hpy()print h.heap()
Partition of a set of 132527 objects. Total size = 8301532 bytes.Index Count % Size % Cumulative % Kind (class / dict of class)0 35144 27 2140412 26 2140412 26 str1 38397 29 1309020 16 3449432 42 tuple2 530 0 739856 9 4189288 50 dict (no owner)
紫衣仙女
TA贡献1839条经验 获得超15个赞
@profile-m memory_profiler
Line # Mem usage Increment Line Contents============================================== 3 @profile 4 5.97 MB 0.00 MB def my_func(): 5 13.61 MB 7.64 MB a = [1] * (10 ** 6) 6 166.20 MB 152.59 MB b = [2] * (2 * 10 ** 7) 7 13.61 MB -152.59 MB del b 8 13.61 MB 0.00 MB return a
开心每一天1111
TA贡献1836条经验 获得超13个赞
# memdebug.pyimport cherrypyimport dowserdef start(port):
cherrypy.tree.mount(dowser.Root())
cherrypy.config.update({
'environment': 'embedded',
'server.socket_port': port })
cherrypy.server.quickstart()
cherrypy.engine.start(blocking=False)更新
CherryPy 2.X, CherryPy 3.Xserver.quickstartengine.startblockingCherryPy 3.X
# memdebug.pyimport cherrypyimport dowserdef start(port):
cherrypy.tree.mount(dowser.Root())
cherrypy.config.update({
'environment': 'embedded',
'server.socket_port': port })
cherrypy.engine.start()添加回答
举报
0/150
提交
取消
