diff --git a/data/org.virt-manager.virt-manager.gschema.xml b/data/org.virt-manager.virt-manager.gschema.xml index 8111ac93..270a7b0a 100644 --- a/data/org.virt-manager.virt-manager.gschema.xml +++ b/data/org.virt-manager.virt-manager.gschema.xml @@ -121,6 +121,11 @@ Poll net i/o stats Whether or not the app will poll VM network i/o statistics + + true + Poll memory stats + Whether or not the app will poll VM memory statistics + diff --git a/ui/preferences.ui b/ui/preferences.ui index 49281ebf..7421fbba 100644 --- a/ui/preferences.ui +++ b/ui/preferences.ui @@ -1,5 +1,5 @@ - + @@ -108,6 +108,9 @@ True False + start + start + False 0 none @@ -119,7 +122,7 @@ True False - 3 + 4 3 3 3 @@ -231,6 +234,36 @@ + + + True + False + 0 + Poll _Memory stats + True + prefs-stats-enable-memory + + + 3 + 4 + + + + + True + True + False + 0 + True + + + + 1 + 3 + 3 + 4 + + @@ -259,7 +292,7 @@ True False - Stats + Polling 1 diff --git a/virtManager/config.py b/virtManager/config.py index c72429de..2be564b1 100644 --- a/virtManager/config.py +++ b/virtManager/config.py @@ -345,16 +345,22 @@ class vmmConfig(object): return self.conf.get("/stats/enable-disk-poll") def get_stats_enable_net_poll(self): return self.conf.get("/stats/enable-net-poll") + def get_stats_enable_memory_poll(self): + return self.conf.get("/stats/enable-memory-poll") def set_stats_enable_disk_poll(self, val): self.conf.set("/stats/enable-disk-poll", val) def set_stats_enable_net_poll(self, val): self.conf.set("/stats/enable-net-poll", val) + def set_stats_enable_memory_poll(self, val): + self.conf.set("/stats/enable-memory-poll", val) def on_stats_enable_disk_poll_changed(self, cb, row=None): return self.conf.notify_add("/stats/enable-disk-poll", cb, row) def on_stats_enable_net_poll_changed(self, cb, row=None): return self.conf.notify_add("/stats/enable-net-poll", cb, row) + def on_stats_enable_memory_poll_changed(self, cb, row=None): + return self.conf.notify_add("/stats/enable-memory-poll", cb, row) # VM Console preferences def on_console_accels_changed(self, cb): diff --git a/virtManager/domain.py b/virtManager/domain.py index efdb215e..1058bf3d 100644 --- a/virtManager/domain.py +++ b/virtManager/domain.py @@ -248,6 +248,8 @@ class vmmDomain(vmmLibvirtObject): self._mem_stats_supported = True + self._enable_mem_stats = False + self._enable_net_poll = False self._stats_net_supported = True self._stats_net_skip = [] @@ -286,6 +288,7 @@ class vmmDomain(vmmLibvirtObject): self.toggle_sample_network_traffic() self.toggle_sample_disk_io() + self.toggle_sample_mem_stats() self.force_update_status() @@ -296,6 +299,9 @@ class vmmDomain(vmmLibvirtObject): self.add_gconf_handle( self.config.on_stats_enable_disk_poll_changed( self.toggle_sample_disk_io)) + self.add_gconf_handle( + self.config.on_stats_enable_memory_poll_changed( + self.toggle_sample_mem_stats)) self.connect("status-changed", self._update_start_vcpus) self.connect("pre-startup", self._prestartup_nodedev_check) @@ -1360,33 +1366,9 @@ class vmmDomain(vmmLibvirtObject): # Don't schedule any conn update, migrate dialog handles it for us - ################### - # Stats helpers ### - ################### - - def _sample_mem_stats(self): - curmem = 0 - totalmem = 1 - - if self._mem_stats_supported and self.is_active(): - try: - stats = self._backend.memoryStats() - # did we get both required stat items back? - if set(['actual', 'rss']).issubset( - set(stats.keys())): - curmem = stats['rss'] - totalmem = stats['actual'] - except libvirt.libvirtError, err: - if util.is_error_nosupport(err): - logging.debug("Mem stats not supported: %s", err) - self._mem_stats_supported = False - else: - logging.error("Error reading mem stats: %s", err) - - pcentCurrMem = curmem * 100.0 / totalmem - pcentCurrMem = max(0.0, min(pcentCurrMem, 100.0)) - - return pcentCurrMem, curmem + ################# + # Stats helpers # + ################# def _sample_cpu_stats(self, info, now): prevCpuTime = 0 @@ -1487,6 +1469,9 @@ class vmmDomain(vmmLibvirtObject): self.record[0]["diskRdKB"] = rdBytes / 1024 self.record[0]["diskWrKB"] = wrBytes / 1024 + def toggle_sample_mem_stats(self, ignore=None): + self._enable_mem_stats = self.config.get_stats_enable_memory_poll() + ################### # Stats accessors # @@ -1757,6 +1742,34 @@ class vmmDomain(vmmLibvirtObject): return rd, wr + def _sample_mem_stats(self): + if (not self._mem_stats_supported or + not self._enable_mem_stats or + not self.is_active()): + return 0, 0 + + curmem = 0 + totalmem = 1 + try: + stats = self._backend.memoryStats() + # did we get both required stat items back? + if set(['actual', 'rss']).issubset( + set(stats.keys())): + curmem = stats['rss'] + totalmem = stats['actual'] + except libvirt.libvirtError, err: + if util.is_error_nosupport(err): + logging.debug("Mem stats not supported: %s", err) + self._mem_stats_supported = False + else: + logging.error("Error reading mem stats: %s", err) + + pcentCurrMem = curmem * 100.0 / totalmem + pcentCurrMem = max(0.0, min(pcentCurrMem, 100.0)) + + return pcentCurrMem, curmem + + def tick(self, stats_update=True): self._invalidate_xml() info = self._backend.info() diff --git a/virtManager/manager.py b/virtManager/manager.py index f12cbc8a..d3f2eaf2 100644 --- a/virtManager/manager.py +++ b/virtManager/manager.py @@ -189,6 +189,7 @@ class vmmManager(vmmGObjectUI): # preferences (we want signal handlers for this) self.enable_polling(COL_DISK) self.enable_polling(COL_NETWORK) + self.enable_polling(COL_MEM) # Select first list entry vmlist = self.widget("vm-list") @@ -279,6 +280,10 @@ class vmmManager(vmmGObjectUI): self.add_gconf_handle( self.config.on_stats_enable_net_poll_changed(self.enable_polling, COL_NETWORK)) + self.add_gconf_handle( + self.config.on_stats_enable_memory_poll_changed( + self.enable_polling, + COL_MEM)) self.toggle_guest_cpu_usage_visible_widget() self.toggle_host_cpu_usage_visible_widget() @@ -991,6 +996,9 @@ class vmmManager(vmmGObjectUI): elif column == COL_NETWORK: widgn = "menu_view_stats_network" do_enable = self.config.get_stats_enable_net_poll() + elif column == COL_MEM: + widgn = "menu_view_stats_memory" + do_enable = self.config.get_stats_enable_memory_poll() widget = self.widget(widgn) tool_text = "" @@ -1002,15 +1010,8 @@ class vmmManager(vmmGObjectUI): widget.set_active(False) widget.set_sensitive(False) tool_text = _("Disabled in preferences dialog.") - widget.set_tooltip_text(tool_text) - disabled_text = _(" (disabled)") - current_text = widget.get_label().strip(disabled_text) - if tool_text: - current_text = current_text + disabled_text - widget.set_label(current_text) - def _toggle_graph_helper(self, do_show, col, datafunc, menu): img = -1 for child in col.get_cells(): diff --git a/virtManager/preferences.py b/virtManager/preferences.py index 6aa7292b..4752ba86 100644 --- a/virtManager/preferences.py +++ b/virtManager/preferences.py @@ -44,6 +44,7 @@ class vmmPreferences(vmmGObjectUI): self.refresh_storage_format() self.refresh_disk_poll() self.refresh_net_poll() + self.refresh_memory_poll() self.refresh_grabkeys_combination() self.refresh_confirm_forcepoweroff() self.refresh_confirm_poweroff() @@ -63,6 +64,7 @@ class vmmPreferences(vmmGObjectUI): "on_prefs_new_vm_sound_toggled": self.change_new_vm_sound, "on_prefs_stats_enable_disk_toggled": self.change_disk_poll, "on_prefs_stats_enable_net_toggled": self.change_net_poll, + "on_prefs_stats_enable_memory_toggled": self.change_memory_poll, "on_prefs_confirm_forcepoweroff_toggled": self.change_confirm_forcepoweroff, "on_prefs_confirm_poweroff_toggled": self.change_confirm_poweroff, "on_prefs_confirm_pause_toggled": self.change_confirm_pause, @@ -162,6 +164,9 @@ class vmmPreferences(vmmGObjectUI): def refresh_net_poll(self): self.widget("prefs-stats-enable-net").set_active( self.config.get_stats_enable_net_poll()) + def refresh_memory_poll(self): + self.widget("prefs-stats-enable-memory").set_active( + self.config.get_stats_enable_memory_poll()) def refresh_grabkeys_combination(self): val = self.config.get_keys_combination() @@ -281,6 +286,8 @@ class vmmPreferences(vmmGObjectUI): self.config.set_stats_enable_disk_poll(src.get_active()) def change_net_poll(self, src): self.config.set_stats_enable_net_poll(src.get_active()) + def change_memory_poll(self, src): + self.config.set_stats_enable_memory_poll(src.get_active()) def change_confirm_forcepoweroff(self, src): self.config.set_confirm_forcepoweroff(src.get_active())