[gnome-usage] Fix showing subprocesses menu with only 1 process. Network processes list have longer update time in



commit 2c44fd75ed40262545c1155a8cbf6d4f0f097b5a
Author: Petr Štětka <pstetka redhat com>
Date:   Wed Apr 12 14:49:27 2017 +0200

    Fix showing subprocesses menu with only 1 process.
    Network processes list have longer update time interval, some as cpu and memory.
    Rename some methods.

 src/cpu-monitor.vala      |    2 +-
 src/memory-monitor.vala   |    2 +-
 src/network-monitor.vala  |    2 +-
 src/process-list-box.vala |   15 +-------
 src/settings.vala         |    1 -
 src/system-monitor.vala   |   90 +++++++++++++++++++++++----------------------
 6 files changed, 50 insertions(+), 62 deletions(-)
---
diff --git a/src/cpu-monitor.vala b/src/cpu-monitor.vala
index 53e46e7..fe98eb3 100644
--- a/src/cpu-monitor.vala
+++ b/src/cpu-monitor.vala
@@ -48,7 +48,7 @@ namespace Usage
             return x_cpu_load;
         }
 
-        public void update_process_info(ref Process process)
+        public void update_process(ref Process process)
         {
             GTop.ProcTime proc_time;
             GTop.ProcState proc_state;
diff --git a/src/memory-monitor.vala b/src/memory-monitor.vala
index d59783f..42f2094 100644
--- a/src/memory-monitor.vala
+++ b/src/memory-monitor.vala
@@ -39,7 +39,7 @@ namespace Usage
             return swap_total;
         }
 
-        public void update_process_info(ref Process process)
+        public void update_process(ref Process process)
         {
             GTop.Mem mem;
             GTop.ProcMem proc_mem;
diff --git a/src/network-monitor.vala b/src/network-monitor.vala
index ddad2c2..fc759dd 100644
--- a/src/network-monitor.vala
+++ b/src/network-monitor.vala
@@ -69,7 +69,7 @@ namespace Usage
             return net_usage;
         }
 
-        public void update_process_info(ref Process process)
+        public void update_process(ref Process process)
         {
             uint64 bytes_out;
             uint64 bytes_in;
diff --git a/src/process-list-box.vala b/src/process-list-box.vala
index f531761..3484912 100644
--- a/src/process-list-box.vala
+++ b/src/process-list-box.vala
@@ -53,20 +53,7 @@ namespace Usage
             bind_model(model, on_row_created);
 
             var settings = (GLib.Application.get_default() as Application).settings;
-
-            uint update_interval;
-            switch(type)
-            {
-                default:
-                case ProcessListBoxType.PROCESSOR:
-                case ProcessListBoxType.MEMORY:
-                    update_interval = settings.list_update_interval_UI;
-                    break;
-                case ProcessListBoxType.NETWORK:
-                    update_interval = settings.list_update_interval_UI_often;
-                    break;
-            }
-            Timeout.add(update_interval, update);
+            Timeout.add(settings.list_update_interval_UI, update);
         }
 
         public bool update()
diff --git a/src/settings.vala b/src/settings.vala
index f7f1f01..484b9cf 100644
--- a/src/settings.vala
+++ b/src/settings.vala
@@ -8,7 +8,6 @@ namespace Usage {
         public uint graph_max_samples { get; set; default = 20; }
         public uint graph_update_interval { get { return 1000; }}
         public uint list_update_interval_UI { get; set; default = 5000; }
-        public uint list_update_interval_UI_often { get; set; default = 1000; }
         public uint list_update_pie_charts_UI { get; set; default = 1000; }
         public uint data_update_interval { get; set; default = 1000; }
     }
diff --git a/src/system-monitor.vala b/src/system-monitor.vala
index 6d7b129..26d6767 100644
--- a/src/system-monitor.vala
+++ b/src/system-monitor.vala
@@ -17,7 +17,7 @@ namespace Usage
         private MemoryMonitor memory_monitor;
         private NetworkMonitor network_monitor;
 
