查看python函数内存使用情况:Memspector

jopen 9年前

查看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.open-open.com/lib/view/home/1443081904857