Commit 4f3d5f8c authored by sumpfralle's avatar sumpfralle

added a simple memory analyzer plugin


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1236 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 6bd3a71d
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkListStore" id="MemoryAnalyzerModel">
<columns>
<!-- column-name name -->
<column type="gchararray"/>
<!-- column-name count -->
<column type="gulong"/>
<!-- column-name cumulsize -->
<column type="gulong"/>
<!-- column-name size -->
<column type="gulong"/>
</columns>
</object>
<object class="GtkDialog" id="MemoryAnalyzerWindow">
<property name="border_width">5</property>
<property name="title" translatable="yes">Memory Analyzer</property>
<property name="type_hint">normal</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">etched-in</property>
<child>
<object class="GtkTreeView" id="MemoryAnalyzerTable">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">MemoryAnalyzerModel</property>
<property name="reorderable">True</property>
<property name="search_column">0</property>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
<property name="title">Size (all) [kB]</property>
<property name="clickable">True</property>
<property name="sort_column_id">2</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="title">Count</property>
<property name="clickable">True</property>
<property name="sort_order">descending</property>
<property name="sort_column_id">1</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn4">
<property name="title">Average size [B]</property>
<property name="clickable">True</property>
<property name="sort_column_id">3</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title">Type</property>
<property name="clickable">True</property>
<property name="sort_column_id">0</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="MemoryAnalyzerRefreshButton">
<property name="label">gtk-refresh</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="MemoryAnalyzerCloseButton">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">MemoryAnalyzerRefreshButton</action-widget>
<action-widget response="0">MemoryAnalyzerCloseButton</action-widget>
</action-widgets>
</object>
<object class="GtkToggleAction" id="ToggleMemoryAnalyzerAction">
<property name="label">_Memory Analyzer</property>
<property name="short_label">Memory</property>
<property name="tooltip">Show an analysis of PyCAM's memory consumption</property>
</object>
</interface>
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2012 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM 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.
PyCAM 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 PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import guppy
import pycam.Plugins
class MemoryAnalyzer(pycam.Plugins.PluginBase):
UI_FILE = "memory_analyzer.ui"
DEPENDS = []
CATEGORIES = ["System"]
def setup(self):
if self.gui:
import gtk
self._gtk = gtk
# menu item and shortcut
self.toggle_action = self.gui.get_object("ToggleMemoryAnalyzerAction")
self._gtk_handlers = []
self._gtk_handlers.append((self.toggle_action, "toggled",
self.toggle_window))
self.register_gtk_accelerator("memory_analyzer", self.toggle_action,
None, "ToggleMemoryAnalyzerAction")
self.core.register_ui("view_menu", "ToggleMemoryAnalyzerAction",
self.toggle_action, 80)
# the window
self.window = self.gui.get_object("MemoryAnalyzerWindow")
self.window.set_default_size(500, 400)
hide_window = lambda *args: self.toggle_window(value=False)
self._gtk_handlers.extend([
(self.window, "delete-event", hide_window),
(self.window, "destroy", hide_window),
(self.gui.get_object("MemoryAnalyzerCloseButton"),
"clicked", hide_window),
(self.gui.get_object("MemoryAnalyzerRefreshButton"),
"clicked", self.refresh_memory_analyzer)])
self.model = self.gui.get_object("MemoryAnalyzerModel")
# window state
self._window_position = None
self.register_gtk_handlers(self._gtk_handlers)
return True
def teardown(self):
if self.gui:
self.window.hide()
self.core.unregister_ui("view_menu", self.toggle_action)
self.unregister_gtk_accelerator("memory_analyzer",
self.toggle_action)
self.core.unregister_ui("view_menu", self.toggle_action)
self.unregister_gtk_handlers(self._gtk_handlers)
def toggle_window(self, widget=None, value=None, action=None):
checkbox_state = self.toggle_action.get_active()
if value is None:
new_state = checkbox_state
elif action is None:
new_state = value
else:
new_state = action
if new_state:
if self._window_position:
self.window.move(*self._window_position)
self.refresh_memory_analyzer()
self.window.show()
else:
self._window_position = self.window.get_position()
self.window.hide()
self.toggle_action.set_active(new_state)
# don't destroy the window with a "destroy" event
return True
def refresh_memory_analyzer(self, widget=None):
memory_state = guppy.hpy().heap()
self.model.clear()
for row in memory_state.stat.get_rows():
item = (row.name, row.count, row.size / 1024, row.size / row.count)
self.model.append(item)
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