工具: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
脚本helloworld.py的作用,是在运行的进程里打印出helloworld字段
2、使用命令pyrasite-memory-viewer pid查看当前进程的最大对象
退出:q 然后出现下图后y
3、使用命令pyrasite-shell pid进入进程的shell,然后可以使用globals()和locals()查看全局和本地变量
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的全部内容。