@@ -104,7 +104,7 @@ export class ChildProcessTracker {
104
104
ChildProcessTracker . logger . warn ( `Missing process with id ${ pid } ` )
105
105
return
106
106
}
107
- const stats = await this . getUsage ( pid )
107
+ const stats = this . getUsage ( pid )
108
108
if ( stats ) {
109
109
ChildProcessTracker . logger . debug ( `Process ${ pid } usage: %O` , stats )
110
110
if ( stats . memory > ChildProcessTracker . thresholds . memory ) {
@@ -143,8 +143,16 @@ export class ChildProcessTracker {
143
143
this . #processByPid. clear ( )
144
144
}
145
145
146
- public async getUsage ( pid : number ) : Promise < ProcessStats > {
147
- const getWindowsUsage = ( ) => {
146
+ public getUsage ( pid : number ) : ProcessStats {
147
+ try {
148
+ // isWin() leads to circular dependency.
149
+ return process . platform === 'win32' ? getWindowsUsage ( ) : getUnixUsage ( )
150
+ } catch ( e ) {
151
+ ChildProcessTracker . logger . warn ( `Failed to get process stats for ${ pid } : ${ e } ` )
152
+ return { cpu : 0 , memory : 0 }
153
+ }
154
+
155
+ function getWindowsUsage ( ) {
148
156
const cpuOutput = proc
149
157
. execFileSync ( 'wmic' , [
150
158
'path' ,
@@ -167,7 +175,8 @@ export class ChildProcessTracker {
167
175
memory : memoryBytes ,
168
176
}
169
177
}
170
- const getUnixUsage = ( ) => {
178
+
179
+ function getUnixUsage ( ) {
171
180
const cpuMemOutput = proc . execFileSync ( 'ps' , [ '-p' , pid . toString ( ) , '-o' , '%cpu,%mem' ] ) . toString ( )
172
181
const rssOutput = proc . execFileSync ( 'ps' , [ '-p' , pid . toString ( ) , '-o' , 'rss' ] ) . toString ( )
173
182
@@ -180,13 +189,6 @@ export class ChildProcessTracker {
180
189
memory : memoryBytes ,
181
190
}
182
191
}
183
- try {
184
- // isWin() leads to circular dependency.
185
- return process . platform === 'win32' ? getWindowsUsage ( ) : getUnixUsage ( )
186
- } catch ( e ) {
187
- ChildProcessTracker . logger . warn ( `Failed to get process stats for ${ pid } : ${ e } ` )
188
- return { cpu : 0 , memory : 0 }
189
- }
190
192
}
191
193
}
192
194
0 commit comments