1
>
/*---------------------------------------------------------------------------------------------
remoteAgentService.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
7
>
import { RemoteAgentConnectionContext, IRemoteAgentEnvironment } from '../../../../platform/remote/common/remoteAgentEnvironment.js';
8
>
import { IChannel, IServerChannel } from '../../../../base/parts/ipc/common/ipc.js';
9
>
import { IDiagnosticInfoOptions, IDiagnosticInfo } from '../../../../platform/diagnostics/common/diagnostics.js';
10
>
import { Event } from '../../../../base/common/event.js';
11
>
import { PersistentConnectionEvent } from '../../../../platform/remote/common/remoteAgentConnection.js';
12
>
import { ITelemetryData, TelemetryLevel } from '../../../../platform/telemetry/common/telemetry.js';
13
>
import { timeout } from '../../../../base/common/async.js';
14
>
15
>
export const IRemoteAgentService = createDecorator<IRemoteAgentService>('remoteAgentService');
16
>
17
>
export interface IRemoteAgentService {
18
>
readonly _serviceBrand: undefined;
19
>
20
>
getConnection(): IRemoteAgentConnection | null;
21
>
/**
22
>
* Get the remote environment. In case of an error, returns `null`.
23
>
*/
24
>
getEnvironment(): Promise<IRemoteAgentEnvironment | null>;
25
>
/**
26
>
* Get the remote environment. Can return an error.
27
>
*/
28
>
getRawEnvironment(): Promise<IRemoteAgentEnvironment | null>;
29
>
/**
30
>
* Get exit information for a remote extension host.
31
>
*/
32
>
getExtensionHostExitInfo(reconnectionToken: string): Promise<IExtensionHostExitInfo | null>;
33
>
34
>
/**
35
>
* Gets the round trip time from the remote extension host. Note that this
36
>
* may be delayed if the extension host is busy.
37
>
*/
38
>
getRoundTripTime(): Promise<number | undefined>;
39
>
40
>
/**
41
>
* Gracefully ends the current connection, if any.
42
>
*/
43
>
endConnection(): Promise<void>;
44
>
45
>
getDiagnosticInfo(options: IDiagnosticInfoOptions): Promise<IDiagnosticInfo | undefined>;
46
>
updateTelemetryLevel(telemetryLevel: TelemetryLevel): Promise<void>;
47
>
logTelemetry(eventName: string, data?: ITelemetryData): Promise<void>;
48
>
flushTelemetry(): Promise<void>;
49
>
}
50
>
51
>
export interface IExtensionHostExitInfo {
52
>
code: number;
53
>
signal: string;
54
>
}
55
>
56
>
export interface IRemoteAgentConnection {
57
>
readonly remoteAuthority: string;
58
>
59
>
readonly onReconnecting: Event<void>;
60
>
readonly onDidStateChange: Event<PersistentConnectionEvent>;
61
>
62
>
end(): Promise<void>;
63
>
dispose(): void;
64
>
getChannel<T extends IChannel>(channelName: string): T;
65
>
withChannel<T extends IChannel, R>(channelName: string, callback: (channel: T) => Promise<R>): Promise<R>;
66
>
registerChannel<T extends IServerChannel<RemoteAgentConnectionContext>>(channelName: string, channel: T): void;
67
>
getInitialConnectionTimeMs(): Promise<number>;
68
>
updateGraceTime(graceTime: number): void;
69
>
}
70
>
71
>
export interface IRemoteConnectionLatencyMeasurement {
72
>
73
>
readonly initial: number | undefined;
74
>
readonly current: number;
75
>
readonly average: number;
76
>
77
>
readonly high: boolean;
78
>
}
79
>
80
>
export const remoteConnectionLatencyMeasurer = new class {
81
>
82
>
readonly maxSampleCount = 5;
83
>
readonly sampleDelay = 2000;
84
>
85
>
readonly initial: number[] = [];
86
>
readonly maxInitialCount = 3;
87
>
88
>
readonly average: number[] = [];
89
>
readonly maxAverageCount = 100;
90
>
91
>
readonly highLatencyMultiple = 2;
92
>
readonly highLatencyMinThreshold = 500;
93
>
readonly highLatencyMaxThreshold = 1500;
94
>
95
>
lastMeasurement: IRemoteConnectionLatencyMeasurement | undefined = undefined;
96
>
get latency() { return this.lastMeasurement; }
97
>
98
>
async measure(remoteAgentService: IRemoteAgentService): Promise<IRemoteConnectionLatencyMeasurement | undefined> {
99
let currentLatency = Infinity;
100