Commit fb2667f2 authored by Luke Macken's avatar Luke Macken

Make the pyrasite-memory-viewer much easier to use

parent ea09b1a3
......@@ -4,35 +4,32 @@ Payloads
Viewing the largest objects in your process
-------------------------------------------
This payload uses `meliae <https://launchpad.net/meliae>`_ to dump all of
the objects in your process to an `objects.json` file (currently dumped in
the working directory of your process).
Pyrasite provides a tool to view object memory usage statistics, and the
live value, of largest objects in your process. This requires `urwid
<http://pypi.python.org/pypi/urwid>`_ and `meliae
<https://launchpad.net/meliae>`_ to be installed.
We recommend using python-meliae from your OS distribution, if available.
If it is not, you will need to first install Cython, and then meliae
seperately. If pip/easy_install does not work, you may need to use the
tarball from the upstream website.
::
.. literalinclude:: ../pyrasite/payloads/dump_memory.py
:language: python
:start-after: html
$ pyrasite-memory-viewer <PID>
::
$ pyrasite <PID> pyrasite/payloads/dump_memory.py
.. image:: http://lewk.org/img/pyrasite-memory-viewer.png
.. note:: We recommend using python-meliae from your OS distribution, if available. If it is not, you will need to first install Cython, and then meliae seperately. If pip/easy_install does not work, you may need to use the tarball from the upstream website.
Pyrasite also provides a tool to view the values of largest objects in your
process. This requires `urwid <http://pypi.python.org/pypi/urwid>`_ to be
installed.
This tool automatically injects the following payload:
.. literalinclude:: ../pyrasite/payloads/dump_memory.py
:language: python
:start-after: html
::
You can easily dump the object memory usage JSON data by hand, if you wish:
$ pyrasite-memory-viewer <PID> objects.json
::
$ pyrasite <PID> pyrasite/payloads/dump_memory.py
.. image:: http://lewk.org/img/pyrasite-memory-viewer.png
Call Graph
----------
......
......@@ -5,5 +5,5 @@
# https://launchpad.net/meliae
# http://jam-bazaar.blogspot.com/2009/11/memory-debugging-with-meliae.html
from meliae import scanner
scanner.dump_all_objects('objects.json')
import os, meliae
meliae.scanner.dump_all_objects('/tmp/pyrasite-%d-objects.json' % os.getpid())
......@@ -30,8 +30,9 @@ import urwid
import urwid.raw_display
from meliae import loader
from os.path import join, abspath, dirname
from pyrasite.inspect import ObjectInspector
import pyrasite
class PyrasiteMemoryViewer(object):
......@@ -47,7 +48,7 @@ class PyrasiteMemoryViewer(object):
]
def __init__(self, pid, objects):
self.inspector = ObjectInspector(pid)
self.pid = pid
self.objects = objects
self.summary = objects.summarize()
......@@ -67,7 +68,7 @@ class PyrasiteMemoryViewer(object):
def display_object(self, w, state):
if state:
value = self.inspector.inspect(w.obj.max_address)
value = pyrasite.inspect(self.pid, w.obj.max_address)
self.object_output.set_text(value)
def get_object_buttons(self, group=[]):
......@@ -134,16 +135,19 @@ class PyrasiteMemoryViewer(object):
def main():
if len(sys.argv) != 3:
print "[ pyrasite memory viewer ]\n"
print "Usage: %s <pid> <objects.json>" % sys.argv[0]
print "\n pid - the running process id"
print " objects.json - the output of the dump-memory payload"
print
if len(sys.argv) != 2:
print("[ pyrasite memory viewer ]\n")
print("Usage: %s <pid> <objects.json>" % sys.argv[0])
print("\n pid - the running process id")
print("")
sys.exit(1)
pid = int(sys.argv[1])
filename = sys.argv[2]
payload = abspath(join(dirname(__file__), '..',
'payloads', 'dump_memory.py'))
pyrasite.inject(pid, payload)
filename = '/tmp/pyrasite-%d-objects.json' % pid
objects = loader.load(filename)
objects.compute_referrers()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment