[gnome-usage/pstetka/gnome-usage-disk-io: 4/7] system-monitor: Add support for Disk i/o monitoring



commit 8e1a303a62e3e7e1a573aea5f49e984cd0fd1106
Author: Petr Štětka <pstetka redhat com>
Date:   Tue Mar 27 17:38:25 2018 +0200

    system-monitor: Add support for Disk i/o monitoring
    
    Add support for monitoring disk i/o for processes in backend.
    https://bugzilla.gnome.org/show_bug.cgi?id=787549

 src/app-item.vala       |  8 +++++++-
 src/disk-monitor.vala   | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/meson.build         |  3 ++-
 src/monitor.vala        |  1 -
 src/process.vala        |  5 +++++
 src/system-monitor.vala | 23 ++++++++++++++++++++---
 vapi/libgtop-2.0.vapi   | 11 +++++++++++
 7 files changed, 91 insertions(+), 6 deletions(-)
---
diff --git a/src/app-item.vala b/src/app-item.vala
index 244218f..7d66dfa 100644
--- a/src/app-item.vala
+++ b/src/app-item.vala
@@ -8,6 +8,8 @@ namespace Usage
         public uint representative_uid { get; private set; }
         public double cpu_load { get; private set; }
         public uint64 mem_usage { get; private set; }
+        public uint64 disk_read { get; private set; }
+        public uint64 disk_write { get; private set; }
         public Fdo.AccountsUser? user { get; private set; default = null; }
 
         private static HashTable<string, AppInfo>? apps_info;
