提交 7c4205b5 编写于 作者: J Johannes Rieken

fix #42144

上级 554a9c6d
......@@ -48,6 +48,10 @@ class MockExtensionService implements IExtensionService {
throw new Error('Not implemented');
}
public canProfileExtensionHost() {
return false;
}
public startExtensionHostProfile(): TPromise<ProfileSession> {
throw new Error('Not implemented');
}
......
......@@ -43,6 +43,9 @@ class SimpleExtensionService implements IExtensionService {
getExtensions(): TPromise<IExtensionDescription[]> {
return TPromise.wrap([]);
}
canProfileExtensionHost() {
return false;
}
startExtensionHostProfile(): TPromise<ProfileSession> {
throw new Error('Not implemented');
}
......
......@@ -169,6 +169,11 @@ export interface IExtensionService {
*/
getExtensionsStatus(): { [id: string]: IExtensionsStatus };
/**
* Check if the extension host can be profiled.
*/
canProfileExtensionHost(): boolean;
/**
* Begin an extension host process profile session.
*/
......
......@@ -16,6 +16,7 @@ import { StatusbarAlignment, IStatusbarRegistry, StatusbarItemDescriptor, Extens
import { Registry } from 'vs/platform/registry/common/platform';
import { IExtensionHostProfileService, ProfileSessionState, RuntimeExtensionsInput } from 'vs/workbench/parts/extensions/electron-browser/runtimeExtensionsEditor';
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 {
......@@ -38,6 +39,7 @@ export class ExtensionHostProfileService extends Disposable implements IExtensio
@IExtensionService private readonly _extensionService: IExtensionService,
@IWorkbenchEditorService private readonly _editorService: IWorkbenchEditorService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IMessageService private readonly _messageService: IMessageService
) {
super();
this._profile = null;
......@@ -67,6 +69,12 @@ export class ExtensionHostProfileService extends Disposable implements IExtensio
if (this._state !== ProfileSessionState.None) {
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._extensionService.startExtensionHostProfile().then((value) => {
......
......@@ -275,6 +275,8 @@ export class ExtensionHostProcessWorker {
let startPort = 9333;
if (typeof this._environmentService.debugExtensionHost.port === 'number') {
startPort = expected = this._environmentService.debugExtensionHost.port;
} else {
return TPromise.as({ expected: undefined, actual: 0 });
}
return new TPromise((c, e) => {
return findFreePort(startPort, 10 /* try 10 ports */, 5000 /* try up to 5 seconds */).then(port => {
......
......@@ -7,15 +7,8 @@
import { IExtensionService, IExtensionDescription, ProfileSession, IExtensionHostProfile, ProfileSegmentId } from 'vs/platform/extensions/common/extensions';
import { TPromise } from 'vs/base/common/winjs.base';
import { localize } from 'vs/nls';
import { TernarySearchTree } from 'vs/base/common/map';
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';
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);
});
});
......@@ -337,6 +337,10 @@ export class ExtensionService extends Disposable implements IExtensionService {
return result;
}
public canProfileExtensionHost(): boolean {
return this._extensionHostProcessWorker && Boolean(this._extensionHostProcessWorker.getInspectPort());
}
public startExtensionHostProfile(): TPromise<ProfileSession> {
if (this._extensionHostProcessWorker) {
let port = this._extensionHostProcessWorker.getInspectPort();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册