使用memory_profiler工具對python工程做內存分析

memory_profiler使用
memory_profiler主要用來監控python工程佔用內存大小

安裝

pip install -U memory_profiler

用法

from memory_profiler import profile

在需要分析的函數上面添加註釋

@profile(precision=4,stream=open('memory_profiler.log','w+'))

查看memory_profiler.log,裏面記錄了每一行代碼的內存使用情況

發佈了93 篇原創文章 · 獲贊 225 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章