@@ -85,6 +87,8 @@ namespace Usage
         public void remove_processes() {
             cpu_load = 0;
             mem_usage = 0;
+            disk_read = 0;
+            disk_write = 0;
 
             foreach(var process in processes.get_values()) {
                 if(!process.mark_as_updated)
@@ -92,6 +96,8 @@ namespace Usage
                 else {
                     cpu_load += process.cpu_load;
                     mem_usage += process.mem_usage;
+                    disk_read += process.disk_read;
+                    disk_write += process.disk_write;
                 }
             }
 
@@ -145,4 +151,4 @@ namespace Usage
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/disk-monitor.vala b/src/disk-monitor.vala
new file mode 100644
index 0000000..ac057e0
--- /dev/null
+++ b/src/disk-monitor.vala
@@ -0,0 +1,46 @@
+/* disk-monitor.vala
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Petr Štětka <pstetka redhat com>
+ */
+
+namespace Usage {
+    public class DiskMonitor : Monitor {
+        public uint64 read_bytes { get; private set; }
+        public uint64 write_bytes { get; private set; }
+
+        public void update() {
+            read_bytes = 0;
+            write_bytes = 0;
+        }
+
+        public void update_process(ref Process process, bool first_update) {
+            GTop.ProcIo proc_io;
+            GTop.get_proc_io (out proc_io, process.pid);
+
+            if(!first_update)
+                process.disk_read = proc_io.disk_rbytes - process.disk_read_last;
+            process.disk_read_last = proc_io.disk_rbytes;
+            read_bytes += process.disk_read;
+
+            if(!first_update)
+                process.disk_write = proc_io.disk_wbytes - process.disk_write_last;
+            process.disk_write_last = proc_io.disk_wbytes;
+            write_bytes += process.disk_write;
+        }
+    }
+}
diff --git a/src/meson.build b/src/meson.build
index e31625f..0a754f1 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,6 +7,7 @@ vala_sources = [
   'cpu-graph.vala',
   'cpu-monitor.vala',
   'cpu-sub-view.vala',
+  'disk-monitor.vala',
   'gnome-usage.vala',
   'graph-box.vala',
   'graph-stacked-renderer.vala',
@@ -71,4 +72,4 @@ executable(
   c_args: c_args,
   vala_args: '--vapidir=' + vapi_dir,
   install: true
-)
+)
\ No newline at end of file
diff --git a/src/monitor.vala b/src/monitor.vala
index 2cdf32d..7592c6b 100644
--- a/src/monitor.vala
+++ b/src/monitor.vala
@@ -21,5 +21,4 @@
 public interface Monitor
 {
     public abstract void update ();
-    public abstract void update_process (ref Usage.Process process);
 }
diff --git a/src/process.vala b/src/process.vala
index 0f89c8f..af0b262 100644
--- a/src/process.vala
+++ b/src/process.vala
@@ -34,6 +34,11 @@ namespace Usage
 
         public uint64 mem_usage { get; set; default = 0; }
 
+        public uint64 disk_read { get; set; default = 0; }
+        public uint64 disk_read_last { get; set; default = 0; }
+        public uint64 disk_write { get;  set; default = 0; }
+        public uint64 disk_write_last { get; set; default = 0; }
+
         public bool mark_as_updated { get; set; default = true; }
         public ProcessStatus status { get; private set; default = ProcessStatus.SLEEPING; }
 
diff --git a/src/system-monitor.vala b/src/system-monitor.vala
index 30f9d37..486d3e2 100644
--- a/src/system-monitor.vala
+++ b/src/system-monitor.vala
@@ -22,19 +22,25 @@ namespace Usage
 {
     public class SystemMonitor : Object
     {
-        public bool process_list_ready { get; private set; default = false; }
+        public bool cpu_process_list_ready { get; private set; default = false; }
+        public bool disk_process_list_ready { get; private set; default = false; }
         public double cpu_load { get; private set; }
         public double[] x_cpu_load { get; private set; }
         public uint64 ram_usage { get; private set; }
         public uint64 ram_total { get; private set; }
         public uint64 swap_usage { get; private set; }
         public uint64 swap_total { get; private set; }
+        public uint64 disk_read { get; private set; }
+        public uint64 disk_write { get; private set; }
+
         public bool group_system_apps { get; set; default = true; }
 
         private CpuMonitor cpu_monitor;
         private MemoryMonitor memory_monitor;
+        private DiskMonitor disk_monitor;
 
         private HashTable<string, AppItem> app_table;
+        private bool first_update = true;
         private int process_mode = GTop.KERN_PROC_ALL;
         private static SystemMonitor system_monitor;
 
@@ -63,6 +69,7 @@ namespace Usage
 
             cpu_monitor = new CpuMonitor();
             memory_monitor = new MemoryMonitor();
+            disk_monitor = new DiskMonitor();
 
             app_table = new HashTable<string, AppItem>(str_hash, str_equal);
             var settings = Settings.get_default();
@@ -79,7 +86,6 @@ namespace Usage
         {
             var settings = Settings.get_default();
             app_table.remove_all();
-            process_list_ready = false;
 
             if(group_system_apps) {
                 var system = new AppItem.system();
@@ -89,7 +95,12 @@ namespace Usage
             update_data();
             Timeout.add(settings.data_update_interval, () =>
             {
-                process_list_ready = true;
+                cpu_process_list_ready = true;
+                return false;
+            });
+            Timeout.add(settings.data_update_interval*2, () =>
+            {
+                disk_process_list_ready = true;
                 return false;
             });
         }
@@ -98,6 +109,7 @@ namespace Usage
         {
             cpu_monitor.update();
             memory_monitor.update();
+            disk_monitor.update();
 
             cpu_load = cpu_monitor.get_cpu_load();
             x_cpu_load = cpu_monitor.get_x_cpu_load();
@@ -149,6 +161,10 @@ namespace Usage
             foreach(var app in app_table.get_values())
                 app.remove_processes();
 
+            disk_read = disk_monitor.read_bytes;
+            disk_write = disk_monitor.write_bytes;
+            first_update = false;
+
             return true;
         }
 
@@ -156,6 +172,7 @@ namespace Usage
         {
             cpu_monitor.update_process(ref process);
             memory_monitor.update_process(ref process);
+            disk_monitor.update_process(ref process, first_update);
             process.update_status();
         }
 
diff --git a/vapi/libgtop-2.0.vapi b/vapi/libgtop-2.0.vapi
index e18d171..b8246ba 100644
--- a/vapi/libgtop-2.0.vapi
+++ b/vapi/libgtop-2.0.vapi
@@ -216,4 +216,15 @@ namespace GTop {
     }
     [CCode(array_length = false)]
     public MountEntry[] get_mountlist(out MountList mount_list, bool all_fs);
+
+    [CCode(cname = "glibtop_proc_io", cheader_filename = "glibtop/procio.h")]
+    public struct ProcIo {
+        uint64 flags;
+        uint64 disk_rchar;
+        uint64 disk_wchar;
+        uint64 disk_rbytes;
+        uint64 disk_wbytes;
+        uint64 reserved[10];
+    }
+    public void get_proc_io(out ProcIo proc_io, GLib.Pid pid);
 }


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