Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jan 25, 2018
1 parent be07c3c commit 8708c71
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/vs/platform/actions/test/common/menuService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
3 changes: 3 additions & 0 deletions src/vs/platform/commands/test/commandService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class SimpleExtensionService implements IExtensionService {
getExtensions(): TPromise<IExtensionDescription[]> {
return TPromise.wrap([]);
}
canProfileExtensionHost() {
return false;
}
startExtensionHostProfile(): TPromise<ProfileSession> {
throw new Error('Not implemented');
}
Expand Down
5 changes: 5 additions & 0 deletions src/vs/platform/extensions/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,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();
Expand Down

0 comments on commit 8708c71

Please sign in to comment.