@@ -8,6 +8,7 @@ import * as crossSpawn from 'cross-spawn'
88import * as logger from '../logger/logger'
99import { Timeout , CancellationError , waitUntil } from './timeoutUtils'
1010import { PollingSet } from './pollingSet'
11+ import { CircularBuffer } from './collectionUtils'
1112
1213export interface RunParameterContext {
1314 /** Reports an error parsed from the stdin/stdout streams. */
@@ -73,6 +74,7 @@ export class ChildProcessTracker {
7374 cpu : 50 ,
7475 }
7576 static readonly logger = logger . getLogger ( 'childProcess' )
77+ static readonly loggedPids = new CircularBuffer ( 1000 )
7678 #processByPid: Map < number , ChildProcess > = new Map < number , ChildProcess > ( )
7779 #pids: PollingSet < number >
7880
@@ -100,21 +102,28 @@ export class ChildProcessTracker {
100102
101103 private async checkProcessUsage ( pid : number ) : Promise < void > {
102104 if ( ! this . #pids. has ( pid ) ) {
103- ChildProcessTracker . logger . warn ( `Missing process with id ${ pid } ` )
105+ ChildProcessTracker . logOnce ( pid , `Missing process with id ${ pid } ` )
104106 return
105107 }
106108 const stats = this . getUsage ( pid )
107109 if ( stats ) {
108110 ChildProcessTracker . logger . debug ( `Process ${ pid } usage: %O` , stats )
109111 if ( stats . memory > ChildProcessTracker . thresholds . memory ) {
110- ChildProcessTracker . logger . warn ( `Process ${ pid } exceeded memory threshold: ${ stats . memory } ` )
112+ ChildProcessTracker . logOnce ( pid , `Process ${ pid } exceeded memory threshold: ${ stats . memory } ` )
111113 }
112114 if ( stats . cpu > ChildProcessTracker . thresholds . cpu ) {
113- ChildProcessTracker . logger . warn ( `Process ${ pid } exceeded cpu threshold: ${ stats . cpu } ` )
115+ ChildProcessTracker . logOnce ( pid , `Process ${ pid } exceeded cpu threshold: ${ stats . cpu } ` )
114116 }
115117 }
116118 }
117119
120+ public static logOnce ( pid : number , msg : string ) {
121+ if ( ! ChildProcessTracker . loggedPids . contains ( pid ) ) {
122+ ChildProcessTracker . loggedPids . add ( pid )
123+ ChildProcessTracker . logger . warn ( msg )
124+ }
125+ }
126+
118127 public add ( childProcess : ChildProcess ) {
119128 const pid = childProcess . pid ( )
120129 this . #processByPid. set ( pid , childProcess )
@@ -147,7 +156,7 @@ export class ChildProcessTracker {
147156 // isWin() leads to circular dependency.
148157 return process . platform === 'win32' ? getWindowsUsage ( ) : getUnixUsage ( )
149158 } catch ( e ) {
150- ChildProcessTracker . logger . warn ( `Failed to get process stats for ${ pid } : ${ e } ` )
159+ ChildProcessTracker . logOnce ( pid , `Failed to get process stats for ${ pid } : ${ e } ` )
151160 return { cpu : 0 , memory : 0 }
152161 }
153162
0 commit comments