Skip to content

Commit

Permalink
Showing process memory usage works in Flatpak
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Dec 25, 2023
1 parent 24f0dc7 commit cbeb519
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Managers/Process.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -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) {
Expand All @@ -413,4 +424,4 @@ public class Monitor.Process : GLib.Object {
mem_percentage_history.add (mem_percentage);
}

}
}
2 changes: 2 additions & 0 deletions src/Managers/ProcessProvider.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Monitor {

public Gee.HashMap<int, string> pids_cmdline = new Gee.HashMap<int, string> ();
public Gee.HashMap<int, string> pids_stat = new Gee.HashMap<int, string> ();
public Gee.HashMap<int, string> pids_statm = new Gee.HashMap<int, string> ();
public Gee.HashMap<int, string> pids_io = new Gee.HashMap<int, string> ();
public Gee.HashMap<int, string> pids_status = new Gee.HashMap<int, string> ();
public Gee.HashMap<int, string> pids_children = new Gee.HashMap<int, string> ();
Expand Down Expand Up @@ -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"]);
Expand Down
3 changes: 3 additions & 0 deletions src/Managers/ProcessStructs.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit cbeb519

Please sign in to comment.