diff --git a/extensions/profiler/package.json b/extensions/profiler/package.json index bbd9563491..068c12cc7b 100644 --- a/extensions/profiler/package.json +++ b/extensions/profiler/package.json @@ -32,6 +32,16 @@ "command": "profiler.newProfiler", "title": "New Profiler", "category": "Profiler" + }, + { + "command": "profiler.start", + "title": "Start", + "category": "Profiler" + }, + { + "command": "profiler.stop", + "title": "Stop", + "category": "Profiler" } ], "outputChannels": [ diff --git a/src/sql/parts/profiler/contrib/profilerActions.contribution.ts b/src/sql/parts/profiler/contrib/profilerActions.contribution.ts index be617d3b9a..2e7ce2a69c 100644 --- a/src/sql/parts/profiler/contrib/profilerActions.contribution.ts +++ b/src/sql/parts/profiler/contrib/profilerActions.contribution.ts @@ -23,6 +23,10 @@ import { IObjectExplorerService } from '../../objectExplorer/common/objectExplor import { ProfilerInput } from 'sql/parts/profiler/editor/profilerInput'; import { TPromise } from 'vs/base/common/winjs.base'; import * as TaskUtilities from 'sql/workbench/common/taskUtilities'; +import { IProfilerService} from '../service/interfaces'; +import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { KeyCode, KeyMod } from 'vs/editor/editor.api'; +import { ProfilerEditor } from '../editor/profilerEditor'; // Contribute Global Actions const category = nls.localize('profilerCategory', "Profiler"); @@ -46,3 +50,42 @@ CommandsRegistry.registerCommand({ return editorService.openEditor(profilerInput, { pinned: true }, false).then(() => TPromise.as(true)); } }); + +KeybindingsRegistry.registerCommandAndKeybindingRule({ + id: 'profiler.newProfiler', + weight: KeybindingsRegistry.WEIGHT.builtinExtension(), + when: undefined, + primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_P, + mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_P }, + handler: CommandsRegistry.getCommand('profiler.newProfiler').handler +}); + +CommandsRegistry.registerCommand({ + id: 'profiler.start', + handler: (accessor: ServicesAccessor) => { + let profilerService: IProfilerService = accessor.get(IProfilerService); + let editorService: IWorkbenchEditorService = accessor.get(IWorkbenchEditorService); + + let activeEditor = editorService.getActiveEditor(); + if (activeEditor instanceof ProfilerEditor) { + let profilerInput = activeEditor.input; + return profilerService.startSession(profilerInput.id); + } + return TPromise.as(false); + } +}); + +CommandsRegistry.registerCommand({ + id: 'profiler.stop', + handler: (accessor: ServicesAccessor) => { + let profilerService: IProfilerService = accessor.get(IProfilerService); + let editorService: IWorkbenchEditorService = accessor.get(IWorkbenchEditorService); + + let activeEditor = editorService.getActiveEditor(); + if (activeEditor instanceof ProfilerEditor) { + let profilerInput = activeEditor.input; + return profilerService.stopSession(profilerInput.id); + } + return TPromise.as(false); + } +}); \ No newline at end of file diff --git a/src/sql/parts/profiler/contrib/profilerActions.ts b/src/sql/parts/profiler/contrib/profilerActions.ts index 406e867470..8fefb22408 100644 --- a/src/sql/parts/profiler/contrib/profilerActions.ts +++ b/src/sql/parts/profiler/contrib/profilerActions.ts @@ -79,10 +79,7 @@ export class ProfilerStart extends Action { public run(input: ProfilerInput): TPromise { this.enabled = false; input.data.clear(); - return TPromise.wrap(this._profilerService.startSession(input.id).then(() => { - input.state.change({ isRunning: true, isStopped: false, isPaused: false }); - return true; - })); + return TPromise.wrap(this._profilerService.startSession(input.id)); } } @@ -131,10 +128,7 @@ export class ProfilerStop extends Action { public run(input: ProfilerInput): TPromise { this.enabled = false; - return TPromise.wrap(this._profilerService.stopSession(input.id).then(() => { - input.state.change({ isStopped: true, isPaused: false, isRunning: false }); - return true; - })); + return TPromise.wrap(this._profilerService.stopSession(input.id)); } } diff --git a/src/sql/parts/profiler/editor/profilerInput.ts b/src/sql/parts/profiler/editor/profilerInput.ts index e9fac4bb5f..c8fc4e2513 100644 --- a/src/sql/parts/profiler/editor/profilerInput.ts +++ b/src/sql/parts/profiler/editor/profilerInput.ts @@ -135,6 +135,10 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { }); } + public onSessionStateChanged(state: ProfilerState) { + this.state.change(state); + } + public onMoreRows(eventMessage: sqlops.ProfilerSessionEvents) { if (eventMessage.eventsLost){ this._notificationService.warn(nls.localize("profiler.eventsLost", "The XEvent Profiler session for {0} has lost events.", this._connection.serverName)); diff --git a/src/sql/parts/profiler/service/interfaces.ts b/src/sql/parts/profiler/service/interfaces.ts index 3a3480d9e3..a4249ac6e8 100644 --- a/src/sql/parts/profiler/service/interfaces.ts +++ b/src/sql/parts/profiler/service/interfaces.ts @@ -8,6 +8,7 @@ import { ProfilerInput } from 'sql/parts/profiler/editor/profilerInput'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import * as sqlops from 'sqlops'; +import { INewProfilerState } from '../editor/profilerState'; const PROFILER_SERVICE_ID = 'profilerService'; export const IProfilerService = createDecorator(PROFILER_SERVICE_ID); @@ -29,6 +30,10 @@ export interface IProfilerSession { * Called by the service when the session is closed unexpectedly */ onSessionStopped(events: sqlops.ProfilerSessionStoppedParams); + /** + * Called by the service when the session state is changed + */ + onSessionStateChanged(newState: INewProfilerState); } /** diff --git a/src/sql/parts/profiler/service/profilerService.ts b/src/sql/parts/profiler/service/profilerService.ts index 01b9a99f70..dd69f3f23b 100644 --- a/src/sql/parts/profiler/service/profilerService.ts +++ b/src/sql/parts/profiler/service/profilerService.ts @@ -96,7 +96,10 @@ export class ProfilerService implements IProfilerService { } public startSession(id: ProfilerSessionID): Thenable { - return this._runAction(id, provider => provider.startSession(this._idMap.get(id))); + return this._runAction(id, provider => provider.startSession(this._idMap.get(id))).then(() => { + this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false }); + return true; + }); } public pauseSession(id: ProfilerSessionID): Thenable { @@ -104,7 +107,10 @@ export class ProfilerService implements IProfilerService { } public stopSession(id: ProfilerSessionID): Thenable { - return this._runAction(id, provider => provider.stopSession(this._idMap.get(id))); + return this._runAction(id, provider => provider.stopSession(this._idMap.get(id))).then(() => { + this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isStopped: true, isPaused: false, isRunning: false }); + return true; + }); } private _runAction(id: ProfilerSessionID, action: (handler: sqlops.ProfilerProvider) => Thenable): Thenable {