Commit 0a3d0ba6 authored by Luke Macken's avatar Luke Macken

Pull the ObjectInspector out of the memory-viewer and into pyrasite.inspect

parent 74675f8b
# This file is part of pyrasite.
#
# pyrasite is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyrasite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyrasite. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2011 Red Hat, Inc.
import subprocess
class ObjectInspector(object):
"""Inspects objects in a running Python program"""
def __init__(self, pid):
self.pid = pid
def inspect(self, address):
cmd = [
'gdb --quiet -p %s -batch' % self.pid,
'-eval-command="print (PyObject *)%s"' % address,
]
p = subprocess.Popen(' '.join(cmd), shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
for line in out.split('\n'):
if line.startswith('$1 = '):
return line[5:]
......@@ -26,12 +26,13 @@ the value of the object itself.
__version__ = '1.0'
import sys
import subprocess
import urwid
import urwid.raw_display
from meliae import loader
from pyrasite.inspect import ObjectInspector
class PyrasiteMemoryViewer(object):
palette = [
('body', 'black', 'light gray', 'standout'),
......@@ -45,7 +46,7 @@ class PyrasiteMemoryViewer(object):
]
def __init__(self, pid, objects):
self.pid = pid
self.inspector = ObjectInspector(pid)
self.objects = objects
self.summary = objects.summarize()
......@@ -65,21 +66,7 @@ class PyrasiteMemoryViewer(object):
def display_object(self, w, state):
if state:
cmd = [
'gdb --quiet -p %s -batch' % self.pid,
'-eval-command="print (PyObject *)%s"' % w.obj.max_address,
]
p = subprocess.Popen(' '.join(cmd), shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
if err:
print "Errors:", err
value = ''
for line in out.split('\n'):
if line.startswith('$1 = '):
value += line[5:]
value = self.inspector.inspect(w.obj.max_address)
self.object_output.set_text(value)
def get_object_buttons(self, group=[]):
......
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