Prompt to create Profiler session per server (#2303)

* Null check getXEventSessions return value

* Profiler state WIP

* Fix various bugs getting session state
This commit is contained in:
Karl Burtram
2018-08-23 15:33:23 -04:00
committed by GitHub
parent befa34790f
commit 70d47c1757
3 changed files with 79 additions and 13 deletions

View File

@@ -17,7 +17,6 @@ import * as Actions from 'sql/parts/profiler/contrib/profilerActions';
import { CONTEXT_PROFILER_EDITOR, PROFILER_TABLE_COMMAND_SEARCH } from './interfaces'; import { CONTEXT_PROFILER_EDITOR, PROFILER_TABLE_COMMAND_SEARCH } from './interfaces';
import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox'; import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox';
import { textFormatter } from 'sql/parts/grid/services/sharedServices'; import { textFormatter } from 'sql/parts/grid/services/sharedServices';
import * as DOM from 'vs/base/browser/dom'; import * as DOM from 'vs/base/browser/dom';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
@@ -99,7 +98,8 @@ export interface IDetailData {
} }
export class ProfilerEditor extends BaseEditor { export class ProfilerEditor extends BaseEditor {
public static ID: string = 'workbench.editor.profiler'; public static readonly ID: string = 'workbench.editor.profiler';
private _editor: ProfilerResourceEditor; private _editor: ProfilerResourceEditor;
private _editorModel: ITextModel; private _editorModel: ITextModel;
private _editorInput: UntitledEditorInput; private _editorInput: UntitledEditorInput;
@@ -158,9 +158,6 @@ export class ProfilerEditor extends BaseEditor {
} }
protected createEditor(parent: HTMLElement): void { protected createEditor(parent: HTMLElement): void {
// test backend
//this._profilerService.registerProvider('default', this._instantiationService.createInstance(ProfilerTestBackend));
this._container = document.createElement('div'); this._container = document.createElement('div');
this._container.className = 'carbon-profiler'; this._container.className = 'carbon-profiler';
parent.appendChild(this._container); parent.appendChild(this._container);
@@ -457,13 +454,32 @@ export class ProfilerEditor extends BaseEditor {
this._connectAction.connected = this.input.state.isConnected; this._connectAction.connected = this.input.state.isConnected;
if (this.input.state.isConnected) { if (this.input.state.isConnected) {
this._updateToolbar(); this._updateToolbar();
this._sessionSelector.enable(); this._sessionSelector.enable();
this._profilerService.getXEventSessions(this.input.id).then((r) => { this._profilerService.getXEventSessions(this.input.id).then((r) => {
// set undefined result to empty list
if (!r) {
r = [];
}
this._sessionSelector.setOptions(r); this._sessionSelector.setOptions(r);
this._sessionsList = r; this._sessionsList = r;
if (this.input.sessionName === undefined || this.input.sessionName === '') { if ((this.input.sessionName === undefined || this.input.sessionName === '') && this._sessionsList.length > 0) {
this.input.sessionName = this._sessionsList[0]; let sessionIndex: number = 0;
let uiState = this._profilerService.getSessionViewState(this.input.id);
if (uiState && uiState.previousSessionName) {
sessionIndex = this._sessionsList.indexOf(uiState.previousSessionName);
} else {
this._profilerService.launchCreateSessionDialog(this.input);
}
if (sessionIndex < 0) {
sessionIndex = 0;
}
this.input.sessionName = this._sessionsList[sessionIndex];
this._sessionSelector.selectWithOptionName(this.input.sessionName);
} }
}); });
} else { } else {
@@ -493,9 +509,14 @@ export class ProfilerEditor extends BaseEditor {
this._updateToolbar(); this._updateToolbar();
this._sessionSelector.enable(); this._sessionSelector.enable();
this._profilerService.getXEventSessions(this.input.id).then((r) => { this._profilerService.getXEventSessions(this.input.id).then((r) => {
// set undefined result to empty list
if (!r) {
r = [];
}
this._sessionsList = r; this._sessionsList = r;
this._sessionSelector.setOptions(r); this._sessionSelector.setOptions(r);
if (this.input.sessionName === undefined || this.input.sessionName === '') { if ((this.input.sessionName === undefined || this.input.sessionName === '') && this._sessionsList.length > 0) {
this.input.sessionName = this._sessionsList[0]; this.input.sessionName = this._sessionsList[0];
} }
}); });

View File

@@ -109,6 +109,12 @@ export interface IProfilerService {
* otherwise returns all session templates * otherwise returns all session templates
*/ */
getSessionTemplates(providerId?: string): Array<IProfilerSessionTemplate>; getSessionTemplates(providerId?: string): Array<IProfilerSessionTemplate>;
/**
* Gets the session view state
* @param sessionId The session ID to get the view state for
* @returns Sessions view state
*/
getSessionViewState(sessionId: string): any;
/** /**
* Launches the dialog for editing the view columns of a profiler session template for the given input * Launches the dialog for editing the view columns of a profiler session template for the given input
* @param input input object that contains the necessary information which will be modified based on used input * @param input input object that contains the necessary information which will be modified based on used input

View File

@@ -19,6 +19,8 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { INotificationService } from 'vs/platform/notification/common/notification'; import { INotificationService } from 'vs/platform/notification/common/notification';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { Scope as MementoScope, Memento } from 'vs/workbench/common/memento';
class TwoWayMap<T, K> { class TwoWayMap<T, K> {
private forwardMap: Map<T, K>; private forwardMap: Map<T, K>;
@@ -45,19 +47,27 @@ class TwoWayMap<T, K> {
} }
export class ProfilerService implements IProfilerService { export class ProfilerService implements IProfilerService {
private static readonly PROFILER_SERVICE_UI_STATE_STORAGE_KEY = 'profileservice.uiState';
public _serviceBrand: any; public _serviceBrand: any;
private _providers = new Map<string, sqlops.ProfilerProvider>(); private _providers = new Map<string, sqlops.ProfilerProvider>();
private _idMap = new TwoWayMap<ProfilerSessionID, string>(); private _idMap = new TwoWayMap<ProfilerSessionID, string>();
private _sessionMap = new Map<ProfilerSessionID, IProfilerSession>(); private _sessionMap = new Map<ProfilerSessionID, IProfilerSession>();
private _connectionMap = new Map<ProfilerSessionID, IConnectionProfile>();
private _editColumnDialog: ProfilerColumnEditorDialog; private _editColumnDialog: ProfilerColumnEditorDialog;
private _memento: any;
private _context: Memento;
constructor( constructor(
@IConnectionManagementService private _connectionService: IConnectionManagementService, @IConnectionManagementService private _connectionService: IConnectionManagementService,
@IConfigurationService public _configurationService: IConfigurationService, @IConfigurationService public _configurationService: IConfigurationService,
@IInstantiationService private _instantiationService: IInstantiationService, @IInstantiationService private _instantiationService: IInstantiationService,
@INotificationService private _notificationService: INotificationService, @INotificationService private _notificationService: INotificationService,
@ICommandService private _commandService: ICommandService @ICommandService private _commandService: ICommandService,
) { } @IStorageService private _storageService: IStorageService
) {
this._context = new Memento('ProfilerEditor');
this._memento = this._context.getMemento(this._storageService, MementoScope.GLOBAL);
}
public registerProvider(providerId: string, provider: sqlops.ProfilerProvider): void { public registerProvider(providerId: string, provider: sqlops.ProfilerProvider): void {
this._providers.set(providerId, provider); this._providers.set(providerId, provider);
@@ -77,23 +87,22 @@ export class ProfilerService implements IProfilerService {
} }
this._sessionMap.set(uri, session); this._sessionMap.set(uri, session);
this._connectionMap.set(uri, connectionProfile);
this._idMap.set(uri, uri); this._idMap.set(uri, uri);
return TPromise.wrap(uri); return TPromise.wrap(uri);
} }
public onMoreRows(params: sqlops.ProfilerSessionEvents): void { public onMoreRows(params: sqlops.ProfilerSessionEvents): void {
this._sessionMap.get(this._idMap.reverseGet(params.sessionId)).onMoreRows(params); this._sessionMap.get(this._idMap.reverseGet(params.sessionId)).onMoreRows(params);
} }
public onSessionStopped(params: sqlops.ProfilerSessionStoppedParams): void { public onSessionStopped(params: sqlops.ProfilerSessionStoppedParams): void {
this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)).onSessionStopped(params); this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)).onSessionStopped(params);
} }
public onProfilerSessionCreated(params: sqlops.ProfilerSessionCreatedParams): void { public onProfilerSessionCreated(params: sqlops.ProfilerSessionCreatedParams): void {
this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)).onProfilerSessionCreated(params); this._sessionMap.get(this._idMap.reverseGet(params.ownerUri)).onProfilerSessionCreated(params);
this.updateMemento(params.ownerUri, { previousSessionName: params.sessionName });
} }
public connectSession(id: ProfilerSessionID): Thenable<boolean> { public connectSession(id: ProfilerSessionID): Thenable<boolean> {
@@ -114,6 +123,7 @@ export class ProfilerService implements IProfilerService {
} }
public startSession(id: ProfilerSessionID, sessionName: string): Thenable<boolean> { public startSession(id: ProfilerSessionID, sessionName: string): Thenable<boolean> {
this.updateMemento(id, { previousSessionName: sessionName });
return this._runAction(id, provider => provider.startSession(this._idMap.get(id), sessionName)).then(() => { return this._runAction(id, provider => provider.startSession(this._idMap.get(id), sessionName)).then(() => {
this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false }); this._sessionMap.get(this._idMap.reverseGet(id)).onSessionStateChanged({ isRunning: true, isStopped: false, isPaused: false });
return true; return true;
@@ -178,6 +188,35 @@ export class ProfilerService implements IProfilerService {
} }
} }
public getSessionViewState(ownerUri: string): any {
let mementoKey = this.getMementoKey(ownerUri);
let uiStateMap = this._memento[ProfilerService.PROFILER_SERVICE_UI_STATE_STORAGE_KEY];
if (uiStateMap && mementoKey) {
return uiStateMap[mementoKey];
}
return undefined;
}
private getMementoKey(ownerUri: string): string {
let mementoKey = undefined;
let connectionProfile: IConnectionProfile = this._connectionMap.get(ownerUri);
if (connectionProfile) {
mementoKey = connectionProfile.serverName;
}
return mementoKey;
}
private updateMemento(ownerUri: string, uiState: any) {
// update persisted session state
let mementoKey = this.getMementoKey(ownerUri);
let uiStateMap = this._memento[ProfilerService.PROFILER_SERVICE_UI_STATE_STORAGE_KEY];
if (uiStateMap && mementoKey) {
uiStateMap[mementoKey] = uiState;
this._memento[ProfilerService.PROFILER_SERVICE_UI_STATE_STORAGE_KEY] = uiStateMap;
this._context.saveMemento();
}
}
public launchColumnEditor(input?: ProfilerInput): Thenable<void> { public launchColumnEditor(input?: ProfilerInput): Thenable<void> {
if (!this._editColumnDialog) { if (!this._editColumnDialog) {
this._editColumnDialog = this._instantiationService.createInstance(ProfilerColumnEditorDialog); this._editColumnDialog = this._instantiationService.createInstance(ProfilerColumnEditorDialog);