python内存泄露诊断过程记录pyrasite

工具:pyrasite;包含三个命令行 pyrasite / pyrasite-shell / pyrasite-memory-viewer

安装:gdb meliae urwid

说明:Pyrasite is a library and a set of tools for injecting code into running Python programs.

1、使用:pyrasite -l 显示可以使用的脚本,脚本路径在:/usr/local/lib/python2.7/site-packages/pyrasite/payloads

python内存泄露诊断过程记录pyrasite_第1张图片

 脚本helloworld.py的作用,是在运行的进程里打印出helloworld字段

python内存泄露诊断过程记录pyrasite_第2张图片

 

2、使用命令pyrasite-memory-viewer pid查看当前进程的最大对象

python内存泄露诊断过程记录pyrasite_第3张图片

python内存泄露诊断过程记录pyrasite_第4张图片

退出:q 然后出现下图后y

python内存泄露诊断过程记录pyrasite_第5张图片

3、使用命令pyrasite-shell pid进入进程的shell,然后可以使用globals()和locals()查看全局和本地变量

 python内存泄露诊断过程记录pyrasite_第6张图片

pyrasite-shell - Give it a pid, get a shell

You can easily drop into a shell and execute commands in a running process using the pyrasite-shell.

$ pyrasite-shell
Usage: pyrasite-shell 
$ pyrasite-shell $(pgrep -f "ipython")
Pyrasite Shell 2.0beta9
Connected to 'ipython'
Python 2.7.2 (default, Oct 27 2011, 01:40:22)
[GCC 4.6.1 20111003 (Red Hat 4.6.1-10)] on linux2
>>> print(x)
foo

>>> globals()['x'] = 'bar'

 

工具:lptrace,跟踪进程

安装:pip install lptrace

 

参考:

1、http://pyrasite.com/

2、https://github.com/khamidou/lptrace

3、http://pyrasite.readthedocs.io/en/latest/#

4、https://www.mankier.com/1/pyrasite#Contents-pyrasite-memory-viewer_-_View_the_largest_objects_in_your_process

5、http://www.jianshu.com/p/2d06a1a01cc3

你可能感兴趣的:(python内存泄露诊断过程记录pyrasite)