pyre-cli 4.13.0 → 4.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -5
- package/package.json +1 -1
- package/src/monitors/collectors.ts +13 -14
package/dist/index.js
CHANGED
|
@@ -504,15 +504,14 @@ async function collectProcesses(limit) {
|
|
|
504
504
|
try {
|
|
505
505
|
const isMac = process.platform === "darwin";
|
|
506
506
|
const sortArg = isMac ? "-r" : "--sort=-pcpu";
|
|
507
|
-
const threadsArg = isMac ? "threads" : "nlwp";
|
|
508
507
|
const headClause = limit && limit > 0 ? ` | head -n ${limit + 1}` : "";
|
|
509
|
-
const raw = (await run(`ps -eo pid,ppid,user,pcpu,pmem,state
|
|
508
|
+
const raw = (await run(`ps -eo pid,ppid,user,pcpu,pmem,state,time,comm ${sortArg}${headClause}`)).trim();
|
|
510
509
|
const lines = raw.split("\n").slice(1);
|
|
511
510
|
return lines.map((line) => {
|
|
512
|
-
const parts = line.match(/\s*(\d+)\s+(\d+)\s+(\S+)\s+([\d.]+)\s+([\d.]+)\s+(\S+)\s+(
|
|
511
|
+
const parts = line.match(/\s*(\d+)\s+(\d+)\s+(\S+)\s+([\d.]+)\s+([\d.]+)\s+(\S+)\s+([\d:.]+)\s+(.+)/);
|
|
513
512
|
if (!parts) return null;
|
|
514
|
-
const runtimeSec = parts[
|
|
515
|
-
return { pid: parseInt(parts[1]), ppid: parseInt(parts[2]), user: parts[3], cpu: parseFloat(parts[4]), mem: parseFloat(parts[5]), state: parts[6], threads:
|
|
513
|
+
const runtimeSec = parts[7].split(":").reduce((acc, val, idx) => acc + parseInt(val) * Math.pow(60, 2 - idx), 0);
|
|
514
|
+
return { pid: parseInt(parts[1]), ppid: parseInt(parts[2]), user: parts[3], cpu: parseFloat(parts[4]), mem: parseFloat(parts[5]), state: parts[6], threads: 0, runtime: runtimeSec, command: parts[8] };
|
|
516
515
|
}).filter((p) => p !== null && p.pid > 0);
|
|
517
516
|
} catch {
|
|
518
517
|
return [];
|
package/package.json
CHANGED
|
@@ -606,20 +606,19 @@ export async function collectNetwork(): Promise<NetworkData> {
|
|
|
606
606
|
|
|
607
607
|
export async function collectProcesses(limit?: number): Promise<ProcessData[]> {
|
|
608
608
|
try {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
.filter((p): p is ProcessData => p !== null && p.pid > 0);
|
|
609
|
+
const isMac = process.platform === 'darwin';
|
|
610
|
+
const sortArg = isMac ? '-r' : '--sort=-pcpu';
|
|
611
|
+
const headClause = limit && limit > 0 ? ` | head -n ${limit + 1}` : '';
|
|
612
|
+
const raw = (await run(`ps -eo pid,ppid,user,pcpu,pmem,state,time,comm ${sortArg}${headClause}`)).trim();
|
|
613
|
+
const lines = raw.split('\n').slice(1);
|
|
614
|
+
return lines
|
|
615
|
+
.map(line => {
|
|
616
|
+
const parts = line.match(/\s*(\d+)\s+(\d+)\s+(\S+)\s+([\d.]+)\s+([\d.]+)\s+(\S+)\s+([\d:.]+)\s+(.+)/);
|
|
617
|
+
if (!parts) return null;
|
|
618
|
+
const runtimeSec = parts[7].split(':').reduce((acc, val, idx) => acc + parseInt(val) * Math.pow(60, 2 - idx), 0);
|
|
619
|
+
return { pid: parseInt(parts[1]), ppid: parseInt(parts[2]), user: parts[3], cpu: parseFloat(parts[4]), mem: parseFloat(parts[5]), state: parts[6], threads: 0, runtime: runtimeSec, command: parts[8] };
|
|
620
|
+
})
|
|
621
|
+
.filter((p): p is ProcessData => p !== null && p.pid > 0);
|
|
623
622
|
} catch {
|
|
624
623
|
return [];
|
|
625
624
|
}
|