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 ...@@ -4,35 +4,32 @@ Payloads
Viewing the largest objects in your process Viewing the largest objects in your process
------------------------------------------- -------------------------------------------
This payload uses `meliae <https://launchpad.net/meliae>`_ to dump all of Pyrasite provides a tool to view object memory usage statistics, and the
the objects in your process to an `objects.json` file (currently dumped in live value, of largest objects in your process. This requires `urwid
the working directory of your process). <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 $ pyrasite-memory-viewer <PID>
:language: python
:start-after: html
::
$ 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 This tool automatically injects the following payload:
process. This requires `urwid <http://pypi.python.org/pypi/urwid>`_ to be
installed.
.. 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 Call Graph
---------- ----------
......
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
# https://launchpad.net/meliae # https://launchpad.net/meliae
# http://jam-bazaar.blogspot.com/2009/11/memory-debugging-with-meliae.html # http://jam-bazaar.blogspot.com/2009/11/memory-debugging-with-meliae.html
from meliae import scanner import os, meliae
scanner.dump_all_objects('objects.json') meliae.scanner.dump_all_objects('/tmp/pyrasite-%d-objects.json' % os.getpid())
...@@ -30,8 +30,9 @@ import urwid ...@@ -30,8 +30,9 @@ import urwid
import urwid.raw_display import urwid.raw_display
from meliae import loader from meliae import loader
from os.path import join, abspath, dirname
from pyrasite.inspect import ObjectInspector import pyrasite
class PyrasiteMemoryViewer(object): class PyrasiteMemoryViewer(object):
...@@ -47,7 +48,7 @@ class PyrasiteMemoryViewer(object): ...@@ -47,7 +48,7 @@ class PyrasiteMemoryViewer(object):
] ]
def __init__(self, pid, objects): def __init__(self, pid, objects):
self.inspector = ObjectInspector(pid) self.pid = pid
self.objects = objects self.objects = objects
self.summary = objects.summarize() self.summary = objects.summarize()
...@@ -67,7 +68,7 @@ class PyrasiteMemoryViewer(object): ...@@ -67,7 +68,7 @@ class PyrasiteMemoryViewer(object):
def display_object(self, w, state): def display_object(self, w, state):
if 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) self.object_output.set_text(value)
def get_object_buttons(self, group=[]): def get_object_buttons(self, group=[]):
...@@ -134,16 +135,19 @@ class PyrasiteMemoryViewer(object): ...@@ -134,16 +135,19 @@ class PyrasiteMemoryViewer(object):
def main(): def main():
if len(sys.argv) != 3: if len(sys.argv) != 2:
print "[ pyrasite memory viewer ]\n" print("[ pyrasite memory viewer ]\n")
print "Usage: %s <pid> <objects.json>" % sys.argv[0] print("Usage: %s <pid> <objects.json>" % sys.argv[0])
print "\n pid - the running process id" print("\n pid - the running process id")
print " objects.json - the output of the dump-memory payload" print("")
print
sys.exit(1) sys.exit(1)
pid = int(sys.argv[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 = loader.load(filename)
objects.compute_referrers() 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