prefs: Allow disabling all memorystats polling

Similar to how we allow disabling disk/net polling, not sure yet what
effect it might have on remote connections, so best to add this option
just to be safe.

Unlike disk/net stats, we enable this checking by default.
This commit is contained in:
Cole Robinson 2014-01-12 17:39:21 -05:00
parent 2dffdff328
commit 55d6b7f377
6 changed files with 102 additions and 37 deletions

View File

@ -121,6 +121,11 @@
<summary>Poll net i/o stats</summary>
<description>Whether or not the app will poll VM network i/o statistics</description>
</key>
<key name="enable-memory-poll" type="b">
<default>true</default>
<summary>Poll memory stats</summary>
<description>Whether or not the app will poll VM memory statistics</description>
</key>
</schema>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.0 on Wed Oct 2 14:45:17 2013 -->
<!-- Generated with glade 3.16.0 on Sun Jan 12 17:26:50 2014 -->
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkAdjustment" id="adjustment1">
@ -108,6 +108,9 @@
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="vexpand">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
@ -119,7 +122,7 @@
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">3</property>
<property name="n_rows">4</property>
<property name="n_columns">3</property>
<property name="column_spacing">3</property>
<property name="row_spacing">3</property>
@ -231,6 +234,36 @@
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Poll _Memory stats</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">prefs-stats-enable-memory</property>
</object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="prefs-stats-enable-memory">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_prefs_stats_enable_memory_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
</object>
</child>
</object>
@ -259,7 +292,7 @@
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Stats</property>
<property name="label" translatable="yes">Polling</property>
</object>
<packing>
<property name="position">1</property>

View File

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

View File

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

View File

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

View File

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