mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Profiler Keybindings (#1801)
* Added default new profiler keybinding. Exposed profiler.start and profiler.stop so they can be used with keybindings * Changing where session state gets set * Cleaning up unnecessary code
This commit is contained in:
committed by
GitHub
parent
4f76f116ac
commit
1819036d7d
@@ -32,6 +32,16 @@
|
|||||||
"command": "profiler.newProfiler",
|
"command": "profiler.newProfiler",
|
||||||
"title": "New Profiler",
|
"title": "New Profiler",
|
||||||
"category": "Profiler"
|
"category": "Profiler"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "profiler.start",
|
||||||
|
"title": "Start",
|
||||||
|
"category": "Profiler"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "profiler.stop",
|
||||||
|
"title": "Stop",
|
||||||
|
"category": "Profiler"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"outputChannels": [
|
"outputChannels": [
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ import { IObjectExplorerService } from '../../objectExplorer/common/objectExplor
|
|||||||
import { ProfilerInput } from 'sql/parts/profiler/editor/profilerInput';
|
import { ProfilerInput } from 'sql/parts/profiler/editor/profilerInput';
|
||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
import * as TaskUtilities from 'sql/workbench/common/taskUtilities';
|
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
|
// Contribute Global Actions
|
||||||
const category = nls.localize('profilerCategory', "Profiler");
|
const category = nls.localize('profilerCategory', "Profiler");
|
||||||
@@ -46,3 +50,42 @@ CommandsRegistry.registerCommand({
|
|||||||
return editorService.openEditor(profilerInput, { pinned: true }, false).then(() => TPromise.as(true));
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -79,10 +79,7 @@ export class ProfilerStart extends Action {
|
|||||||
public run(input: ProfilerInput): TPromise<boolean> {
|
public run(input: ProfilerInput): TPromise<boolean> {
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
input.data.clear();
|
input.data.clear();
|
||||||
return TPromise.wrap(this._profilerService.startSession(input.id).then(() => {
|
return TPromise.wrap(this._profilerService.startSession(input.id));
|
||||||
input.state.change({ isRunning: true, isStopped: false, isPaused: false });
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,10 +128,7 @@ export class ProfilerStop extends Action {
|
|||||||
|
|
||||||
public run(input: ProfilerInput): TPromise<boolean> {
|
public run(input: ProfilerInput): TPromise<boolean> {
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
return TPromise.wrap(this._profilerService.stopSession(input.id).then(() => {
|
return TPromise.wrap(this._profilerService.stopSession(input.id));
|
||||||
input.state.change({ isStopped: true, isPaused: false, isRunning: false });
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,10 @@ export class ProfilerInput extends EditorInput implements IProfilerSession {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onSessionStateChanged(state: ProfilerState) {
|
||||||
|
this.state.change(state);
|
||||||
|
}
|
||||||
|
|
||||||
public onMoreRows(eventMessage: sqlops.ProfilerSessionEvents) {
|
public onMoreRows(eventMessage: sqlops.ProfilerSessionEvents) {
|
||||||
if (eventMessage.eventsLost){
|
if (eventMessage.eventsLost){
|
||||||
this._notificationService.warn(nls.localize("profiler.eventsLost", "The XEvent Profiler session for {0} has lost events.", this._connection.serverName));
|
this._notificationService.warn(nls.localize("profiler.eventsLost", "The XEvent Profiler session for {0} has lost events.", this._connection.serverName));
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ProfilerInput } from 'sql/parts/profiler/editor/profilerInput';
|
|||||||
|
|
||||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import * as sqlops from 'sqlops';
|
import * as sqlops from 'sqlops';
|
||||||
|
import { INewProfilerState } from '../editor/profilerState';
|
||||||
|
|
||||||
const PROFILER_SERVICE_ID = 'profilerService';
|
const PROFILER_SERVICE_ID = 'profilerService';
|
||||||
export const IProfilerService = createDecorator<IProfilerService>(PROFILER_SERVICE_ID);
|
export const IProfilerService = createDecorator<IProfilerService>(PROFILER_SERVICE_ID);
|
||||||
@@ -29,6 +30,10 @@ export interface IProfilerSession {
|
|||||||
* Called by the service when the session is closed unexpectedly
|
* Called by the service when the session is closed unexpectedly
|
||||||
*/
|
*/
|
||||||
onSessionStopped(events: sqlops.ProfilerSessionStoppedParams);
|
onSessionStopped(events: sqlops.ProfilerSessionStoppedParams);
|
||||||
|
/**
|
||||||
|
* Called by the service when the session state is changed
|
||||||
|
*/
|
||||||
|
onSessionStateChanged(newState: INewProfilerState);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -96,7 +96,10 @@ export class ProfilerService implements IProfilerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public startSession(id: ProfilerSessionID): Thenable<boolean> {
|
public startSession(id: ProfilerSessionID): Thenable<boolean> {
|
||||||
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<boolean> {
|
public pauseSession(id: ProfilerSessionID): Thenable<boolean> {
|
||||||
@@ -104,7 +107,10 @@ export class ProfilerService implements IProfilerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public stopSession(id: ProfilerSessionID): Thenable<boolean> {
|
public stopSession(id: ProfilerSessionID): Thenable<boolean> {
|
||||||
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<T>(id: ProfilerSessionID, action: (handler: sqlops.ProfilerProvider) => Thenable<T>): Thenable<T> {
|
private _runAction<T>(id: ProfilerSessionID, action: (handler: sqlops.ProfilerProvider) => Thenable<T>): Thenable<T> {
|
||||||
|
|||||||
Reference in New Issue
Block a user