[virt-tools-list] [PATCH] Add memory stats widget also to domain summary view.
Thorsten Behrens
tbehrens at suse.com
Tue Nov 19 22:47:38 UTC 2013
---
data/org.virt-manager.virt-manager.gschema.xml | 6 +++++
ui/manager.ui | 9 +++++++
virtManager/config.py | 6 +++++
virtManager/domain.py | 3 +++
virtManager/manager.py | 34 +++++++++++++++++++++++++-
5 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/data/org.virt-manager.virt-manager.gschema.xml b/data/org.virt-manager.virt-manager.gschema.xml
index c56db56..8111ac9 100644
--- a/data/org.virt-manager.virt-manager.gschema.xml
+++ b/data/org.virt-manager.virt-manager.gschema.xml
@@ -94,6 +94,12 @@
<description>Show the host cpu usage field in the domain list summary view</description>
</key>
+ <key name="memory-usage" type="b">
+ <default>false</default>
+ <summary>Show memory usage in summary</summary>
+ <description>Show memory usage field in the domain list summary view</description>
+ </key>
+
</schema>
<schema id="org.virt-manager.virt-manager.stats" path="/org/virt-manager/virt-manager/stats/">
diff --git a/ui/manager.ui b/ui/manager.ui
index baa2cf9..6fcc199 100644
--- a/ui/manager.ui
+++ b/ui/manager.ui
@@ -190,6 +190,15 @@
</object>
</child>
<child>
+ <object class="GtkCheckMenuItem" id="menu_view_stats_memory">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">_Memory Usage</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_menu_view_memory_usage_activate" swapped="no"/>
+ </object>
+ </child>
+ <child>
<object class="GtkCheckMenuItem" id="menu_view_stats_disk">
<property name="visible">True</property>
<property name="can_focus">False</property>
diff --git a/virtManager/config.py b/virtManager/config.py
index e98597c..059ff77 100644
--- a/virtManager/config.py
+++ b/virtManager/config.py
@@ -241,6 +241,8 @@ class vmmConfig(object):
return self.conf.get("/vmlist-fields/cpu-usage")
def is_vmlist_host_cpu_usage_visible(self):
return self.conf.get("/vmlist-fields/host-cpu-usage")
+ def is_vmlist_memory_usage_visible(self):
+ return self.conf.get("/vmlist-fields/memory-usage")
def is_vmlist_disk_io_visible(self):
return self.conf.get("/vmlist-fields/disk-usage")
def is_vmlist_network_traffic_visible(self):
@@ -250,6 +252,8 @@ class vmmConfig(object):
self.conf.set("/vmlist-fields/cpu-usage", state)
def set_vmlist_host_cpu_usage_visible(self, state):
self.conf.set("/vmlist-fields/host-cpu-usage", state)
+ def set_vmlist_memory_usage_visible(self, state):
+ self.conf.set("/vmlist-fields/memory-usage", state)
def set_vmlist_disk_io_visible(self, state):
self.conf.set("/vmlist-fields/disk-usage", state)
def set_vmlist_network_traffic_visible(self, state):
@@ -259,6 +263,8 @@ class vmmConfig(object):
return self.conf.notify_add("/vmlist-fields/cpu-usage", cb)
def on_vmlist_host_cpu_usage_visible_changed(self, cb):
return self.conf.notify_add("/vmlist-fields/host-cpu-usage", cb)
+ def on_vmlist_memory_usage_visible_changed(self, cb):
+ return self.conf.notify_add("/vmlist-fields/memory-usage", cb)
def on_vmlist_disk_io_visible_changed(self, cb):
return self.conf.notify_add("/vmlist-fields/disk-usage", cb)
def on_vmlist_network_traffic_visible_changed(self, cb):
diff --git a/virtManager/domain.py b/virtManager/domain.py
index b8324d5..81da335 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -1521,6 +1521,9 @@ class vmmDomain(vmmLibvirtObject):
if len(cpudata) > limit:
cpudata = cpudata[0:limit]
return cpudata
+ def memory_usage_vector_limit(self, limit):
+ return self.in_out_vector_limit(self.stats_memory_vector(),
+ limit)
def network_traffic_vector_limit(self, limit, ceil=None):
return self.in_out_vector_limit(self.network_traffic_vector(ceil),
limit)
diff --git a/virtManager/manager.py b/virtManager/manager.py
index 114904b..ff94d3a 100644
--- a/virtManager/manager.py
+++ b/virtManager/manager.py
@@ -56,8 +56,9 @@ ROW_INSPECTION_OS_ICON) = range(11)
(COL_NAME,
COL_GUEST_CPU,
COL_HOST_CPU,
+COL_MEM,
COL_DISK,
-COL_NETWORK) = range(5)
+COL_NETWORK) = range(6)
def _style_get_prop(widget, propname):
@@ -133,6 +134,8 @@ class vmmManager(vmmGObjectUI):
self.toggle_stats_visible_guest_cpu,
"on_menu_view_host_cpu_usage_activate":
self.toggle_stats_visible_host_cpu,
+ "on_menu_view_memory_usage_activate":
+ self.toggle_stats_visible_memory_usage,
"on_menu_view_disk_io_activate" :
self.toggle_stats_visible_disk,
"on_menu_view_network_traffic_activate":
@@ -165,6 +168,7 @@ class vmmManager(vmmGObjectUI):
# list.get_column, so avoid it
self.diskcol = None
self.netcol = None
+ self.memcol = None
self.guestcpucol = None
self.hostcpucol = None
self.spacer_txt = None
@@ -229,6 +233,7 @@ class vmmManager(vmmGObjectUI):
self.diskcol = None
self.guestcpucol = None
+ self.memcol = None
self.hostcpucol = None
self.netcol = None
@@ -257,6 +262,9 @@ class vmmManager(vmmGObjectUI):
self.config.on_vmlist_host_cpu_usage_visible_changed(
self.toggle_host_cpu_usage_visible_widget))
self.add_gconf_handle(
+ self.config.on_vmlist_memory_usage_visible_changed(
+ self.toggle_memory_usage_visible_widget))
+ self.add_gconf_handle(
self.config.on_vmlist_disk_io_visible_changed(
self.toggle_disk_io_visible_widget))
self.add_gconf_handle(
@@ -391,12 +399,14 @@ class vmmManager(vmmGObjectUI):
self.guestcpucol = make_stats_column(_("CPU usage"), COL_GUEST_CPU)
self.hostcpucol = make_stats_column(_("Host CPU usage"), COL_HOST_CPU)
+ self.memcol = make_stats_column(_("Memory usage"), COL_MEM)
self.diskcol = make_stats_column(_("Disk I/O"), COL_DISK)
self.netcol = make_stats_column(_("Network I/O"), COL_NETWORK)
model.set_sort_func(COL_NAME, self.vmlist_name_sorter)
model.set_sort_func(COL_GUEST_CPU, self.vmlist_guest_cpu_usage_sorter)
model.set_sort_func(COL_HOST_CPU, self.vmlist_host_cpu_usage_sorter)
+ model.set_sort_func(COL_MEM, self.vmlist_memory_usage_sorter)
model.set_sort_func(COL_DISK, self.vmlist_disk_io_sorter)
model.set_sort_func(COL_NETWORK, self.vmlist_network_usage_sorter)
model.set_sort_column_id(COL_NAME, Gtk.SortType.ASCENDING)
@@ -954,6 +964,13 @@ class vmmManager(vmmGObjectUI):
return cmp(obj1.host_cpu_time_percentage(),
obj2.host_cpu_time_percentage())
+ def vmlist_memory_usage_sorter(self, model, iter1, iter2, ignore):
+ obj1 = model.get_value(iter1, ROW_HANDLE)
+ obj2 = model.get_value(iter2, ROW_HANDLE)
+
+ return cmp(obj1.stats_memory(),
+ obj2.stats_memory())
+
def vmlist_disk_io_sorter(self, model, iter1, iter2, ignore):
obj1 = model.get_value(iter1, ROW_HANDLE)
obj2 = model.get_value(iter2, ROW_HANDLE)
@@ -1016,6 +1033,10 @@ class vmmManager(vmmGObjectUI):
self._toggle_graph_helper(
self.config.is_vmlist_disk_io_visible(), self.diskcol,
self.disk_io_img, "menu_view_stats_disk")
+ def toggle_memory_usage_visible_widget(self):
+ self._toggle_graph_helper(
+ self.config.is_vmlist_memory_usage_visible(), self.memcol,
+ self.memory_usage_img, "menu_view_stats_memory")
def toggle_guest_cpu_usage_visible_widget(self):
self._toggle_graph_helper(
self.config.is_vmlist_guest_cpu_usage_visible(), self.guestcpucol,
@@ -1030,6 +1051,7 @@ class vmmManager(vmmGObjectUI):
set_stats = {
COL_GUEST_CPU: self.config.set_vmlist_guest_cpu_usage_visible,
COL_HOST_CPU: self.config.set_vmlist_host_cpu_usage_visible,
+ COL_MEM: self.config.set_vmlist_memory_usage_visible,
COL_DISK: self.config.set_vmlist_disk_io_visible,
COL_NETWORK: self.config.set_vmlist_network_traffic_visible,
}
@@ -1039,6 +1061,8 @@ class vmmManager(vmmGObjectUI):
self.toggle_stats_visible(src, COL_GUEST_CPU)
def toggle_stats_visible_host_cpu(self, src):
self.toggle_stats_visible(src, COL_HOST_CPU)
+ def toggle_stats_visible_memory_usage(self, src):
+ self.toggle_stats_visible(src, COL_MEM)
def toggle_stats_visible_disk(self, src):
self.toggle_stats_visible(src, COL_DISK)
def toggle_stats_visible_network(self, src):
@@ -1060,6 +1084,14 @@ class vmmManager(vmmGObjectUI):
data = obj.host_cpu_time_vector_limit(GRAPH_LEN)
cell.set_property('data_array', data)
+ def memory_usage_img(self, column_ignore, cell, model, _iter, data):
+ obj = model.get_value(_iter, ROW_HANDLE)
+ if obj is None or not hasattr(obj, "conn"):
+ return
+
+ data = obj.memory_usage_vector_limit(GRAPH_LEN)
+ cell.set_property('data_array', data)
+
def disk_io_img(self, column_ignore, cell, model, _iter, data):
obj = model[_iter][ROW_HANDLE]
if obj is None or not hasattr(obj, "conn"):
--
1.8.4
More information about the virt-tools-list
mailing list