aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/perf/Perf.js
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/modules/perf/Perf.js')
-rw-r--r--desktop/modules/perf/Perf.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/desktop/modules/perf/Perf.js b/desktop/modules/perf/Perf.js
index d84c694..8294e94 100644
--- a/desktop/modules/perf/Perf.js
+++ b/desktop/modules/perf/Perf.js
@@ -188,6 +188,25 @@ function push(list, v, n) {
return out.length > n ? out.slice(out.length - n) : out;
}
+// The process rows of one `top -b` frame, run under LC_ALL=C: [{pid, name,
+// cpu, mem}], cpu in percent of one core as top shows it, mem the resident
+// size in bytes. RES is KiB unless top scaled it to a suffixed unit (1.0g),
+// and COMMAND is the last column and may hold spaces ("Isolated Web Co").
+function procs(text) {
+ const out = [];
+ let rows = false;
+ for (const line of text.split("\n")) {
+ if (/^\s*PID\s+USER\b/.test(line)) { rows = true; continue; }
+ if (!rows) continue;
+ const f = line.trim().split(/\s+/);
+ const res = /^([\d.]+)([kmgtp]?)$/.exec(f[5] || "");
+ if (f.length < 12 || !res) continue;
+ const scale = 1024 ** (1 + Math.max(0, "kmgtp".indexOf(res[2] || "k")));
+ out.push({ pid: Number(f[0]), name: f.slice(11).join(" "), cpu: Number(f[8]), mem: Number(res[1]) * scale });
+ }
+ return out;
+}
+
function bytes(n) {
if (n === null || n === undefined) return "--";
const u = ["B", "K", "M", "G", "T"];