





















@@ -60,6 +60,7 @@ type CaseResult = {
60606161type CliOptions = {
6262cases: GatewayBenchCase[];
63+cpuProfDir?: string;
6364entry: string;
6465json: boolean;
6566output?: string;
@@ -201,6 +202,7 @@ function resolveCases(caseIds: string[]): GatewayBenchCase[] {
201202function parseOptions(): CliOptions {
202203return {
203204cases: resolveCases(parseRepeatableFlag("--case")),
205+cpuProfDir: parseFlagValue("--cpu-prof-dir"),
204206entry: parseFlagValue("--entry") ?? DEFAULT_ENTRY,
205207json: hasFlag("--json"),
206208output: parseFlagValue("--output"),
@@ -223,6 +225,7 @@ Options:
223225 --runs <n> Measured runs per case (default: ${DEFAULT_RUNS})
224226 --warmup <n> Warmup runs per case (default: ${DEFAULT_WARMUP})
225227 --timeout-ms <ms> Per-run timeout (default: ${DEFAULT_TIMEOUT_MS})
228+ --cpu-prof-dir <dir> Write one V8 CPU profile per run
226229 --output <path> Write machine-readable JSON to a file
227230 --json Emit machine-readable JSON
228231 --help, -h Show this text
@@ -658,7 +661,9 @@ function readProcessTreeCpuMs(rootPid: number | undefined): number | null {
658661659662async function runGatewaySample(options: {
660663benchCase: GatewayBenchCase;
664+cpuProfDir?: string;
661665entry: string;
666+sampleIndex: number;
662667timeoutMs: number;
663668}): Promise<GatewaySample> {
664669const root = mkdtempSync(path.join(tmpdir(), "openclaw-gateway-bench-"));
@@ -674,24 +679,34 @@ async function runGatewaySample(options: {
674679let readyLogMs: number | null = null;
675680let childExited = false;
676681677-const child = spawn(
678-process.execPath,
679-[
680-options.entry,
681-"gateway",
682-"run",
683-"--port",
684-String(port),
685-"--bind",
686-"loopback",
687-"--auth",
688-"none",
689-"--tailscale",
690-"off",
691-"--allow-unconfigured",
692-],
693-{ cwd: process.cwd(), detached: process.platform !== "win32", env },
694-);
682+const childArgs = [
683+ ...(options.cpuProfDir
684+ ? [
685+"--cpu-prof",
686+"--cpu-prof-dir",
687+options.cpuProfDir,
688+"--cpu-prof-name",
689+`openclaw-gateway-${options.benchCase.id}-${options.sampleIndex}-${Date.now()}.cpuprofile`,
690+]
691+ : []),
692+options.entry,
693+"gateway",
694+"run",
695+"--port",
696+String(port),
697+"--bind",
698+"loopback",
699+"--auth",
700+"none",
701+"--tailscale",
702+"off",
703+"--allow-unconfigured",
704+];
705+const child = spawn(process.execPath, childArgs, {
706+cwd: process.cwd(),
707+detached: process.platform !== "win32",
708+ env,
709+});
695710const cpuStartMs = readProcessTreeCpuMs(child.pid);
696711const sampleRss = () => {
697712const rssMb = readProcessRssMb(child.pid);
@@ -773,6 +788,7 @@ async function runGatewaySample(options: {
773788774789async function runCase(options: {
775790benchCase: GatewayBenchCase;
791+cpuProfDir?: string;
776792entry: string;
777793runs: number;
778794timeoutMs: number;
@@ -783,7 +799,9 @@ async function runCase(options: {
783799for (let index = 0; index < total; index += 1) {
784800const sample = await runGatewaySample({
785801benchCase: options.benchCase,
802+cpuProfDir: options.cpuProfDir,
786803entry: options.entry,
804此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。