From 2ef3f7614aa29a8f76f5641e886ba959cd41893f Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 5 Feb 2018 13:12:41 +0100 Subject: [PATCH] add more log calls to some services (for #41680) --- .../electron-browser/broadcastService.ts | 10 +- .../electron-browser/lifecycleService.ts | 108 ++++++++++-------- .../lifecycle/electron-main/lifecycleMain.ts | 13 ++- src/vs/workbench/electron-browser/shell.ts | 2 +- 4 files changed, 83 insertions(+), 50 deletions(-) diff --git a/src/vs/platform/broadcast/electron-browser/broadcastService.ts b/src/vs/platform/broadcast/electron-browser/broadcastService.ts index 638a77284aa..09c7f4f8ed6 100644 --- a/src/vs/platform/broadcast/electron-browser/broadcastService.ts +++ b/src/vs/platform/broadcast/electron-browser/broadcastService.ts @@ -9,6 +9,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' import Event, { Emitter } from 'vs/base/common/event'; import { ipcRenderer as ipc } from 'electron'; +import { ILogService } from 'vs/platform/log/common/log'; export const IBroadcastService = createDecorator('broadcastService'); @@ -30,7 +31,10 @@ export class BroadcastService implements IBroadcastService { private _onBroadcast: Emitter; - constructor(private windowId: number) { + constructor( + private windowId: number, + @ILogService private logService: ILogService + ) { this._onBroadcast = new Emitter(); this.registerListeners(); @@ -38,6 +42,8 @@ export class BroadcastService implements IBroadcastService { private registerListeners(): void { ipc.on('vscode:broadcast', (event, b: IBroadcast) => { + this.logService.trace(`Received broadcast from main in window ${this.windowId}: `, b); + this._onBroadcast.fire(b); }); } @@ -47,6 +53,8 @@ export class BroadcastService implements IBroadcastService { } public broadcast(b: IBroadcast): void { + this.logService.trace(`Sending broadcast to main from window ${this.windowId}: `, b); + ipc.send('vscode:broadcast', this.windowId, { channel: b.channel, payload: b.payload diff --git a/src/vs/platform/lifecycle/electron-browser/lifecycleService.ts b/src/vs/platform/lifecycle/electron-browser/lifecycleService.ts index 61bf03a4aad..26d27676441 100644 --- a/src/vs/platform/lifecycle/electron-browser/lifecycleService.ts +++ b/src/vs/platform/lifecycle/electron-browser/lifecycleService.ts @@ -15,6 +15,7 @@ import Event, { Emitter } from 'vs/base/common/event'; import { IWindowService } from 'vs/platform/windows/common/windows'; import { mark } from 'vs/base/common/performance'; import { Barrier } from 'vs/base/common/async'; +import { ILogService } from 'vs/platform/log/common/log'; export class LifecycleService implements ILifecycleService { @@ -32,10 +33,9 @@ export class LifecycleService implements ILifecycleService { constructor( @IMessageService private _messageService: IMessageService, @IWindowService private _windowService: IWindowService, - @IStorageService private _storageService: IStorageService + @IStorageService private _storageService: IStorageService, + @ILogService private _logService: ILogService ) { - this._registerListeners(); - const lastShutdownReason = this._storageService.getInteger(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE); this._storageService.remove(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE); if (lastShutdownReason === ShutdownReason.RELOAD) { @@ -45,51 +45,10 @@ export class LifecycleService implements ILifecycleService { } else { this._startupKind = StartupKind.NewWindow; } - } - public get phase(): LifecyclePhase { - return this._phase; - } + this._logService.trace(`lifecycle: starting up (startup kind: ${this._startupKind})`); - public set phase(value: LifecyclePhase) { - if (value < this.phase) { - throw new Error('Lifecycle cannot go backwards'); - } - if (this._phase === value) { - return; - } - - this._phase = value; - mark(`LifecyclePhase/${LifecyclePhase[value]}`); - - if (this._phaseWhen.has(this._phase)) { - this._phaseWhen.get(this._phase).open(); - this._phaseWhen.delete(this._phase); - } - } - - public when(phase: LifecyclePhase): Thenable { - if (phase <= this._phase) { - return Promise.resolve(); - } - let barrier = this._phaseWhen.get(phase); - if (!barrier) { - barrier = new Barrier(); - this._phaseWhen.set(phase, barrier); - } - return barrier.wait(); - } - - public get startupKind(): StartupKind { - return this._startupKind; - } - - public get onWillShutdown(): Event { - return this._onWillShutdown.event; - } - - public get onShutdown(): Event { - return this._onShutdown.event; + this._registerListeners(); } private _registerListeners(): void { @@ -97,14 +56,19 @@ export class LifecycleService implements ILifecycleService { // Main side indicates that window is about to unload, check for vetos ipc.on('vscode:onBeforeUnload', (event, reply: { okChannel: string, cancelChannel: string, reason: ShutdownReason }) => { + this._logService.trace(`lifecycle: onBeforeUnload (reason: ${reply.reason})`); + + // store shutdown reason to retrieve next startup this._storageService.store(LifecycleService._lastShutdownReasonKey, JSON.stringify(reply.reason), StorageScope.WORKSPACE); // trigger onWillShutdown events and veto collecting this.onBeforeUnload(reply.reason).done(veto => { if (veto) { + this._logService.trace('lifecycle: onBeforeUnload prevented via veto'); this._storageService.remove(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE); ipc.send(reply.cancelChannel, windowId); } else { + this._logService.trace('lifecycle: onBeforeUnload continues without veto'); ipc.send(reply.okChannel, windowId); } }); @@ -112,6 +76,8 @@ export class LifecycleService implements ILifecycleService { // Main side indicates that we will indeed shutdown ipc.on('vscode:onWillUnload', (event, reply: { replyChannel: string, reason: ShutdownReason }) => { + this._logService.trace(`lifecycle: onWillUnload (reason: ${reply.reason})`); + this._onShutdown.fire(reply.reason); ipc.send(reply.replyChannel, windowId); }); @@ -129,4 +95,54 @@ export class LifecycleService implements ILifecycleService { return handleVetos(vetos, err => this._messageService.show(Severity.Error, toErrorMessage(err))); } + + public get phase(): LifecyclePhase { + return this._phase; + } + + public set phase(value: LifecyclePhase) { + if (value < this.phase) { + throw new Error('Lifecycle cannot go backwards'); + } + + if (this._phase === value) { + return; + } + + this._logService.trace(`lifecycle: phase changed (value: ${value})`); + + this._phase = value; + mark(`LifecyclePhase/${LifecyclePhase[value]}`); + + if (this._phaseWhen.has(this._phase)) { + this._phaseWhen.get(this._phase).open(); + this._phaseWhen.delete(this._phase); + } + } + + public when(phase: LifecyclePhase): Thenable { + if (phase <= this._phase) { + return Promise.resolve(); + } + + let barrier = this._phaseWhen.get(phase); + if (!barrier) { + barrier = new Barrier(); + this._phaseWhen.set(phase, barrier); + } + + return barrier.wait(); + } + + public get startupKind(): StartupKind { + return this._startupKind; + } + + public get onWillShutdown(): Event { + return this._onWillShutdown.event; + } + + public get onShutdown(): Event { + return this._onShutdown.event; + } } diff --git a/src/vs/platform/lifecycle/electron-main/lifecycleMain.ts b/src/vs/platform/lifecycle/electron-main/lifecycleMain.ts index 345cea01303..81b62cf1206 100644 --- a/src/vs/platform/lifecycle/electron-main/lifecycleMain.ts +++ b/src/vs/platform/lifecycle/electron-main/lifecycleMain.ts @@ -190,15 +190,20 @@ export class LifecycleService implements ILifecycleService { // first ask the window itself if it vetos the unload return this.onBeforeUnloadWindowInRenderer(window, windowUnloadReason).then(veto => { if (veto) { + this.logService.trace('Lifecycle#unload(): veto in renderer', window.id); + return this.handleVeto(veto); } // then check for vetos in the main side return this.onBeforeUnloadWindowInMain(window, windowUnloadReason).then(veto => { if (veto) { - return this.handleVeto(veto); - } + this.logService.trace('Lifecycle#unload(): veto in main', window.id); + return this.handleVeto(veto); + } else { + this.logService.trace('Lifecycle#unload(): unload continues without veto', window.id); + } // finally if there are no vetos, unload the renderer return this.onWillUnloadWindowInRenderer(window, windowUnloadReason).then(() => false); @@ -294,10 +299,14 @@ export class LifecycleService implements ILifecycleService { } public kill(code?: number): void { + this.logService.trace('Lifecycle#kill()'); + app.exit(code); } public relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): void { + this.logService.trace('Lifecycle#relaunch()'); + const args = process.argv.slice(1); if (options && options.addArgs) { args.push(...options.addArgs); diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index fe92aaa7044..b1bb403feb2 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -340,7 +340,7 @@ export class WorkbenchShell { const instantiationService: IInstantiationService = new InstantiationService(serviceCollection, true); - this.broadcastService = new BroadcastService(this.configuration.windowId); + this.broadcastService = instantiationService.createInstance(BroadcastService, this.configuration.windowId); serviceCollection.set(IBroadcastService, this.broadcastService); serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, this.configuration.windowId, this.configuration));