tt-help-cli-ycl 1.4.61 → 1.4.62
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/package.json
CHANGED
|
@@ -13,14 +13,31 @@ import { spawn, execSync } from "child_process";
|
|
|
13
13
|
import { EventEmitter } from "events";
|
|
14
14
|
|
|
15
15
|
const MAX_RESTART = 3;
|
|
16
|
+
const IS_WIN = process.platform === "win32";
|
|
16
17
|
|
|
17
18
|
function getProcessStats(pid) {
|
|
18
19
|
try {
|
|
19
|
-
const
|
|
20
|
+
const cmd = IS_WIN
|
|
21
|
+
? `tasklist /FI "PID eq ${pid}" /FO CSV /NH`
|
|
22
|
+
: `ps -p ${pid} -o rss=,etime=`;
|
|
23
|
+
const stdout = execSync(cmd, {
|
|
20
24
|
encoding: "utf-8",
|
|
21
25
|
timeout: 3000,
|
|
26
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
22
27
|
}).trim();
|
|
23
28
|
if (!stdout) return null;
|
|
29
|
+
|
|
30
|
+
if (IS_WIN) {
|
|
31
|
+
// tasklist CSV: "name.exe","pid","session","session#","mem usage"
|
|
32
|
+
const cols = stdout.split(",");
|
|
33
|
+
const memStr = (cols[4] || "").replace(/[^0-9.]/g, "");
|
|
34
|
+
const memKB = parseInt(memStr, 10);
|
|
35
|
+
return {
|
|
36
|
+
memoryMB: isNaN(memKB) ? 0 : Math.round((memKB / 1024) * 10) / 10,
|
|
37
|
+
elapsed: "?",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
24
41
|
const parts = stdout.split(/\s+/);
|
|
25
42
|
const rssKB = parseInt(parts[0], 10);
|
|
26
43
|
const elapsed = parts.slice(1).join(" ") || "0";
|