
























@@ -14,10 +14,10 @@ if (!isLinux && !isMac) {
1414}
15151616const repoRoot = process.cwd();
17-const tmpHome = mkdtempSync(path.join(os.tmpdir(), "openclaw-startup-memory-"));
1817const tmpDir = process.env.TMPDIR || process.env.TEMP || process.env.TMP || os.tmpdir();
19-const rssHookPath = path.join(tmpHome, "measure-rss.mjs");
2018const MAX_RSS_MARKER = "__OPENCLAW_MAX_RSS_KB__=";
19+let tmpHome = null;
20+let rssHookPath = null;
21212222function parseArgs(argv) {
2323const options = {
@@ -59,18 +59,6 @@ function parseArgs(argv) {
5959return options;
6060}
616162-writeFileSync(
63-rssHookPath,
64-[
65-"process.on('exit', () => {",
66-" const usage = typeof process.resourceUsage === 'function' ? process.resourceUsage() : null;",
67-` if (usage && typeof usage.maxRSS === 'number') console.error('${MAX_RSS_MARKER}' + String(usage.maxRSS));`,
68-"});",
69-"",
70-].join("\n"),
71-"utf8",
72-);
73-7462const DEFAULT_LIMITS_MB = {
7563help: 100,
7664statusJson: 400,
@@ -146,6 +134,9 @@ function formatCaseCommand(testCase) {
146134}
147135148136function buildBenchEnv() {
137+if (!tmpHome) {
138+throw new Error("temporary home is not initialized");
139+}
149140const env = {
150141HOME: tmpHome,
151142USERPROFILE: tmpHome,
@@ -181,6 +172,9 @@ function buildBenchEnv() {
181172}
182173183174function runCase(testCase) {
175+if (!rssHookPath) {
176+throw new Error("RSS hook path is not initialized");
177+}
184178const env = buildBenchEnv();
185179const result = spawnSync(process.execPath, ["--import", rssHookPath, ...testCase.args], {
186180cwd: repoRoot,
@@ -278,14 +272,29 @@ function writeReport(options, results) {
278272}
279273280274const options = parseArgs(process.argv.slice(2));
275+tmpHome = mkdtempSync(path.join(os.tmpdir(), "openclaw-startup-memory-"));
276+rssHookPath = path.join(tmpHome, "measure-rss.mjs");
277+writeFileSync(
278+rssHookPath,
279+[
280+"process.on('exit', () => {",
281+" const usage = typeof process.resourceUsage === 'function' ? process.resourceUsage() : null;",
282+` if (usage && typeof usage.maxRSS === 'number') console.error('${MAX_RSS_MARKER}' + String(usage.maxRSS));`,
283+"});",
284+"",
285+].join("\n"),
286+"utf8",
287+);
281288const results = [];
282289try {
283290for (const testCase of cases) {
284291results.push(runCase(testCase));
285292}
286293} finally {
287294writeReport(options, results);
288-rmSync(tmpHome, { recursive: true, force: true });
295+if (tmpHome) {
296+rmSync(tmpHome, { recursive: true, force: true });
297+}
289298}
290299291300const failure = results.find((result) => result.status !== "pass");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。