-        private HashTable<Pid?, Process> process_table_pid;
+        private HashTable<Pid?, Process> process_table;
         private HashTable<string, Process> cpu_process_table;
         private HashTable<string, Process> ram_process_table;
         private HashTable<string, Process> net_process_table;
@@ -25,14 +25,14 @@ namespace Usage
                private int process_mode = GTop.EXCLUDE_SYSTEM;
                private GLib.List<AppInfo> apps_info;
 
-               public List<unowned Process> get_processes_pid()
+               public List<unowned Process> get_processes()
         {
-            return process_table_pid.get_values();
+            return process_table.get_values();
         }
 
         public unowned Process get_process_by_pid(Pid pid)
         {
-            return process_table_pid.get(pid);
+            return process_table.get(pid);
         }
 
         public List<unowned Process> get_cpu_processes()
@@ -78,7 +78,7 @@ namespace Usage
             memory_monitor = new MemoryMonitor();
             network_monitor = new NetworkMonitor();
 
-            process_table_pid = new HashTable<Pid?, Process>(int_hash, int_equal);
+            process_table = new HashTable<Pid?, Process>(int_hash, int_equal);
             cpu_process_table = new HashTable<string, Process>(str_hash, str_equal);
             ram_process_table = new HashTable<string, Process>(str_hash, str_equal);
             net_process_table = new HashTable<string, Process>(str_hash, str_equal);
@@ -111,72 +111,72 @@ namespace Usage
             net_upload = network_monitor.get_net_upload();
             net_usage = network_monitor.get_net_usage();
 
-            foreach(unowned Process process in process_table_pid.get_values())
+            foreach(unowned Process process in process_table.get_values())
             {
                 process.set_alive(false);
             }
 
-            set_alive_false_table_cmdline(ref cpu_process_table);
-            set_alive_false_table_cmdline(ref ram_process_table);
-            set_alive_false_table_cmdline(ref net_process_table);
+            set_alive_false(ref cpu_process_table);
+            set_alive_false(ref ram_process_table);
+            set_alive_false(ref net_process_table);
 
             GTop.Proclist proclist;
             var pids = GTop.get_proclist (out proclist, process_mode);
 
             for(uint i = 0; i < proclist.number; i++)
             {
-                if (!(pids[i] in process_table_pid))
+                if (!(pids[i] in process_table))
                 {
                     string cmdline_parameter;
-                    string cmdline = get_full_process_cmd_for_pid(pids[i], out cmdline_parameter);
+                    string cmdline = get_full_process_cmd(pids[i], out cmdline_parameter);
                     string display_name = get_display_name(cmdline, cmdline_parameter);
                     var process = new Process(pids[i], cmdline, cmdline_parameter, display_name);
-                    cpu_monitor.update_process_info(ref process);
-                    process_table_pid.insert (pids[i], (owned) process);
+                    cpu_monitor.update_process(ref process);
+                    process_table.insert (pids[i], (owned) process);
                 }
                 else
                 {
-                    Process process = process_table_pid[pids[i]];
+                    Process process = process_table[pids[i]];
                     process.set_alive(true);
                     get_process_status(ref process);
-                    cpu_monitor.update_process_info(ref process);
-                    memory_monitor.update_process_info(ref process);
-                    network_monitor.update_process_info(ref process);
+                    cpu_monitor.update_process(ref process);
+                    memory_monitor.update_process(ref process);
+                    network_monitor.update_process(ref process);
                 }
             }
 
-            foreach(unowned Process process in process_table_pid.get_values())
+            foreach(unowned Process process in process_table.get_values())
             {
                 if (process.get_alive() == false)
                 {
                     process.set_status(ProcessStatus.DEAD);
-                    process_table_pid.remove (process.get_pid());
+                    process_table.remove (process.get_pid());
                 }
             }
 
-            var process_table_pid_condition = new HashTable<Pid?, Process>(int_hash, int_equal);
-            foreach(unowned Process process in process_table_pid.get_values())
+            var process_table_temp = new HashTable<Pid?, Process>(int_hash, int_equal);
+            foreach(unowned Process process in process_table.get_values())
             {
                 if(process.get_cpu_load() >= 1)
-                    process_table_pid_condition.insert(process.get_pid(), process);
+                    process_table_temp.insert(process.get_pid(), process);
             }
