提交 8708c716 编写于 作者: J Johannes Rieken

fix #42144

上级 be07c3cc
...@@ -48,6 +48,10 @@ class MockExtensionService implements IExtensionService { ...@@ -48,6 +48,10 @@ class MockExtensionService implements IExtensionService {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }
public canProfileExtensionHost() {
return false;
}
public startExtensionHostProfile(): TPromise<ProfileSession> { public startExtensionHostProfile(): TPromise<ProfileSession> {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }
......
...@@ -40,6 +40,9 @@ class SimpleExtensionService implements IExtensionService { ...@@ -40,6 +40,9 @@ class SimpleExtensionService implements IExtensionService {
getExtensions(): TPromise<IExtensionDescription[]> { getExtensions(): TPromise<IExtensionDescription[]> {
return TPromise.wrap([]); return TPromise.wrap([]);
} }
canProfileExtensionHost() {
return false;
}
startExtensionHostProfile(): TPromise<ProfileSession> { startExtensionHostProfile(): TPromise<ProfileSession> {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }
......
...@@ -168,6 +168,11 @@ export interface IExtensionService { ...@@ -168,6 +168,11 @@ export interface IExtensionService {
*/ */
getExtensionsStatus(): { [id: string]: IExtensionsStatus }; getExtensionsStatus(): { [id: string]: IExtensionsStatus };
/**
* Check if the extension host can be profiled.
*/
canProfileExtensionHost(): boolean;
/** /**
* Begin an extension host process profile session. * Begin an extension host process profile session.
*/ */
......
...@@ -16,6 +16,7 @@ import { StatusbarAlignment, IStatusbarRegistry, StatusbarItemDescriptor, Extens ...@@ -16,6 +16,7 @@ import { StatusbarAlignment, IStatusbarRegistry, StatusbarItemDescriptor, Extens
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { IExtensionHostProfileService, ProfileSessionState, RuntimeExtensionsInput } from 'vs/workbench/parts/extensions/electron-browser/runtimeExtensionsEditor'; import { IExtensionHostProfileService, ProfileSessionState, RuntimeExtensionsInput } from 'vs/workbench/parts/extensions/electron-browser/runtimeExtensionsEditor';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
export class ExtensionHostProfileService extends Disposable implements IExtensionHostProfileService { export class ExtensionHostProfileService extends Disposable implements IExtensionHostProfileService {
...@@ -38,6 +39,7 @@ export class ExtensionHostProfileService extends Disposable implements IExtensio ...@@ -38,6 +39,7 @@ export class ExtensionHostProfileService extends Disposable implements IExtensio
@IExtensionService private readonly _extensionService: IExtensionService, @IExtensionService private readonly _extensionService: IExtensionService,
@IWorkbenchEditorService private readonly _editorService: IWorkbenchEditorService, @IWorkbenchEditorService private readonly _editorService: IWorkbenchEditorService,
@IInstantiationService private readonly _instantiationService: IInstantiationService, @IInstantiationService private readonly _instantiationService: IInstantiationService,
@IMessageService private readonly _messageService: IMessageService
) { ) {
super(); super();
this._profile = null; this._profile = null;
...@@ -67,6 +69,12 @@ export class ExtensionHostProfileService extends Disposable implements IExtensio ...@@ -67,6 +69,12 @@ export class ExtensionHostProfileService extends Disposable implements IExtensio
if (this._state !== ProfileSessionState.None) { if (this._state !== ProfileSessionState.None) {
return; return;
} }
if (!this._extensionService.canProfileExtensionHost()) {
this._messageService.show(Severity.Info, nls.localize('noPro', "To profile extensions, launch with `--inspect-extensions=<port>`."));
return;
}
this._setState(ProfileSessionState.Starting); this._setState(ProfileSessionState.Starting);
this._extensionService.startExtensionHostProfile().then((value) => { this._extensionService.startExtensionHostProfile().then((value) => {
......
...@@ -276,6 +276,8 @@ export class ExtensionHostProcessWorker { ...@@ -276,6 +276,8 @@ export class ExtensionHostProcessWorker {
let startPort = 9333; let startPort = 9333;
if (typeof this._environmentService.debugExtensionHost.port === 'number') { if (typeof this._environmentService.debugExtensionHost.port === 'number') {
startPort = expected = this._environmentService.debugExtensionHost.port; startPort = expected = this._environmentService.debugExtensionHost.port;
} else {
return TPromise.as({ expected: undefined, actual: 0 });
} }
return new TPromise((c, e) => { return new TPromise((c, e) => {
return findFreePort(startPort, 10 /* try 10 ports */, 5000 /* try up to 5 seconds */).then(port => { return findFreePort(startPort, 10 /* try 10 ports */, 5000 /* try up to 5 seconds */).then(port => {
......
...@@ -7,15 +7,8 @@ ...@@ -7,15 +7,8 @@
import { IExtensionService, IExtensionDescription, ProfileSession, IExtensionHostProfile, ProfileSegmentId } from 'vs/platform/extensions/common/extensions'; import { IExtensionService, IExtensionDescription, ProfileSession, IExtensionHostProfile, ProfileSegmentId } from 'vs/platform/extensions/common/extensions';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { localize } from 'vs/nls';
import { TernarySearchTree } from 'vs/base/common/map'; import { TernarySearchTree } from 'vs/base/common/map';
import { realpathSync } from 'vs/base/node/extfs'; import { realpathSync } from 'vs/base/node/extfs';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IStatusbarService, StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { writeFile } from 'vs/base/node/pfs';
import * as path from 'path';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { setTimeout } from 'timers';
import { Profile, ProfileNode } from 'v8-inspect-profiler'; import { Profile, ProfileNode } from 'v8-inspect-profiler';
export class ExtensionHostProfiler { export class ExtensionHostProfiler {
...@@ -128,27 +121,3 @@ export class ExtensionHostProfiler { ...@@ -128,27 +121,3 @@ export class ExtensionHostProfiler {
}; };
} }
} }
CommandsRegistry.registerCommand('exthost.profile.start', async accessor => {
const statusbarService = accessor.get(IStatusbarService);
const extensionService = accessor.get(IExtensionService);
const environmentService = accessor.get(IEnvironmentService);
const handle = statusbarService.addEntry({ text: localize('message', "$(zap) Profiling Extension Host...") }, StatusbarAlignment.LEFT);
extensionService.startExtensionHostProfile().then(session => {
setTimeout(() => {
session.stop().then(result => {
result.getAggregatedTimes().forEach((val, index) => {
console.log(`${index} : ${Math.round(val / 1000)} ms`);
});
let profilePath = path.join(environmentService.userHome, 'extHostProfile.cpuprofile');
console.log(`Saving profile at ${profilePath}`);
return writeFile(profilePath, JSON.stringify(result.data));
}).then(() => {
handle.dispose();
});
}, 5000);
});
});
...@@ -370,6 +370,10 @@ export class ExtensionService extends Disposable implements IExtensionService { ...@@ -370,6 +370,10 @@ export class ExtensionService extends Disposable implements IExtensionService {
return result; return result;
} }
public canProfileExtensionHost(): boolean {
return this._extensionHostProcessWorker && Boolean(this._extensionHostProcessWorker.getInspectPort());
}
public startExtensionHostProfile(): TPromise<ProfileSession> { public startExtensionHostProfile(): TPromise<ProfileSession> {
if (this._extensionHostProcessWorker) { if (this._extensionHostProcessWorker) {
let port = this._extensionHostProcessWorker.getInspectPort(); let port = this._extensionHostProcessWorker.getInspectPort();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册