




















@@ -562,6 +562,25 @@ export async function sampleProcess(pid, options = {}) {
562562return samplePosixProcess(pid, run);
563563}
564564565+export function summarizeProcessSamples(samples) {
566+const validSamples = samples.filter((sample) => sample && Number.isFinite(sample.rssMiB));
567+if (validSamples.length === 0) {
568+return null;
569+}
570+const peakRssSample = validSamples.reduce((peak, sample) =>
571+sample.rssMiB > peak.rssMiB ? sample : peak,
572+);
573+const numericCpuSamples = validSamples
574+.map((sample) => sample.cpuPercent)
575+.filter((value) => Number.isFinite(value));
576+return {
577+ ...peakRssSample,
578+sampleCount: validSamples.length,
579+peakCpuPercent:
580+numericCpuSamples.length > 0 ? Math.max(...numericCpuSamples) : peakRssSample.cpuPercent,
581+};
582+}
583+565584async function samplePosixProcess(pid, run) {
566585try {
567586const { stdout } = await run("ps", ["-o", "rss=,pcpu=", "-p", String(pid)], {
@@ -696,9 +715,22 @@ export async function main() {
696715assertIncludesAny(inspectProviders, EXPECTED_PROVIDERS, "plugins inspect providers");
697716698717const child = await startGateway(runner, port, env, logPath);
718+const processSamples = [];
719+const sampleGateway = async () => {
720+const sample = await sampleProcess(child.pid);
721+if (sample) {
722+processSamples.push(sample);
723+}
724+return sample;
725+};
726+let sampleTimer;
699727try {
700728await waitForGatewayReady(child, port, logPath);
701-const initialSample = await sampleProcess(child.pid);
729+const initialSample = await sampleGateway();
730+sampleTimer = setInterval(() => {
731+void sampleGateway().catch(() => {});
732+}, 1000);
733+sampleTimer.unref?.();
702734const healthz = await fetchJson(`http://127.0.0.1:${port}/healthz`);
703735const readyz = await fetchJson(`http://127.0.0.1:${port}/readyz`);
704736if (!healthz.ok || healthz.body?.status !== "live") {
@@ -776,8 +808,10 @@ export async function main() {
776808);
777809}
778810await retryRpcCall("diagnostics.stability", {}, { runner, port, env });
779-const finalSample = await sampleProcess(child.pid);
811+const finalSample = await sampleGateway();
780812assertResourceCeiling(finalSample);
813+const peakSample = summarizeProcessSamples(processSamples);
814+assertResourceCeiling(peakSample);
781815assertNoErrorLogs(logPath);
782816783817console.log(
@@ -790,6 +824,7 @@ export async function main() {
790824 channelAccount,
791825 initialSample,
792826 finalSample,
827+ peakSample,
793828},
794829null,
7958302,
@@ -800,6 +835,9 @@ export async function main() {
800835console.error(tailFile(logPath));
801836throw error;
802837} finally {
838+if (sampleTimer) {
839+clearInterval(sampleTimer);
840+}
803841await stopGateway(child);
804842}
805843}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。