[gnome-boxes] Add Disk graph stats



commit 91a588f170cf9d8981ba8567a445f4cb4911aa49
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Thu Nov 10 21:48:19 2011 +0100

    Add Disk graph stats

 src/libvirt-machine.vala |   29 ++++++++++++++++++++++++++---
 src/mini-graph.vala      |    6 ++++--
 src/properties.vala      |    2 +-
 3 files changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 3a3a744..4d4262a 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -68,6 +68,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
         double cpu_time_abs;
         double cpu_guest_percent;
         double memory_percent;
+        DomainDiskStats disk;
         double disk_read;
         double disk_write;
         DomainInterfaceStats net;
@@ -117,6 +118,28 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     }
 
     private void update_io_stat (ref MachineStat stat) {
+        if (!is_running ())
+            return;
+
+        try {
+            // FIXME: switch to domain.get_devices () and loop over all interfaces
+            var xmldoc = domain.get_config (0).to_xml ();
+            var target_dev = extract_xpath (xmldoc,
+                "string(/domain/devices/disk[ type='file']/target/@dev)", true);
+            if (target_dev == "")
+                return;
+
+            var disk = GLib.Object.new (typeof (GVir.DomainDisk),
+                                        "path", target_dev,
+                                        "domain", domain) as GVir.DomainDisk;
+            stat.disk = disk.get_stats ();
+            var prev = stats[STATS_SIZE - 1];
+            if (prev.disk != null) {
+                stat.disk_read = (stat.disk.rd_bytes - prev.disk.rd_bytes);
+                stat.disk_write = (stat.disk.wr_bytes - prev.disk.wr_bytes);
+            }
+        } catch (GLib.Error err) {
+        }
     }
 
 
@@ -192,9 +215,9 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                 return;
 
             stats_id = Timeout.add_seconds (1, () => {
-                    update_stats ();
-                    return true;
-                });
+                update_stats ();
+                return true;
+            });
         } else {
             if (stats_id != 0)
                 GLib.Source.remove (stats_id);
diff --git a/src/mini-graph.vala b/src/mini-graph.vala
index 275e1a9..c84664e 100644
--- a/src/mini-graph.vala
+++ b/src/mini-graph.vala
@@ -15,7 +15,7 @@ private class Boxes.MiniGraph: Gtk.DrawingArea {
             ymax_set = true;
         }
     }
-    private bool ymax_set;
+    private bool ymax_set = false;
 
     public MiniGraph (double[] points = {}, int npoints = -1) {
         this.points = points;
@@ -33,9 +33,10 @@ private class Boxes.MiniGraph: Gtk.DrawingArea {
             return 1.0;
 
         double max = points[0];
-        foreach (var p in points)
+        foreach (var p in points) {
             if (p > max)
                 max = p;
+        }
 
         return max;
     }
@@ -59,6 +60,7 @@ private class Boxes.MiniGraph: Gtk.DrawingArea {
         var x = 0.0;
         foreach (var p in points) {
             var y = height - p * dy;
+
             if (x == 0.0)
                 cr.move_to (x, y);
             else
diff --git a/src/properties.vala b/src/properties.vala
index 1c8acbb..5ae240f 100644
--- a/src/properties.vala
+++ b/src/properties.vala
@@ -224,7 +224,7 @@ private class Boxes.Properties: Boxes.UI {
         label = new Gtk.Label (_("I/O:"));
         label.get_style_context ().add_class ("boxes-graph-label");
         grid.attach (label, 2, 0, 1, 1);
-        io = new MiniGraph.with_ymax ({}, 20);
+        io = new MiniGraph ({}, 20);
         io.hexpand = true;
         grid.attach (io, 3, 0, 1, 1);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]