Commit d3528e96 authored by Luke Macken's avatar Luke Macken

Use a WebKit widget to render our Info tab

parent 1d44ebdc
...@@ -23,13 +23,14 @@ ...@@ -23,13 +23,14 @@
import os import os
import sys import sys
import time import time
import socket
import psutil import psutil
import logging import logging
import keyword import keyword
import tokenize import tokenize
from meliae import loader from meliae import loader
from gi.repository import GLib, GObject, Pango, Gtk from gi.repository import GLib, GObject, Pango, Gtk, WebKit
import pyrasite import pyrasite
from pyrasite.utils import setup_logger, run from pyrasite.utils import setup_logger, run
...@@ -94,10 +95,16 @@ class PyrasiteWindow(Gtk.Window): ...@@ -94,10 +95,16 @@ class PyrasiteWindow(Gtk.Window):
main_vbox.pack_end(self.progress, False, False, 0) main_vbox.pack_end(self.progress, False, False, 0)
hbox.pack_start(main_vbox, True, True, 0) hbox.pack_start(main_vbox, True, True, 0)
(text_widget, info_buffer) = self.create_text(False) self.info_html = ''
notebook.append_page(text_widget, Gtk.Label.new_with_mnemonic('_Info')) self.info_view = WebKit.WebView()
self.info_buffer = info_buffer self.info_view.load_string(self.info_html, "text/html", "utf-8", '#')
self.info_buffer.create_tag('title', font = 'Sans 18')
info_window = Gtk.ScrolledWindow(hadjustment = None,
vadjustment = None)
info_window.set_policy(Gtk.PolicyType.AUTOMATIC,
Gtk.PolicyType.AUTOMATIC)
info_window.add(self.info_view)
notebook.append_page(info_window, Gtk.Label.new_with_mnemonic('_Info'))
(stacks_widget, source_buffer) = self.create_text(True) (stacks_widget, source_buffer) = self.create_text(True)
notebook.append_page(stacks_widget, Gtk.Label.new_with_mnemonic('_Stacks')) notebook.append_page(stacks_widget, Gtk.Label.new_with_mnemonic('_Stacks'))
...@@ -251,64 +258,105 @@ class PyrasiteWindow(Gtk.Window): ...@@ -251,64 +258,105 @@ class PyrasiteWindow(Gtk.Window):
log.debug("obj_row_activated_cb(%s, %s)" % (args, kw)) log.debug("obj_row_activated_cb(%s, %s)" % (args, kw))
def generate_description(self, proc, title): def generate_description(self, proc, title):
d = ''
p = psutil.Process(proc.pid) p = psutil.Process(proc.pid)
cputimes = p.get_cpu_times() cputimes = p.get_cpu_times()
d += '\nCPU usage: %0.2f%% (%s user, %s system)\n' % (
p.get_cpu_percent(interval=1.0),
cputimes.user, cputimes.system)
meminfo = p.get_memory_info() meminfo = p.get_memory_info()
d += 'Memory usage: %0.2f%% (%s RSS, %s VMS)\n\n' % (
p.get_memory_percent(),
meminfo.rss, meminfo.vms)
d += '[ Open Files ]'
for open_file in p.get_open_files():
d += '\n' + str(open_file)
d += '\n\n[ Connections ]'
for conn in p.get_connections():
d += '\n' + str(conn)
d += '\n\n[ Threads ]'
for thread in p.get_threads():
d += '\n' + str(thread)
io = p.get_io_counters() io = p.get_io_counters()
d += '\n\n[ IO ]\nread count: %s\n' % io.read_count
d += 'read bytes: %s\n' % io.read_bytes self.info_html = """
d += 'write count: %s\n' % io.write_count <h2>%(title)s</h2>
d += 'write bytes: %s\n' % io.write_bytes <h3>Resource Usage</h3>
<ul>
d += '\n[ Details ]\n' <li><b>CPU:</b> %(cpu)0.2f%% (%(cpu_user)s user, %(cpu_sys)s system)</li>
d += 'status: %s\n' % p.status <li><b>Memory:</b> %(mem)0.2f%% (%(mem_rss)s RSS, %(mem_vms)s VMS)</li>
d += 'cwd: %s\n' % p.getcwd() <li><b>Read count:</b> %(read_count)s</li>
d += 'cmdline: %s\n' % ' '.join(p.cmdline) <li><b>Read bytes:</b> %(read_bytes)s</li>
d += 'terminal: %s\n' % p.terminal <li><b>Write count:</b> %(write_count)s</li>
d += 'created: %s\n' % time.ctime(p.create_time) <li><b>Write bytes:</b> %(write_bytes)s</li>
d += 'username: %s\n' % p.username </ul>
d += 'uid: %s\n' % p.uids.real """ % dict(
d += 'gid: %s\n' % p.gids.real title = proc.title,
d += 'nice: %s\n\n' % p.nice cpu = p.get_cpu_percent(interval=1.0),
cpu_user = cputimes.user,
# output and style the title cpu_sys = cputimes.system,
(start, end) = self.info_buffer.get_bounds() mem = p.get_memory_percent(),
self.info_buffer.delete(start, end) mem_rss = meminfo.rss,
(start, end) = self.source_buffer.get_bounds() mem_vms = meminfo.vms,
self.source_buffer.delete(start, end) read_count = io.read_count,
read_bytes = io.read_bytes,
start = self.info_buffer.get_iter_at_offset(0) write_count = io.write_count,
end = start.copy() write_bytes = io.write_bytes,
self.info_buffer.insert(end, title) )
start = end.copy()
start.backward_chars(len(title)) open_files = p.get_open_files()
self.info_buffer.apply_tag_by_name('title', start, end) if open_files:
self.info_buffer.insert(end, '\n') self.info_html += """
<h3>Open Files</h3>
# output the description <table border="1">
self.info_buffer.insert(end, d) <thead><tr><th>fd</th><th>Path</th></tr></thead>
%(open_files)s
</table>
""" % dict(
open_files = ''.join(['<tr><td>%s</td><td>%s</td></tr>' %
(f.fd, f.path) for f in open_files]))
conns = p.get_connections()
if conns:
self.info_html += """
<h3>Connections</h3>
<table border="1">
<thead><tr><th>fd</th><th>Family</th><th>Type</th>
<th>Local</th><th>Remote</th><th>Status</th></tr></thead>
"""
families = dict([(getattr(socket, k), k) for k in dir(socket)
if k.startswith('AF_')])
types = dict([(getattr(socket, k), k) for k in dir(socket)
if k.startswith('SOCK_')])
for c in conns:
self.info_html += """
<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
<td>%s</td></tr>
""" % (c.fd, families[c.family], types[c.type],
':'.join(map(str, c.local_address)),
':'.join(map(str, c.remote_address)),
c.status)
self.info_html += """
</table>
"""
threads = p.get_threads()
if threads:
self.info_html += """
<h3>Threads</h3>
<table border="1">
<thead><tr><th>ID</th><th>User Time</th><th>System Time</th>
</tr></thead>
"""
for thread in threads:
self.info_html += """
<tr><td>%s</td><td>%s</td><td>%s</td></tr>
""" % (thread.id, thread.user_time, thread.system_time)
self.info_html += "</table>"
self.info_html += """
<h3>Details</h3>
<ul>
<li><b>status:</b> %s</li>
<li><b>cwd:</b> %s</li>
<li><b>cmdline:</b> %s</li>
<li><b>terminal:</b> %s</li>
<li><b>created:</b> %s</li>
<li><b>username:</b> %s</li>
<li><b>uid:</b> %s</li>
<li><b>gid:</b> %s</li>
<li><b>nice:</b> %s</li>
</ul>
""" % (p.status, p.getcwd(), ' '.join(p.cmdline),
p.terminal, time.ctime(p.create_time),
p.username, p.uids.real, p.gids.real, p.nice)
self.info_view.load_string(self.info_html, "text/html", "utf-8", '#')
def update_progress(self, fraction, text=None): def update_progress(self, fraction, text=None):
if text: if text:
......
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