提交 904db5d8 编写于 作者: D Daniel Imms

Support measuring terminal proc latency

上级 1f4d9035
......@@ -8,6 +8,7 @@ import { ITerminalService, ITerminalInstance, IShellLaunchConfig, ITerminalProce
import { ExtHostContext, ExtHostTerminalServiceShape, MainThreadTerminalServiceShape, MainContext, IExtHostContext, ShellLaunchConfigDto } from 'vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { UriComponents, URI } from 'vs/base/common/uri';
import { StopWatch } from 'vs/base/common/stopwatch';
@extHostNamedCustomer(MainContext.MainThreadTerminalService)
export class MainThreadTerminalService implements MainThreadTerminalServiceShape {
......@@ -227,6 +228,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
request.proxy.onShutdown(immediate => this._proxy.$acceptProcessShutdown(request.proxy.terminalId, immediate));
request.proxy.onRequestCwd(() => this._proxy.$acceptProcessRequestCwd(request.proxy.terminalId));
request.proxy.onRequestInitialCwd(() => this._proxy.$acceptProcessRequestInitialCwd(request.proxy.terminalId));
request.proxy.onRequestLatency(() => this._onRequestLatency(request.proxy.terminalId));
}
public $sendProcessTitle(terminalId: number, title: string): void {
......@@ -253,4 +255,16 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
public $sendProcessCwd(terminalId: number, cwd: string): void {
this._terminalProcesses[terminalId].emitCwd(cwd);
}
private async _onRequestLatency(terminalId: number): Promise<void> {
const COUNT = 2;
let sum = 0;
for (let i = 0; i < COUNT; i++) {
const sw = StopWatch.create(true);
await this._proxy.$acceptProcessRequestLatency(terminalId);
sw.stop();
sum += sw.elapsed();
}
this._terminalProcesses[terminalId].emitLatency(sum / COUNT);
}
}
......@@ -1041,6 +1041,7 @@ export interface ExtHostTerminalServiceShape {
$acceptProcessShutdown(id: number, immediate: boolean): void;
$acceptProcessRequestInitialCwd(id: number): void;
$acceptProcessRequestCwd(id: number): void;
$acceptProcessRequestLatency(id: number): number;
}
export interface ExtHostSCMShape {
......
......@@ -529,6 +529,10 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
this._terminalProcesses[id].getCwd().then(cwd => this._proxy.$sendProcessCwd(id, cwd));
}
public $acceptProcessRequestLatency(id: number): number {
return id;
}
private _onProcessExit(id: number, exitCode: number): void {
// Remove listeners
this._terminalProcesses[id].dispose();
......
......@@ -27,6 +27,11 @@ import { IRemoteEnvironmentService } from 'vs/workbench/services/remote/common/r
/** The amount of time to consider terminal errors to be related to the launch */
const LAUNCHING_DURATION = 500;
/**
* The minimum amount of time between latency requests.
*/
const LATENCY_MEASURING_INTERVAL = 1000;
/**
* Holds all state related to the creation and management of terminal processes.
*
......@@ -46,6 +51,9 @@ export class TerminalProcessManager implements ITerminalProcessManager {
private _process: ITerminalChildProcess | null = null;
private _preLaunchInputQueue: string[] = [];
private _disposables: IDisposable[] = [];
private _latency: number = -1;
private _latencyRequest: Promise<number>;
private _latencyLastMeasured: number = 0;
private readonly _onProcessReady = new Emitter<void>();
public get onProcessReady(): Event<void> { return this._onProcessReady.event; }
......@@ -77,6 +85,7 @@ export class TerminalProcessManager implements ITerminalProcessManager {
c(undefined);
});
});
this.ptyProcessReady.then(async () => await this.getLatency());
}
public dispose(immediate: boolean = false): void {
......@@ -240,6 +249,18 @@ export class TerminalProcessManager implements ITerminalProcessManager {
return this._process.getCwd();
}
public async getLatency(): Promise<number> {
if (!this._process) {
return Promise.resolve(0);
}
if (this._latencyLastMeasured === 0 || this._latencyLastMeasured + LATENCY_MEASURING_INTERVAL < Date.now()) {
this._latencyRequest = this._process.getLatency();
this._latency = await this._latencyRequest;
this._latencyLastMeasured = Date.now();
}
return Promise.resolve(this._latency);
}
private _onExit(exitCode: number): void {
this._process = null;
......
......@@ -654,6 +654,7 @@ export interface ITerminalProcessManager extends IDisposable {
getInitialCwd(): Promise<string>;
getCwd(): Promise<string>;
getLatency(): Promise<number>;
}
export const enum ProcessState {
......@@ -685,12 +686,14 @@ export interface ITerminalProcessExtHostProxy extends IDisposable {
emitExit(exitCode: number): void;
emitInitialCwd(initialCwd: string): void;
emitCwd(cwd: string): void;
emitLatency(latency: number): void;
onInput: Event<string>;
onResize: Event<{ cols: number, rows: number }>;
onShutdown: Event<boolean>;
onRequestInitialCwd: Event<void>;
onRequestCwd: Event<void>;
onRequestLatency: Event<void>;
}
export interface ITerminalProcessExtHostRequest {
......@@ -733,4 +736,5 @@ export interface ITerminalChildProcess {
getInitialCwd(): Promise<string>;
getCwd(): Promise<string>;
getLatency(): Promise<number>;
}
\ No newline at end of file
......@@ -31,9 +31,12 @@ export class TerminalProcessExtHostProxy implements ITerminalChildProcess, ITerm
public get onRequestInitialCwd(): Event<void> { return this._onRequestInitialCwd.event; }
private readonly _onRequestCwd = new Emitter<void>();
public get onRequestCwd(): Event<void> { return this._onRequestCwd.event; }
private readonly _onRequestLatency = new Emitter<void>();
public get onRequestLatency(): Event<void> { return this._onRequestLatency.event; }
private _pendingInitialCwdRequests: ((value?: string | Thenable<string>) => void)[] = [];
private _pendingCwdRequests: ((value?: string | Thenable<string>) => void)[] = [];
private _pendingLatencyRequests: ((value?: number | Thenable<number>) => void)[] = [];
constructor(
public terminalId: number,
......@@ -86,6 +89,12 @@ export class TerminalProcessExtHostProxy implements ITerminalChildProcess, ITerm
}
}
public emitLatency(latency: number): void {
while (this._pendingLatencyRequests.length > 0) {
this._pendingLatencyRequests.pop()!(latency);
}
}
public shutdown(immediate: boolean): void {
this._onShutdown.fire(immediate);
}
......@@ -111,4 +120,11 @@ export class TerminalProcessExtHostProxy implements ITerminalChildProcess, ITerm
this._pendingCwdRequests.push(resolve);
});
}
public getLatency(): Promise<number> {
return new Promise<number>(resolve => {
this._onRequestLatency.fire();
this._pendingLatencyRequests.push(resolve);
});
}
}
\ No newline at end of file
......@@ -213,4 +213,8 @@ export class TerminalProcess implements ITerminalChildProcess, IDisposable {
resolve(this._initialCwd);
});
}
public getLatency(): Promise<number> {
return Promise.resolve(0);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册