preferences: Allow disabling VM CPU poll

With this, the only libvirt API call we hit on each tick is the
connection nodeinfo.
This commit is contained in:
Cole Robinson 2014-02-11 15:29:30 -05:00
parent a70b836b2d
commit d220cc5d52
7 changed files with 98 additions and 28 deletions

View File

@ -116,11 +116,15 @@
<description>The statistics update interval in seconds</description>
</key>
<key name="enable-cpu-poll" type="b">
<default>true</default>
<summary>Poll VM CPU stats</summary>
<description>Whether or not the app will poll VM CPU statistics</description>
</key>
<key name="enable-disk-poll" type="b">
<default>false</default>
<summary>Poll disk i/o stats</summary>
<description>Whether or not the app will poll VM disk i/o statistics</description>
</key>
<key name="enable-net-poll" type="b">
<default>false</default>

View File

@ -116,7 +116,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -132,7 +132,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -148,7 +148,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -164,7 +164,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -180,7 +180,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -196,7 +196,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@ -256,6 +256,38 @@
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label28">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Poll C_PU usage</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">prefs-stats-enable-cpu</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="prefs-stats-enable-cpu">
<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_cpu_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
</child>
</object>

View File

@ -343,6 +343,8 @@ class vmmConfig(object):
# Disable/Enable different stats polling
def get_stats_enable_cpu_poll(self):
return self.conf.get("/stats/enable-cpu-poll")
def get_stats_enable_disk_poll(self):
return self.conf.get("/stats/enable-disk-poll")
def get_stats_enable_net_poll(self):
@ -350,6 +352,8 @@ class vmmConfig(object):
def get_stats_enable_memory_poll(self):
return self.conf.get("/stats/enable-memory-poll")
def set_stats_enable_cpu_poll(self, val):
self.conf.set("/stats/enable-cpu-poll", val)
def set_stats_enable_disk_poll(self, val):
self.conf.set("/stats/enable-disk-poll", val)
def set_stats_enable_net_poll(self, val):
@ -357,6 +361,8 @@ class vmmConfig(object):
def set_stats_enable_memory_poll(self, val):
self.conf.set("/stats/enable-memory-poll", val)
def on_stats_enable_cpu_poll_changed(self, cb, row=None):
return self.conf.notify_add("/stats/enable-cpu-poll", cb, row)
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):

View File

@ -2498,7 +2498,8 @@ class vmmDetails(vmmGObjectUI):
dsk_txt = _("Disabled")
net_txt = _("Disabled")
cpu_txt = "%d %%" % self.vm.guest_cpu_time_percentage()
if self.config.get_stats_enable_cpu_poll():
cpu_txt = "%d %%" % self.vm.guest_cpu_time_percentage()
if self.config.get_stats_enable_memory_poll():
cur_vm_memory = self.vm.stats_memory()

View File

@ -261,6 +261,7 @@ class vmmDomain(vmmLibvirtObject):
self.mem_stats_supported = False
self._enable_mem_stats = False
self._enable_cpu_stats = False
self._enable_net_poll = False
self._stats_net_supported = True
@ -303,19 +304,23 @@ class vmmDomain(vmmLibvirtObject):
self.toggle_sample_network_traffic()
self.toggle_sample_disk_io()
self.toggle_sample_mem_stats()
self.toggle_sample_cpu_stats()
self.force_update_status(from_event=True)
# Hook up listeners that need to be cleaned up
self.add_gconf_handle(
self.config.on_stats_enable_cpu_poll_changed(
self.toggle_sample_cpu_stats))
self.add_gconf_handle(
self.config.on_stats_enable_net_poll_changed(
self.toggle_sample_network_traffic))
self.toggle_sample_network_traffic))
self.add_gconf_handle(
self.config.on_stats_enable_disk_poll_changed(
self.toggle_sample_disk_io))
self.toggle_sample_disk_io))
self.add_gconf_handle(
self.config.on_stats_enable_memory_poll_changed(
self.toggle_sample_mem_stats))
self.toggle_sample_mem_stats))
self.connect("status-changed", self._update_start_vcpus)
self.connect("pre-startup", self._prestartup_nodedev_check)
@ -1422,6 +1427,9 @@ class vmmDomain(vmmLibvirtObject):
#################
def _sample_cpu_stats(self, info, now):
if not self._enable_cpu_stats:
return 0, 0, 0, 0
prevCpuTime = 0
prevTimestamp = 0
cpuTime = 0
@ -1523,6 +1531,9 @@ class vmmDomain(vmmLibvirtObject):
def toggle_sample_mem_stats(self, ignore=None):
self._enable_mem_stats = self.config.get_stats_enable_memory_poll()
def toggle_sample_cpu_stats(self, ignore=None):
self._enable_cpu_stats = self.config.get_stats_enable_cpu_poll()
###################
# Stats accessors #
@ -1838,7 +1849,9 @@ class vmmDomain(vmmLibvirtObject):
if not self._using_events():
self._invalidate_xml()
info = self._backend.info()
info = []
if not self._using_events() or self._enable_cpu_stats:
info = self._backend.info()
if stats_update:
self._tick_stats(info)

