tt-help-cli-ycl 1.4.6 → 1.4.7
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 +1 -1
- package/src/cli/tag.js +41 -16
package/package.json
CHANGED
package/src/cli/tag.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { writeFileSync } from "fs";
|
|
1
|
+
import { writeFileSync, unlinkSync } from "fs";
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
3
|
import { execSync } from "child_process";
|
|
4
4
|
import os from "os";
|
|
5
|
+
import path from "path";
|
|
5
6
|
import readline from "readline";
|
|
6
7
|
import { fetchTagData, enrichVideosWithLocation } from "../lib/tag-fetcher.js";
|
|
7
8
|
import { killEdgeProcesses, ensureBrowserReady } from "../lib/browser/cdp.js";
|
|
@@ -68,26 +69,50 @@ function getBrowserMemory(port = null) {
|
|
|
68
69
|
}
|
|
69
70
|
} else if (platform === "win32") {
|
|
70
71
|
// Windows: 用 PowerShell 查 msedge 进程内存(WorkingSet64 → MB)
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
// 用临时 .ps1 文件避免命令行转义问题
|
|
73
|
+
const ps1Path = path.join(os.tmpdir(), `edge-mem-${Date.now()}.ps1`);
|
|
74
|
+
try {
|
|
75
|
+
let ps1Content;
|
|
76
|
+
if (port) {
|
|
77
|
+
ps1Content =
|
|
78
|
+
`$procs = Get-CimInstance Win32_Process -Filter "Name LIKE 'msedge%'" -ErrorAction SilentlyContinue; ` +
|
|
79
|
+
`$sum = 0; ` +
|
|
80
|
+
`foreach ($p in $procs) { ` +
|
|
81
|
+
` if ($p.CommandLine -and $p.CommandLine -like "*--remote-debugging-port=${port}*") { ` +
|
|
82
|
+
` $sum += $p.WorkingSetSize ` +
|
|
83
|
+
` } ` +
|
|
84
|
+
`}; ` +
|
|
85
|
+
`Write-Output $sum`;
|
|
86
|
+
} else {
|
|
87
|
+
ps1Content =
|
|
88
|
+
`$procs = Get-CimInstance Win32_Process -Filter "Name LIKE 'msedge%'" -ErrorAction SilentlyContinue; ` +
|
|
89
|
+
`$sum = 0; ` +
|
|
90
|
+
`foreach ($p in $procs) { $sum += $p.WorkingSetSize }; ` +
|
|
91
|
+
`Write-Output $sum`;
|
|
92
|
+
}
|
|
93
|
+
writeFileSync(ps1Path, ps1Content);
|
|
94
|
+
cmd = `powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${ps1Path}"`;
|
|
95
|
+
const result = execSync(cmd, { timeout: 5000 }).toString().trim();
|
|
96
|
+
try {
|
|
97
|
+
unlinkSync(ps1Path);
|
|
98
|
+
} catch {}
|
|
99
|
+
// PowerShell 返回 WorkingSetSize(字节),需除以 1048576 得 MB
|
|
100
|
+
const bytes = parseInt(result, 10);
|
|
101
|
+
const mb = bytes > 0 ? Math.round(bytes / 1048576) : 0;
|
|
102
|
+
return mb > 0 ? mb : null;
|
|
103
|
+
} catch {
|
|
104
|
+
try {
|
|
105
|
+
unlinkSync(ps1Path);
|
|
106
|
+
} catch {}
|
|
107
|
+
return null;
|
|
76
108
|
}
|
|
77
109
|
} else {
|
|
78
110
|
return null;
|
|
79
111
|
}
|
|
112
|
+
// macOS/Linux: ps RSS 是 KB,awk 已除以 1024 得 MB
|
|
80
113
|
const result = execSync(cmd, { timeout: 5000 }).toString().trim();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const bytes = parseInt(result, 10);
|
|
84
|
-
const mb = bytes > 0 ? Math.round(bytes / 1048576) : 0;
|
|
85
|
-
return mb > 0 ? mb : null;
|
|
86
|
-
} else {
|
|
87
|
-
// macOS/Linux: ps RSS 是 KB,awk 已除以 1024 得 MB
|
|
88
|
-
const mb = parseInt(result, 10);
|
|
89
|
-
return mb > 0 ? mb : null;
|
|
90
|
-
}
|
|
114
|
+
const mb = parseInt(result, 10);
|
|
115
|
+
return mb > 0 ? mb : null;
|
|
91
116
|
} catch {
|
|
92
117
|
return null;
|
|
93
118
|
}
|