[gnome-boxes/gnome-3-4] Asynchronously get information on libvirt domain
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/gnome-3-4] Asynchronously get information on libvirt domain
- Date: Mon, 14 May 2012 20:49:16 +0000 (UTC)
commit 485e9cf702b0107f80cfdb1b4d0d57e82afdc0fe
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Apr 19 03:38:15 2012 +0300
Asynchronously get information on libvirt domain
When a libvirt machine is selected, information is fetched for it every
second and the call to fetch the information can take from about 2.5s to
2 *minutes* 45s (currently thats the case due to a regression in libvirt).
https://bugzilla.gnome.org/show_bug.cgi?id=674352
configure.ac | 2 +-
src/libvirt-machine.vala | 34 +++++++++++++++++++++++++---------
2 files changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b1e4268..238ed20 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ GLIB_MIN_VERSION=2.29.90
GOBJECT_INTROSPECTION_MIN_VERSION=0.9.6
GTK_MIN_VERSION=3.3.5
GTK_VNC_MIN_VERSION=0.4.4
-LIBVIRT_GLIB_MIN_VERSION=0.0.6
+LIBVIRT_GLIB_MIN_VERSION=0.0.8
LIBVIRT_GCONFIG_MIN_VERSION=0.0.8
LIBXML2_MIN_VERSION=2.7.8
SPICE_GTK_MIN_VERSION=0.9
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index f2f0bb6..142c248 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -84,11 +84,14 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
private uint ram_update_timeout = 0;
private uint storage_update_timeout = 0;
+ private uint stats_update_timeout;
+ private Cancellable stats_cancellable;
static const int STATS_SIZE = 20;
private MachineStat[] stats;
construct {
stats = new MachineStat[STATS_SIZE];
+ stats_cancellable = new Cancellable ();
}
public void update_domain_config () {
@@ -185,11 +188,11 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
public double[] cpu_stats;
public double[] io_stats;
public double[] net_stats;
- private void update_stats () {
+ private async void update_stats () {
try {
var now = get_monotonic_time ();
var stat = MachineStat () { timestamp = now };
- var info = domain.get_info ();
+ var info = yield domain.get_info_async (stats_cancellable);
update_cpu_stat (info, ref stat);
update_mem_stat (info, ref stat);
@@ -199,6 +202,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
stats = stats[1:STATS_SIZE];
stats += stat;
+ } catch (IOError.CANCELLED err) {
+ return;
} catch (GLib.Error err) {
warning (err.message);
}
@@ -216,22 +221,33 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
stats_updated ();
}
- private uint stats_id;
private void set_stats_enable (bool enable) {
if (enable) {
debug ("enable statistics for " + name);
- if (stats_id != 0)
+ if (stats_update_timeout != 0)
return;
- stats_id = Timeout.add_seconds (1, () => {
- update_stats ();
+ stats_cancellable.reset ();
+ var stats_updating = false;
+ stats_update_timeout = Timeout.add_seconds (1, () => {
+ if (stats_updating) {
+ warning ("Fetching of stats for '%s' is taking too long. Probably a libvirt bug.", name);
+
+ return true;
+ }
+
+ stats_updating = true;
+ update_stats.begin (() => { stats_updating = false; });
+
return true;
});
} else {
debug ("disable statistics for " + name);
- if (stats_id != 0)
- GLib.Source.remove (stats_id);
- stats_id = 0;
+ if (stats_update_timeout != 0) {
+ stats_cancellable.cancel ();
+ GLib.Source.remove (stats_update_timeout);
+ }
+ stats_update_timeout = 0;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]