View File

@ -189,6 +189,7 @@ class vmmManager(vmmGObjectUI):
# Initialize stat polling columns based on global polling
# preferences (we want signal handlers for this)
self.enable_polling(COL_GUEST_CPU)
self.enable_polling(COL_DISK)
self.enable_polling(COL_NETWORK)
self.enable_polling(COL_MEM)
@ -277,15 +278,17 @@ class vmmManager(vmmGObjectUI):
# Register callbacks with the global stats enable/disable values
# that disable the associated vmlist widgets if reporting is disabled
self.add_gconf_handle(
self.config.on_stats_enable_disk_poll_changed(self.enable_polling,
COL_DISK))
self.config.on_stats_enable_cpu_poll_changed(
self.enable_polling, COL_GUEST_CPU))
self.add_gconf_handle(
self.config.on_stats_enable_net_poll_changed(self.enable_polling,
COL_NETWORK))
self.config.on_stats_enable_disk_poll_changed(
self.enable_polling, COL_DISK))
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.enable_polling, COL_MEM))
self.toggle_guest_cpu_usage_visible_widget()
self.toggle_host_cpu_usage_visible_widget()
@ -982,6 +985,9 @@ class vmmManager(vmmGObjectUI):
return cmp(obj1.network_traffic_rate(), obj2.network_traffic_rate())
def enable_polling(self, column):
if column == COL_GUEST_CPU:
widgn = ["menu_view_stats_guest_cpu", "menu_view_stats_host_cpu"]
do_enable = self.config.get_stats_enable_cpu_poll()
if column == COL_DISK:
widgn = "menu_view_stats_disk"
do_enable = self.config.get_stats_enable_disk_poll()
@ -991,18 +997,19 @@ class vmmManager(vmmGObjectUI):
elif column == COL_MEM:
widgn = "menu_view_stats_memory"
do_enable = self.config.get_stats_enable_memory_poll()
widget = self.widget(widgn)
tool_text = ""
for w in util.listify(widgn):
widget = self.widget(w)
tool_text = ""
if do_enable:
widget.set_sensitive(True)
else:
if widget.get_active():
widget.set_active(False)
widget.set_sensitive(False)
tool_text = _("Disabled in preferences dialog.")
widget.set_tooltip_text(tool_text)
if do_enable:
widget.set_sensitive(True)
else:
if widget.get_active():
widget.set_active(False)
widget.set_sensitive(False)
tool_text = _("Disabled in preferences dialog.")
widget.set_tooltip_text(tool_text)
def _toggle_graph_helper(self, do_show, col, datafunc, menu):
img = -1

View File

@ -45,6 +45,7 @@ class vmmPreferences(vmmGObjectUI):
self.refresh_add_spice_usbredir()
self.refresh_storage_format()
self.refresh_cpu_default()
self.refresh_cpu_poll()
self.refresh_disk_poll()
self.refresh_net_poll()
self.refresh_memory_poll()
@ -71,6 +72,7 @@ class vmmPreferences(vmmGObjectUI):
"on_prefs_add_spice_usbredir_changed": self.change_add_spice_usbredir,
"on_prefs_storage_format_changed": self.change_storage_format,
"on_prefs_cpu_default_changed": self.change_cpu_default,
"on_prefs_stats_enable_cpu_toggled": self.change_cpu_poll,
"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,
@ -214,6 +216,9 @@ class vmmPreferences(vmmGObjectUI):
val = self.config.get_default_cpu_setting(raw=True)
uiutil.set_row_selection(combo, val)
def refresh_cpu_poll(self):
self.widget("prefs-stats-enable-cpu").set_active(
self.config.get_stats_enable_cpu_poll())
def refresh_disk_poll(self):
self.widget("prefs-stats-enable-disk").set_active(
self.config.get_stats_enable_disk_poll())
@ -355,6 +360,8 @@ class vmmPreferences(vmmGObjectUI):
typ = uiutil.get_list_selection(src, 0) or "default"
self.config.set_default_cpu_setting(typ.lower())
def change_cpu_poll(self, src):
self.config.set_stats_enable_cpu_poll(src.get_active())
def change_disk_poll(self, src):
self.config.set_stats_enable_disk_poll(src.get_active())
def change_net_poll(self, src):