3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- /* eslint-disable local/code-no-native-private */
7
-
8
6
import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ;
9
7
import { RemoteAgentConnectionContext , IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment' ;
10
8
import { IChannel , IServerChannel } from 'vs/base/parts/ipc/common/ipc' ;
@@ -74,55 +72,55 @@ export interface IRemoteConnectionLatencyMeasurement {
74
72
75
73
export const remoteConnectionLatencyMeasurer = new class {
76
74
77
- readonly # maxSampleCount = 5 ;
78
- readonly # sampleDelay = 2000 ;
75
+ readonly maxSampleCount = 5 ;
76
+ readonly sampleDelay = 2000 ;
79
77
80
- readonly # initial: number [ ] = [ ] ;
81
- readonly # maxInitialCount = 3 ;
78
+ readonly initial : number [ ] = [ ] ;
79
+ readonly maxInitialCount = 3 ;
82
80
83
- readonly # average: number [ ] = [ ] ;
84
- readonly # maxAverageCount = 100 ;
81
+ readonly average : number [ ] = [ ] ;
82
+ readonly maxAverageCount = 100 ;
85
83
86
- readonly # highLatencyMultiple = 2 ;
87
- readonly # highLatencyMinThreshold = 500 ;
88
- readonly # highLatencyMaxThreshold = 1500 ;
84
+ readonly highLatencyMultiple = 2 ;
85
+ readonly highLatencyMinThreshold = 500 ;
86
+ readonly highLatencyMaxThreshold = 1500 ;
89
87
90
- # lastMeasurement: IRemoteConnectionLatencyMeasurement | undefined = undefined ;
91
- get latency ( ) { return this . # lastMeasurement; }
88
+ lastMeasurement : IRemoteConnectionLatencyMeasurement | undefined = undefined ;
89
+ get latency ( ) { return this . lastMeasurement ; }
92
90
93
91
async measure ( remoteAgentService : IRemoteAgentService ) : Promise < IRemoteConnectionLatencyMeasurement | undefined > {
94
92
let currentLatency = Infinity ;
95
93
96
94
// Measure up to samples count
97
- for ( let i = 0 ; i < this . # maxSampleCount; i ++ ) {
95
+ for ( let i = 0 ; i < this . maxSampleCount ; i ++ ) {
98
96
const rtt = await remoteAgentService . getRoundTripTime ( ) ;
99
97
if ( rtt === undefined ) {
100
98
return undefined ;
101
99
}
102
100
103
101
currentLatency = Math . min ( currentLatency , rtt / 2 /* we want just one way, not round trip time */ ) ;
104
- await timeout ( this . # sampleDelay) ;
102
+ await timeout ( this . sampleDelay ) ;
105
103
}
106
104
107
105
// Keep track of average latency
108
- this . # average. push ( currentLatency ) ;
109
- if ( this . # average. length > this . # maxAverageCount) {
110
- this . # average. shift ( ) ;
106
+ this . average . push ( currentLatency ) ;
107
+ if ( this . average . length > this . maxAverageCount ) {
108
+ this . average . shift ( ) ;
111
109
}
112
110
113
111
// Keep track of initial latency
114
112
let initialLatency : number | undefined = undefined ;
115
- if ( this . # initial. length < this . # maxInitialCount) {
116
- this . # initial. push ( currentLatency ) ;
113
+ if ( this . initial . length < this . maxInitialCount ) {
114
+ this . initial . push ( currentLatency ) ;
117
115
} else {
118
- initialLatency = this . # initial. reduce ( ( sum , value ) => sum + value , 0 ) / this . # initial. length ;
116
+ initialLatency = this . initial . reduce ( ( sum , value ) => sum + value , 0 ) / this . initial . length ;
119
117
}
120
118
121
119
// Remember as last measurement
122
- this . # lastMeasurement = {
120
+ this . lastMeasurement = {
123
121
initial : initialLatency ,
124
122
current : currentLatency ,
125
- average : this . # average. reduce ( ( sum , value ) => sum + value , 0 ) / this . # average. length ,
123
+ average : this . average . reduce ( ( sum , value ) => sum + value , 0 ) / this . average . length ,
126
124
high : ( ( ) => {
127
125
128
126
// based on the initial, average and current latency, try to decide
@@ -137,18 +135,18 @@ export const remoteConnectionLatencyMeasurer = new class {
137
135
return false ;
138
136
}
139
137
140
- if ( currentLatency > this . # highLatencyMaxThreshold) {
138
+ if ( currentLatency > this . highLatencyMaxThreshold ) {
141
139
return true ;
142
140
}
143
141
144
- if ( currentLatency > this . # highLatencyMinThreshold && currentLatency > initialLatency * this . # highLatencyMultiple) {
142
+ if ( currentLatency > this . highLatencyMinThreshold && currentLatency > initialLatency * this . highLatencyMultiple ) {
145
143
return true ;
146
144
}
147
145
148
146
return false ;
149
147
} ) ( )
150
148
} ;
151
149
152
- return this . # lastMeasurement;
150
+ return this . lastMeasurement ;
153
151
}
154
152
} ;
0 commit comments