Add memory stats widget also to manager tree view.

(crobinso: Fix an initialization issue)
This commit is contained in:
Thorsten Behrens 2013-12-18 14:42:42 +01:00 committed by Cole Robinson
parent 0724f1cdaa
commit 77b1143965
5 changed files with 61 additions and 3 deletions

View File

@ -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/">

View File

@ -189,6 +189,15 @@
<signal name="activate" handler="on_menu_view_host_cpu_usage_activate" swapped="no"/>
</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>

View File

@ -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):

View File

@ -1525,6 +1525,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)

View File

@ -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
@ -256,6 +261,9 @@ class vmmManager(vmmGObjectUI):
self.add_gconf_handle(
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))
@ -274,6 +282,7 @@ class vmmManager(vmmGObjectUI):
self.toggle_guest_cpu_usage_visible_widget()
self.toggle_host_cpu_usage_visible_widget()
self.toggle_memory_usage_visible_widget()
self.toggle_disk_io_visible_widget()
self.toggle_network_traffic_visible_widget()
@ -391,12 +400,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 +965,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)
@ -1004,8 +1022,9 @@ class vmmManager(vmmGObjectUI):
col.set_visible(do_show)
self.widget(menu).set_active(do_show)
any_visible = any([col.get_visible() for col in
[self.netcol, self.diskcol, self.guestcpucol, self.hostcpucol]])
any_visible = any([c.get_visible() for c in
[self.netcol, self.diskcol, self.memcol,
self.guestcpucol, self.hostcpucol]])
self.spacer_txt.set_property("visible", not any_visible)
def toggle_network_traffic_visible_widget(self):
@ -1016,6 +1035,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 +1053,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 +1063,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 +1086,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[_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"):