查看python函數內存使用情況:Memspector

jopen 9年前發布 | 16K 次閱讀 Python開發 Memspector

查看python函數內存使用情況

特性

  • Thread handling
  • External tool, doesn't require code modification

Checkmemspector --helpfor command line options

安裝

via pip:pip install memspector

示例

example.py:

l = []


def a():
    l.extend(range(100000))


def b():
    global l
    l = []


a()
a()
b()
a()
b()
a()

Runmemspector example.pyto get the following output:

example.py:b()                                               thread: main_thread
total memory       diff
    2,940,336     -1,799,976
    2,040,440       -900,048

example.py:a()                                               thread: main_thread
total memory       diff
    1,139,848        900,400
    2,040,280        900,000
    1,140,408        900,048
    1,140,408        900,048

example.py                                                   thread: main_thread
total memory       diff
    1,133,832        906,232

項目主頁:http://www.baiduhome.net/lib/view/home/1443081904857

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!