diff --git a/src/Managers/Process.vala b/src/Managers/Process.vala index bb79b9a6..4fe002bc 100644 --- a/src/Managers/Process.vala +++ b/src/Managers/Process.vala @@ -291,6 +291,7 @@ public class Monitor.Process : GLib.Object { stat.num_threads = int.parse (splitted_stat[19]); stat.utime = ulong.parse (splitted_stat[13]); stat.stime = ulong.parse (splitted_stat[14]); + stat.rss = long.parse (splitted_stat[23]); return true; } @@ -299,7 +300,7 @@ public class Monitor.Process : GLib.Object { string ? statm_contents; if (ProcessUtils.is_flatpak_env ()) { var process_provider = ProcessProvider.get_default (); - statm_contents = process_provider.pids_stat.get (this.stat.pid); + statm_contents = process_provider.pids_statm.get (this.stat.pid); } else { statm_contents = ProcessUtils.read_file ("/proc/%d/statm".printf (stat.pid)); } @@ -393,9 +394,19 @@ public class Monitor.Process : GLib.Object { GTop.Memory mem; GTop.get_mem (out mem); - GTop.ProcMem proc_mem; - GTop.get_proc_mem (out proc_mem, stat.pid); - mem_usage = (proc_mem.resident - proc_mem.share) / 1024; // in KiB + if (ProcessUtils.is_flatpak_env ()) { + mem_usage = (stat.rss * 4096 - statm.shared) / 1024; + + if (stat.pid == 552677) { + debug ("%lld %lld", stat.rss, statm.shared); + } + + } else { + GTop.ProcMem proc_mem; + GTop.get_proc_mem (out proc_mem, stat.pid); + mem_usage = (proc_mem.resident - proc_mem.share) / 1024; // in KiB + } + // also if it is using X Window Server if (Gdk.Display.get_default () is Gdk.X11.Display) { @@ -413,4 +424,4 @@ public class Monitor.Process : GLib.Object { mem_percentage_history.add (mem_percentage); } -} \ No newline at end of file +} diff --git a/src/Managers/ProcessProvider.vala b/src/Managers/ProcessProvider.vala index 75ef4cb9..7ee14daf 100644 --- a/src/Managers/ProcessProvider.vala +++ b/src/Managers/ProcessProvider.vala @@ -7,6 +7,7 @@ namespace Monitor { public Gee.HashMap pids_cmdline = new Gee.HashMap (); public Gee.HashMap pids_stat = new Gee.HashMap (); + public Gee.HashMap pids_statm = new Gee.HashMap (); public Gee.HashMap pids_io = new Gee.HashMap (); public Gee.HashMap pids_status = new Gee.HashMap (); public Gee.HashMap pids_children = new Gee.HashMap (); @@ -36,6 +37,7 @@ namespace Monitor { pids[i] = int.parse (procs[i]["pid"]); pids_cmdline.set (pids[i], procs[i]["cmdline"]); pids_stat.set (pids[i], procs[i]["stat"]); + pids_statm.set (pids[i], procs[i]["statm"]); pids_io.set (pids[i], procs[i]["io"]); pids_children.set (pids[i], procs[i]["children"]); pids_status.set (pids[i], procs[i]["status"]); diff --git a/src/Managers/ProcessStructs.vala b/src/Managers/ProcessStructs.vala index 78878f49..2a352772 100644 --- a/src/Managers/ProcessStructs.vala +++ b/src/Managers/ProcessStructs.vala @@ -104,4 +104,7 @@ public struct Monitor.ProcessStatus { public ulong utime; public ulong stime; + + /** Resident Set Size: number of pages the process has in real memory. */ + public long rss; }