Skip to content

Commit 968379f

Browse files
authored
Merge pull request microsoft#187281 from microsoft/tyriar/187274
Log latency stats and remove old unused latency mechanism
2 parents d1ae8a6 + 6ea4677 commit 968379f

File tree

18 files changed

+82
-93
lines changed

18 files changed

+82
-93
lines changed

src/vs/platform/terminal/common/terminal.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ export interface IPtyService {
300300
*/
301301
listProcesses(): Promise<IProcessDetails[]>;
302302
getPerformanceMarks(): Promise<performance.PerformanceMark[]>;
303+
/**
304+
* Measures and returns the latency of the current and all other processes to the pty host.
305+
*/
306+
getLatency(): Promise<IPtyHostLatencyMeasurement[]>;
303307

304308
start(id: number): Promise<ITerminalLaunchError | { injectedArgs: string[] } | undefined>;
305309
shutdown(id: number, immediate: boolean): Promise<void>;
@@ -308,7 +312,6 @@ export interface IPtyService {
308312
clearBuffer(id: number): Promise<void>;
309313
getInitialCwd(id: number): Promise<string>;
310314
getCwd(id: number): Promise<string>;
311-
getLatency(id: number): Promise<number>;
312315
acknowledgeDataEvent(id: number, charCount: number): Promise<void>;
313316
setUnicodeVersion(id: number, version: '6' | '11'): Promise<void>;
314317
processBinary(id: number, data: string): Promise<void>;
@@ -367,6 +370,11 @@ export interface IPtyHostController {
367370
export interface IPtyHostService extends IPtyService, IPtyHostController {
368371
}
369372

373+
export interface IPtyHostLatencyMeasurement {
374+
label: string;
375+
latency: number;
376+
}
377+
370378
/**
371379
* Serialized terminal state matching the interface that can be used across versions, the version
372380
* should be verified before using the state payload.
@@ -739,7 +747,6 @@ export interface ITerminalChildProcess {
739747

740748
getInitialCwd(): Promise<string>;
741749
getCwd(): Promise<string>;
742-
getLatency(): Promise<number>;
743750
refreshProperty<T extends ProcessPropertyType>(property: T): Promise<IProcessPropertyMap[T]>;
744751
updateProperty<T extends ProcessPropertyType>(property: T, value: IProcessPropertyMap[T]): Promise<void>;
745752
}
@@ -992,6 +999,7 @@ export interface ITerminalBackend {
992999
attachToProcess(id: number): Promise<ITerminalChildProcess | undefined>;
9931000
attachToRevivedProcess(id: number): Promise<ITerminalChildProcess | undefined>;
9941001
listProcesses(): Promise<IProcessDetails[]>;
1002+
getLatency(): Promise<IPtyHostLatencyMeasurement[]>;
9951003
getDefaultSystemShell(osOverride?: OperatingSystem): Promise<string>;
9961004
getProfiles(profiles: unknown, defaultProfile: unknown, includeDetectedProfiles?: boolean): Promise<ITerminalProfile[]>;
9971005
getWslPath(original: string, direction: 'unix-to-win' | 'win-to-unix'): Promise<string>;

src/vs/platform/terminal/node/ptyHostService.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { RemoteLoggerChannelClient } from 'vs/platform/log/common/logIpc';
1313
import { getResolvedShellEnv } from 'vs/platform/shell/node/shellEnv';
1414
import { IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/capabilities/capabilities';
1515
import { RequestStore } from 'vs/platform/terminal/common/requestStore';
16-
import { HeartbeatConstants, IHeartbeatService, IProcessDataEvent, IProcessProperty, IProcessPropertyMap, IProcessReadyEvent, IPtyHostService, IPtyService, IRequestResolveVariablesEvent, ISerializedTerminalState, IShellLaunchConfig, ITerminalLaunchError, ITerminalProcessOptions, ITerminalProfile, ITerminalsLayoutInfo, ProcessPropertyType, TerminalIcon, TerminalIpcChannels, TerminalSettingId, TitleEventSource } from 'vs/platform/terminal/common/terminal';
16+
import { HeartbeatConstants, IHeartbeatService, IProcessDataEvent, IProcessProperty, IProcessPropertyMap, IProcessReadyEvent, IPtyHostLatencyMeasurement, IPtyHostService, IPtyService, IRequestResolveVariablesEvent, ISerializedTerminalState, IShellLaunchConfig, ITerminalLaunchError, ITerminalProcessOptions, ITerminalProfile, ITerminalsLayoutInfo, ProcessPropertyType, TerminalIcon, TerminalIpcChannels, TerminalSettingId, TitleEventSource } from 'vs/platform/terminal/common/terminal';
1717
import { registerTerminalPlatformConfiguration } from 'vs/platform/terminal/common/terminalPlatformConfiguration';
1818
import { IGetTerminalLayoutInfoArgs, IProcessDetails, ISetTerminalLayoutInfoArgs } from 'vs/platform/terminal/common/terminalProcess';
1919
import { IPtyHostConnection, IPtyHostStarter } from 'vs/platform/terminal/node/ptyHost';
2020
import { detectAvailableProfiles } from 'vs/platform/terminal/node/terminalProfiles';
2121
import * as performance from 'vs/base/common/performance';
2222
import { getSystemShell } from 'vs/base/node/shell';
23+
import { StopWatch } from 'vs/base/common/stopwatch';
2324

2425
enum Constants {
2526
MaxRestarts = 5
@@ -272,8 +273,17 @@ export class PtyHostService extends Disposable implements IPtyHostService {
272273
getCwd(id: number): Promise<string> {
273274
return this._proxy.getCwd(id);
274275
}
275-
getLatency(id: number): Promise<number> {
276-
return this._proxy.getLatency(id);
276+
async getLatency(): Promise<IPtyHostLatencyMeasurement[]> {
277+
const sw = new StopWatch();
278+
const results = await this._proxy.getLatency();
279+
sw.stop();
280+
return [
281+
{
282+
label: 'ptyhostservice<->ptyhost',
283+
latency: sw.elapsed()
284+
},
285+
...results
286+
];
277287
}
278288
orphanQuestionReply(id: number): Promise<void> {
279289
return this._proxy.orphanQuestionReply(id);

src/vs/platform/terminal/node/ptyService.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { URI } from 'vs/base/common/uri';
1212
import { getSystemShell } from 'vs/base/node/shell';
1313
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
1414
import { RequestStore } from 'vs/platform/terminal/common/requestStore';
15-
import { IProcessDataEvent, IProcessReadyEvent, IPtyService, IRawTerminalInstanceLayoutInfo, IReconnectConstants, IShellLaunchConfig, ITerminalInstanceLayoutInfoById, ITerminalLaunchError, ITerminalsLayoutInfo, ITerminalTabLayoutInfoById, TerminalIcon, IProcessProperty, TitleEventSource, ProcessPropertyType, IProcessPropertyMap, IFixedTerminalDimensions, IPersistentTerminalProcessLaunchConfig, ICrossVersionSerializedTerminalState, ISerializedTerminalState, ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal';
15+
import { IProcessDataEvent, IProcessReadyEvent, IPtyService, IRawTerminalInstanceLayoutInfo, IReconnectConstants, IShellLaunchConfig, ITerminalInstanceLayoutInfoById, ITerminalLaunchError, ITerminalsLayoutInfo, ITerminalTabLayoutInfoById, TerminalIcon, IProcessProperty, TitleEventSource, ProcessPropertyType, IProcessPropertyMap, IFixedTerminalDimensions, IPersistentTerminalProcessLaunchConfig, ICrossVersionSerializedTerminalState, ISerializedTerminalState, ITerminalProcessOptions, IPtyHostLatencyMeasurement } from 'vs/platform/terminal/common/terminal';
1616
import { TerminalDataBufferer } from 'vs/platform/terminal/common/terminalDataBuffering';
1717
import { escapeNonWindowsPath } from 'vs/platform/terminal/common/terminalEnvironment';
1818
import { Terminal as XtermTerminal } from 'xterm-headless';
@@ -399,8 +399,8 @@ export class PtyService extends Disposable implements IPtyService {
399399
return this._throwIfNoPty(id).setUnicodeVersion(version);
400400
}
401401
@traceRpc
402-
async getLatency(id: number): Promise<number> {
403-
return 0;
402+
async getLatency(): Promise<IPtyHostLatencyMeasurement[]> {
403+
return [];
404404
}
405405
@traceRpc
406406
async orphanQuestionReply(id: number): Promise<void> {
@@ -874,9 +874,6 @@ class PersistentTerminalProcess extends Disposable {
874874
getCwd(): Promise<string> {
875875
return this._terminalProcess.getCwd();
876876
}
877-
getLatency(): Promise<number> {
878-
return this._terminalProcess.getLatency();
879-
}
880877

881878
async triggerReplay(): Promise<void> {
882879
if (this._interactionState.value === InteractionState.None) {

src/vs/platform/terminal/node/terminalProcess.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,6 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess
627627
return this._initialCwd;
628628
}
629629

630-
getLatency(): Promise<number> {
631-
return Promise.resolve(0);
632-
}
633-
634630
getWindowsPty(): IProcessReadyWindowsPty | undefined {
635631
return isWindows ? {
636632
backend: 'useConpty' in this._ptyOptions && this._ptyOptions.useConpty ? 'conpty' : 'winpty',

src/vs/server/node/remoteTerminalChannel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
117117
case RemoteTerminalChannelRequest.DetachFromProcess: return this._ptyHostService.detachFromProcess.apply(this._ptyHostService, args);
118118

119119
case RemoteTerminalChannelRequest.ListProcesses: return this._ptyHostService.listProcesses.apply(this._ptyHostService, args);
120+
case RemoteTerminalChannelRequest.GetLatency: return this._ptyHostService.getLatency.apply(this._ptyHostService, args);
120121
case RemoteTerminalChannelRequest.GetPerformanceMarks: return this._ptyHostService.getPerformanceMarks.apply(this._ptyHostService, args);
121122
case RemoteTerminalChannelRequest.OrphanQuestionReply: return this._ptyHostService.orphanQuestionReply.apply(this._ptyHostService, args);
122123
case RemoteTerminalChannelRequest.AcceptPtyHostResolvedVariables: return this._ptyHostService.acceptPtyHostResolvedVariables.apply(this._ptyHostService, args);

src/vs/workbench/api/browser/mainThreadTerminalService.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { DisposableStore, Disposable, IDisposable, MutableDisposable } from 'vs/
77
import { ExtHostContext, ExtHostTerminalServiceShape, MainThreadTerminalServiceShape, MainContext, TerminalLaunchConfig, ITerminalDimensionsDto, ExtHostTerminalIdentifier, TerminalQuickFix } from 'vs/workbench/api/common/extHost.protocol';
88
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
99
import { URI } from 'vs/base/common/uri';
10-
import { StopWatch } from 'vs/base/common/stopwatch';
1110
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1211
import { ILogService } from 'vs/platform/log/common/log';
1312
import { IProcessProperty, IProcessReadyWindowsPty, IShellLaunchConfig, IShellLaunchConfigDto, ITerminalOutputMatch, ITerminalOutputMatcher, ProcessPropertyType, TerminalExitReason, TerminalLocation } from 'vs/platform/terminal/common/terminal';
@@ -368,7 +367,6 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
368367
proxy.onShutdown(immediate => this._proxy.$acceptProcessShutdown(proxy.instanceId, immediate));
369368
proxy.onRequestCwd(() => this._proxy.$acceptProcessRequestCwd(proxy.instanceId));
370369
proxy.onRequestInitialCwd(() => this._proxy.$acceptProcessRequestInitialCwd(proxy.instanceId));
371-
proxy.onRequestLatency(() => this._onRequestLatency(proxy.instanceId));
372370
}
373371

374372
public $sendProcessData(terminalId: number, data: string): void {
@@ -387,27 +385,6 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
387385
this._terminalProcessProxies.get(terminalId)?.emitProcessProperty(property);
388386
}
389387

390-
private async _onRequestLatency(terminalId: number): Promise<void> {
391-
const COUNT = 2;
392-
let sum = 0;
393-
for (let i = 0; i < COUNT; i++) {
394-
const sw = StopWatch.create();
395-
await this._proxy.$acceptProcessRequestLatency(terminalId);
396-
sw.stop();
397-
sum += sw.elapsed();
398-
}
399-
this._getTerminalProcess(terminalId)?.emitLatency(sum / COUNT);
400-
}
401-
402-
private _getTerminalProcess(terminalId: number): ITerminalProcessExtHostProxy | undefined {
403-
const terminal = this._terminalProcessProxies.get(terminalId);
404-
if (!terminal) {
405-
this._logService.error(`Unknown terminal: ${terminalId}`);
406-
return undefined;
407-
}
408-
return terminal;
409-
}
410-
411388
$setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: ISerializableEnvironmentVariableCollection | undefined, descriptionMap: ISerializableEnvironmentDescriptionMap): void {
412389
if (collection) {
413390
const translatedCollection = {

src/vs/workbench/api/common/extHostTerminalService.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,6 @@ class ExtHostPseudoterminal implements ITerminalChildProcess {
313313
return Promise.resolve('');
314314
}
315315

316-
getLatency(): Promise<number> {
317-
return Promise.resolve(0);
318-
}
319-
320316
startSendingEvents(initialDimensions: ITerminalDimensionsDto | undefined): void {
321317
// Attach the listeners
322318
this._pty.onDidWrite(e => this._onProcessData.fire(e));

src/vs/workbench/contrib/terminal/browser/remotePty.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,4 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
209209
handleOrphanQuestion() {
210210
this._remoteTerminalChannel.orphanQuestionReply(this.id);
211211
}
212-
213-
async getLatency(): Promise<number> {
214-
return 0;
215-
}
216212
}

src/vs/workbench/contrib/terminal/browser/remoteTerminalBackend.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import { Emitter } from 'vs/base/common/event';
88
import { revive } from 'vs/base/common/marshalling';
99
import { PerformanceMark, mark } from 'vs/base/common/performance';
1010
import { IProcessEnvironment, OperatingSystem } from 'vs/base/common/platform';
11+
import { StopWatch } from 'vs/base/common/stopwatch';
1112
import { ICommandService } from 'vs/platform/commands/common/commands';
1213
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1314
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1415
import { Registry } from 'vs/platform/registry/common/platform';
1516
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
1617
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
1718
import { ISerializedTerminalCommand } from 'vs/platform/terminal/common/capabilities/capabilities';
18-
import { IShellLaunchConfig, IShellLaunchConfigDto, ITerminalBackend, ITerminalBackendRegistry, ITerminalChildProcess, ITerminalEnvironment, ITerminalLogService, ITerminalProcessOptions, ITerminalProfile, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, ProcessPropertyType, TerminalExtensions, TerminalIcon, TerminalSettingId, TitleEventSource } from 'vs/platform/terminal/common/terminal';
19+
import { IPtyHostLatencyMeasurement, IShellLaunchConfig, IShellLaunchConfigDto, ITerminalBackend, ITerminalBackendRegistry, ITerminalChildProcess, ITerminalEnvironment, ITerminalLogService, ITerminalProcessOptions, ITerminalProfile, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, ProcessPropertyType, TerminalExtensions, TerminalIcon, TerminalSettingId, TitleEventSource } from 'vs/platform/terminal/common/terminal';
1920
import { IProcessDetails } from 'vs/platform/terminal/common/terminalProcess';
2021
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
2122
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
@@ -260,6 +261,19 @@ class RemoteTerminalBackend extends BaseTerminalBackend implements ITerminalBack
260261
return this._remoteTerminalChannel.listProcesses();
261262
}
262263

264+
async getLatency(): Promise<IPtyHostLatencyMeasurement[]> {
265+
const sw = new StopWatch();
266+
const results = await this._remoteTerminalChannel.getLatency();
267+
sw.stop();
268+
return [
269+
{
270+
label: 'window<->ptyhostservice<->ptyhost',
271+
latency: sw.elapsed()
272+
},
273+
...results
274+
];
275+
}
276+
263277
async updateProperty<T extends ProcessPropertyType>(id: number, property: T, value: any): Promise<void> {
264278
await this._remoteTerminalChannel.updateProperty(id, property, value);
265279
}

src/vs/workbench/contrib/terminal/browser/terminalProcessExtHostProxy.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@ export class TerminalProcessExtHostProxy extends Disposable implements ITerminal
3434
readonly onRequestInitialCwd: Event<void> = this._onRequestInitialCwd.event;
3535
private readonly _onRequestCwd = this._register(new Emitter<void>());
3636
readonly onRequestCwd: Event<void> = this._onRequestCwd.event;
37-
private readonly _onRequestLatency = this._register(new Emitter<void>());
38-
readonly onRequestLatency: Event<void> = this._onRequestLatency.event;
3937
private readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty<any>>());
4038
readonly onDidChangeProperty = this._onDidChangeProperty.event;
4139
private readonly _onProcessExit = this._register(new Emitter<number | undefined>());
4240
readonly onProcessExit: Event<number | undefined> = this._onProcessExit.event;
4341

44-
4542
private _pendingInitialCwdRequests: ((value: string | PromiseLike<string>) => void)[] = [];
4643
private _pendingCwdRequests: ((value: string | PromiseLike<string>) => void)[] = [];
47-
private _pendingLatencyRequests: ((value: number | PromiseLike<number>) => void)[] = [];
4844

4945
constructor(
5046
public instanceId: number,
@@ -112,12 +108,6 @@ export class TerminalProcessExtHostProxy extends Disposable implements ITerminal
112108
}
113109
}
114110

115-
emitLatency(latency: number): void {
116-
while (this._pendingLatencyRequests.length > 0) {
117-
this._pendingLatencyRequests.pop()!(latency);
118-
}
119-
}
120-
121111
async start(): Promise<ITerminalLaunchError | undefined> {
122112
return this._terminalService.requestStartExtensionTerminal(this, this._cols, this._rows);
123113
}
@@ -165,13 +155,6 @@ export class TerminalProcessExtHostProxy extends Disposable implements ITerminal
165155
});
166156
}
167157

168-
getLatency(): Promise<number> {
169-
return new Promise<number>(resolve => {
170-
this._onRequestLatency.fire();
171-
this._pendingLatencyRequests.push(resolve);
172-
});
173-
}
174-
175158
async refreshProperty<T extends ProcessPropertyType>(type: T): Promise<any> {
176159
// throws if called in extHostTerminalService
177160
}

0 commit comments

Comments
 (0)