python 内存占用分析工具

2022-06-17  本文已影响0人  Joncc

依赖

pip install memory_profiler
pip install psutil
pip install matplotlib

使用方法
from memory_profiler import profile

@profile(precision=4, stream=open('test.log', 'w+'))
def test(args: List):
...

运行:
python3 test.py

Filename: /vscode/str/test.py

Line #    Mem usage    Increment  Occurences   Line Contents
============================================================
  13     30.5 MiB     30.5 MiB           1   @profile(precision=4, stream=open('test.log', 'w+'))
  14                                         def test(args):
  15     30.5 MiB      0.0 MiB           1       
  16     30.5 MiB      0.0 MiB           1       return args

Mem usage:表示执行该行后Python解释器的内存使用情况
Increment:表示当前行的内存相对于上一行的差异,即自己本身增长了多少,如果减少了则不显示.

上一篇 下一篇

猜你喜欢

热点阅读