@@ -562,6 +562,25 @@ export async function sampleProcess(pid, options = {}) {
562562 return samplePosixProcess ( pid , run ) ;
563563}
564564
565+ 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 ) {
566585 try {
567586 const { stdout } = await run ( "ps" , [ "-o" , "rss=,pcpu=" , "-p" , String ( pid ) ] , {
@@ -696,9 +715,22 @@ export async function main() {
696715 assertIncludesAny ( inspectProviders , EXPECTED_PROVIDERS , "plugins inspect providers" ) ;
697716
698717 const 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 ;
699727 try {
700728 await 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 ?. ( ) ;
702734 const healthz = await fetchJson ( `http://127.0.0.1:${ port } /healthz` ) ;
703735 const readyz = await fetchJson ( `http://127.0.0.1:${ port } /readyz` ) ;
704736 if ( ! healthz . ok || healthz . body ?. status !== "live" ) {
@@ -776,8 +808,10 @@ export async function main() {
776808 ) ;
777809 }
778810 await retryRpcCall ( "diagnostics.stability" , { } , { runner, port, env } ) ;
779- const finalSample = await sampleProcess ( child . pid ) ;
811+ const finalSample = await sampleGateway ( ) ;
780812 assertResourceCeiling ( finalSample ) ;
813+ const peakSample = summarizeProcessSamples ( processSamples ) ;
814+ assertResourceCeiling ( peakSample ) ;
781815 assertNoErrorLogs ( logPath ) ;
782816
783817 console . log (
@@ -790,6 +824,7 @@ export async function main() {
790824 channelAccount,
791825 initialSample,
792826 finalSample,
827+ peakSample,
793828 } ,
794829 null ,
795830 2 ,
@@ -800,6 +835,9 @@ export async function main() {
800835 console . error ( tailFile ( logPath ) ) ;
801836 throw error ;
802837 } finally {
838+ if ( sampleTimer ) {
839+ clearInterval ( sampleTimer ) ;
840+ }
803841 await stopGateway ( child ) ;
804842 }
805843}
0 commit comments