@@ -13,26 +13,18 @@ import {
13
13
import { ChildProcess } from 'child_process' ;
14
14
import { DeprecatePythonPath } from '../../common/experiments/groups' ;
15
15
import { traceDecorators , traceError } from '../../common/logger' ;
16
- import {
17
- IConfigurationService ,
18
- IExperimentsManager ,
19
- IInterpreterPathService ,
20
- IPythonSettings ,
21
- Resource ,
22
- } from '../../common/types' ;
16
+ import { IExperimentsManager , IInterpreterPathService , Resource } from '../../common/types' ;
23
17
import { swallowExceptions } from '../../common/utils/decorators' ;
24
18
import { LanguageServerSymbolProvider } from '../../providers/symbolProvider' ;
25
19
import { PythonEnvironment } from '../../pythonEnvironments/info' ;
26
- import { captureTelemetry , sendTelemetryEvent } from '../../telemetry' ;
20
+ import { captureTelemetry } from '../../telemetry' ;
27
21
import { EventName } from '../../telemetry/constants' ;
28
22
import { ITestingService } from '../../testing/types' ;
29
23
import { FileBasedCancellationStrategy } from '../common/cancellationUtils' ;
30
24
import { LanguageClientMiddleware } from '../languageClientMiddleware' ;
31
25
import { ProgressReporting } from '../progress' ;
32
26
import { ILanguageClientFactory , ILanguageServerProxy } from '../types' ;
33
- import { StopWatch } from '../../common/utils/stopWatch' ;
34
- import { getMemoryUsage } from '../../common/process/memory' ;
35
- import { killPidTree } from '../../common/process/rawProcessApis' ;
27
+ import { killPid } from '../../common/process/rawProcessApis' ;
36
28
37
29
@injectable ( )
38
30
export class JediLanguageServerProxy implements ILanguageServerProxy {
@@ -46,18 +38,11 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
46
38
47
39
private lsVersion : string | undefined ;
48
40
49
- private pidUsageFailures = { timer : new StopWatch ( ) , counter : 0 } ;
50
-
51
- private pythonSettings : IPythonSettings | undefined ;
52
-
53
- private timer ?: NodeJS . Timer | number ;
54
-
55
41
constructor (
56
42
@inject ( ILanguageClientFactory ) private readonly factory : ILanguageClientFactory ,
57
43
@inject ( ITestingService ) private readonly testManager : ITestingService ,
58
44
@inject ( IExperimentsManager ) private readonly experiments : IExperimentsManager ,
59
45
@inject ( IInterpreterPathService ) private readonly interpreterPathService : IInterpreterPathService ,
60
- @inject ( IConfigurationService ) private readonly configurationService : IConfigurationService ,
61
46
) { }
62
47
63
48
private static versionTelemetryProps ( instance : JediLanguageServerProxy ) {
@@ -73,7 +58,7 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
73
58
const pid : number | undefined = ( ( this . languageClient as any ) . _serverProcess as ChildProcess ) ?. pid ;
74
59
const killServer = ( ) => {
75
60
if ( pid ) {
76
- killPidTree ( pid ) ;
61
+ killPid ( pid ) ;
77
62
}
78
63
} ;
79
64
// Do not await on this.
@@ -92,11 +77,6 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
92
77
this . cancellationStrategy = undefined ;
93
78
}
94
79
95
- if ( this . timer ) {
96
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
- clearTimeout ( this . timer as any ) ;
98
- }
99
-
100
80
while ( this . disposables . length > 0 ) {
101
81
const d = this . disposables . shift ( ) ! ;
102
82
d . dispose ( ) ;
@@ -122,8 +102,6 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
122
102
return this . serverReady ( ) ;
123
103
}
124
104
125
- this . pythonSettings = this . configurationService . getSettings ( resource ) ;
126
-
127
105
this . lsVersion =
128
106
( options . middleware ? ( < LanguageClientMiddleware > options . middleware ) . serverVersion : undefined ) ?? '0.19.3' ;
129
107
@@ -150,13 +128,6 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
150
128
}
151
129
152
130
await this . registerTestServices ( ) ;
153
-
154
- try {
155
- await this . checkJediLSPMemoryFootprint ( ) ;
156
- } catch ( ex ) {
157
- // Ignore errors
158
- }
159
-
160
131
return Promise . resolve ( ) ;
161
132
}
162
133
@@ -209,56 +180,4 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
209
180
) ;
210
181
}
211
182
}
212
-
213
- private async checkJediLSPMemoryFootprint ( ) {
214
- // Check memory footprint periodically. Do not check on every request due to
215
- // the performance impact. See https://github.com/soyuka/pidusage - on Windows
216
- // it is using wmic which means spawning cmd.exe process on every request.
217
- if ( this . pythonSettings && this . pythonSettings . jediMemoryLimit === - 1 ) {
218
- return ;
219
- }
220
-
221
- await this . sendJediMemoryTelemetry ( ) ;
222
- if ( this . timer ) {
223
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
224
- clearTimeout ( this . timer as any ) ;
225
- }
226
- this . timer = setTimeout ( ( ) => this . checkJediLSPMemoryFootprint ( ) , 15 * 1000 ) ;
227
- }
228
-
229
- private async sendJediMemoryTelemetry ( ) : Promise < void > {
230
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
- const proc : ChildProcess | undefined = ( this . languageClient as any ) . _serverProcess as ChildProcess ;
232
- if (
233
- ! proc ||
234
- proc . killed ||
235
- this . pidUsageFailures . counter > 2 ||
236
- ! this . pythonSettings ||
237
- this . pythonSettings . jediMemoryLimit === - 1
238
- ) {
239
- return ;
240
- }
241
-
242
- try {
243
- const memory = await getMemoryUsage ( proc . pid ) ;
244
- const limit = Math . min ( Math . max ( this . pythonSettings . jediMemoryLimit , 3072 ) , 8192 ) * 1024 * 1024 ;
245
- if ( memory > 0 ) {
246
- const props = {
247
- memUse : memory ,
248
- limit,
249
- isUserDefinedLimit : limit !== 1024 ,
250
- restart : false ,
251
- } ;
252
- sendTelemetryEvent ( EventName . JEDI_MEMORY , undefined , props ) ;
253
- }
254
- } catch ( err ) {
255
- this . pidUsageFailures . counter += 1 ;
256
- // If this function fails 2 times in the last 60 seconds, lets not try ever again.
257
- if ( this . pidUsageFailures . timer . elapsedTime > 60 * 1000 ) {
258
- this . pidUsageFailures . counter = 0 ;
259
- this . pidUsageFailures . timer . reset ( ) ;
260
- }
261
- traceError ( 'Python Extension: (pidusage-tree)' , err ) ;
262
- }
263
- }
264
183
}
0 commit comments