-            get_updates_table_cmdline(process_table_pid_condition, ref cpu_process_table);
+            update_processes(process_table_temp, ref cpu_process_table);
 
-            process_table_pid_condition.remove_all();
-            foreach(unowned Process process in process_table_pid.get_values())
+            process_table_temp.remove_all();
+            foreach(unowned Process process in process_table.get_values())
             {
                 if(process.get_mem_usage() >= 1)
-                    process_table_pid_condition.insert(process.get_pid(), process);
+                    process_table_temp.insert(process.get_pid(), process);
             }
-            get_updates_table_cmdline(process_table_pid_condition, ref ram_process_table);
+            update_processes(process_table_temp, ref ram_process_table);
 
-            process_table_pid_condition.remove_all();
-            foreach(unowned Process process in process_table_pid.get_values())
+            process_table_temp.remove_all();
+            foreach(unowned Process process in process_table.get_values())
             {
                 if(process.get_net_all() >= 1)
-                    process_table_pid_condition.insert(process.get_pid(), process);
+                    process_table_temp.insert(process.get_pid(), process);
             }
-            get_updates_table_cmdline(process_table_pid_condition, ref net_process_table);
+            update_processes(process_table_temp, ref net_process_table);
 
             return true;
         }
@@ -227,7 +227,7 @@ namespace Usage
                 return cmdline;
                }
 
-               private string get_full_process_cmd_for_pid (Pid pid, out string cmd_parameter)
+               private string get_full_process_cmd (Pid pid, out string cmd_parameter)
         {
             GTop.ProcArgs proc_args;
             GTop.ProcState proc_state;
@@ -296,9 +296,9 @@ namespace Usage
                 process.set_status(ProcessStatus.RUNNING);
         }
 
-        private void set_alive_false_table_cmdline(ref HashTable<string, Process> process_table_cmdline)
+        private void set_alive_false(ref HashTable<string, Process> process_table)
         {
-            foreach(unowned Process process in process_table_cmdline.get_values())
+            foreach(unowned Process process in process_table.get_values())
             {
                 if(process.get_sub_processes() == null)
                     process.set_alive(false);
@@ -312,7 +312,7 @@ namespace Usage
             }
         }
 
-        private void get_updates_table_cmdline(HashTable<Pid?, Process> from_table, ref HashTable<string, 
Process> to_table)
+        private void update_processes(HashTable<Pid?, Process> from_table, ref HashTable<string, Process> 
to_table)
         {
             foreach(unowned Process process_it in from_table.get_values())
             {
@@ -381,12 +381,14 @@ namespace Usage
                     {
                         if (sub_process.get_alive() == false)
                             process.get_sub_processes().remove(sub_process.get_pid());
-
-                        cpu_load += sub_process.get_cpu_load();
-                        mem_usage += sub_process.get_mem_usage();
-                        net_all += sub_process.get_net_all();
-                        net_download += sub_process.get_net_download();
-                        net_upload += sub_process.get_net_upload();
+                       else
+                       {
+                               cpu_load += sub_process.get_cpu_load();
+                               mem_usage += sub_process.get_mem_usage();
+                               net_all += sub_process.get_net_all();
+                               net_download += sub_process.get_net_download();
+                               net_upload += sub_process.get_net_upload();
+                       }
                     }
                     process.set_cpu_load(cpu_load);
                     process.set_mem_usage(mem_usage);
@@ -394,15 +396,15 @@ namespace Usage
                     process.set_net_download(net_download);
                     process.set_net_upload(net_upload);
 
-                    if(process.get_sub_processes().size() == 1) //tranform to process
+                    if(process.get_sub_processes().length == 1) //tranform to process
                     {
                         foreach(unowned Process sub_process in process.get_sub_processes().get_values()) 
//only one
                         {
-                            process = sub_process;
                             process.set_sub_processes(null);
+                            process = sub_process;
                         }
                     }
-                    else if(process.get_sub_processes().size() == 0)
+                    else if(process.get_sub_processes().length == 0)
                     {
                         process.set_sub_processes(null);
                         process.set_alive(false);


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