Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pty host startup marks/traces, revive terminal procs in parallel #186041

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 34 additions & 29 deletions src/vs/platform/terminal/node/ptyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,36 +204,42 @@ export class PtyService extends Disposable implements IPtyService {

@traceRpc
async reviveTerminalProcesses(state: ISerializedTerminalState[], dateTimeFormatLocale: string) {
const promises: Promise<void>[] = [];
for (const terminal of state) {
const restoreMessage = localize('terminal-history-restored', "History restored");
// TODO: We may at some point want to show date information in a hover via a custom sequence:
// new Date(terminal.timestamp).toLocaleDateString(dateTimeFormatLocale)
// new Date(terminal.timestamp).toLocaleTimeString(dateTimeFormatLocale)
const newId = await this.createProcess(
{
...terminal.shellLaunchConfig,
cwd: terminal.processDetails.cwd,
color: terminal.processDetails.color,
icon: terminal.processDetails.icon,
name: terminal.processDetails.titleSource === TitleEventSource.Api ? terminal.processDetails.title : undefined,
initialText: terminal.replayEvent.events[0].data + formatMessageForTerminal(restoreMessage, { loudFormatting: true })
},
terminal.processDetails.cwd,
terminal.replayEvent.events[0].cols,
terminal.replayEvent.events[0].rows,
terminal.unicodeVersion,
terminal.processLaunchConfig.env,
terminal.processLaunchConfig.executableEnv,
terminal.processLaunchConfig.options,
true,
terminal.processDetails.workspaceId,
terminal.processDetails.workspaceName,
true,
terminal.replayEvent.events[0].data
);
// Don't start the process here as there's no terminal to answer CPR
this._revivedPtyIdMap.set(terminal.id, { newId, state: terminal });
promises.push(this._reviveTerminalProcess(terminal));
}
await Promise.all(promises);
}

private async _reviveTerminalProcess(terminal: ISerializedTerminalState): Promise<void> {
const restoreMessage = localize('terminal-history-restored', "History restored");
// TODO: We may at some point want to show date information in a hover via a custom sequence:
// new Date(terminal.timestamp).toLocaleDateString(dateTimeFormatLocale)
// new Date(terminal.timestamp).toLocaleTimeString(dateTimeFormatLocale)
const newId = await this.createProcess(
{
...terminal.shellLaunchConfig,
cwd: terminal.processDetails.cwd,
color: terminal.processDetails.color,
icon: terminal.processDetails.icon,
name: terminal.processDetails.titleSource === TitleEventSource.Api ? terminal.processDetails.title : undefined,
initialText: terminal.replayEvent.events[0].data + formatMessageForTerminal(restoreMessage, { loudFormatting: true })
},
terminal.processDetails.cwd,
terminal.replayEvent.events[0].cols,
terminal.replayEvent.events[0].rows,
terminal.unicodeVersion,
terminal.processLaunchConfig.env,
terminal.processLaunchConfig.executableEnv,
terminal.processLaunchConfig.options,
true,
terminal.processDetails.workspaceId,
terminal.processDetails.workspaceName,
true,
terminal.replayEvent.events[0].data
);
// Don't start the process here as there's no terminal to answer CPR
this._revivedPtyIdMap.set(terminal.id, { newId, state: terminal });
}

@traceRpc
Expand Down Expand Up @@ -506,7 +512,6 @@ export class PtyService extends Disposable implements IPtyService {
if (layout) {
const expandedTabs = await Promise.all(layout.tabs.map(async tab => this._expandTerminalTab(tab)));
const tabs = expandedTabs.filter(t => t.terminals.length > 0);
this._logService.trace('PtyService.getTerminalLayoutInfo result', tabs);
performance.mark('code/didGetTerminalLayoutInfo');
return { tabs };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
// The pty host should not get launched until the first window restored phase
await this._lifecycleService.when(LifecyclePhase.Restored);

mark('code/willConnectPtyHost');
mark('code/terminal/willConnectPtyHost');
this._logService.trace('Renderer->PtyHost#connect: before acquirePort');
acquirePort('vscode:createPtyHostMessageChannel', 'vscode:createPtyHostMessageChannelResult').then(port => {
mark('code/didConnectPtyHost');
mark('code/terminal/didConnectPtyHost');
this._logService.trace('Renderer->PtyHost#connect: connection established');
// There are two connections to the pty host; one to the regular shared process
// _localPtyService, and one directly via message port _ptyHostDirectProxy. The former is
Expand Down Expand Up @@ -279,18 +279,24 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke

// Re-resolve the environments and replace it on the state so local terminals use a fresh
// environment
mark('code/terminal/willGetReviveEnvironments');
for (const state of parsed) {
const freshEnv = await this._resolveEnvironmentForRevive(variableResolver, state.shellLaunchConfig);
state.processLaunchConfig.env = freshEnv;
}
mark('code/terminal/didGetReviveEnvironments');

mark('code/terminal/willReviveTerminalProcesses');
await this._localPtyService.reviveTerminalProcesses(parsed, Intl.DateTimeFormat().resolvedOptions().locale);
mark('code/terminal/didReviveTerminalProcesses');
this._storageService.remove(TerminalStorageKeys.TerminalBufferState, StorageScope.WORKSPACE);
// If reviving processes, send the terminal layout info back to the pty host as it
// will not have been persisted on application exit
const layoutInfo = this._storageService.get(TerminalStorageKeys.TerminalLayoutInfo, StorageScope.WORKSPACE);
if (layoutInfo) {
mark('code/terminal/willSetTerminalLayoutInfo');
await this._localPtyService.setTerminalLayoutInfo(JSON.parse(layoutInfo));
mark('code/terminal/didSetTerminalLayoutInfo');
this._storageService.remove(TerminalStorageKeys.TerminalLayoutInfo, StorageScope.WORKSPACE);
}
} catch {
Expand Down