mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Server Reports extension: fix for start and stop xevent sessions (#13565)
* fix for start and stop xevent sessions * vscode.open for help URL * setup info messages for localization @kburtram - I could use an assist on updating the v# and publishing the vsix, but there's no rush this can wait until after the holidays
This commit is contained in:
committed by
GitHub
parent
ae6494f3e4
commit
1903388b6b
@@ -48,7 +48,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "tempdb.pauseEvent",
|
"command": "tempdb.pauseEvent",
|
||||||
"title": "Pause",
|
"title": "Toggle Auto Refresh",
|
||||||
"icon": {
|
"icon": {
|
||||||
"light": "./out/src/media/insights.svg",
|
"light": "./out/src/media/insights.svg",
|
||||||
"dark": "./out/src/media/insights_inverse.svg"
|
"dark": "./out/src/media/insights_inverse.svg"
|
||||||
@@ -387,7 +387,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"handlebars": "^4.5.3",
|
"handlebars": "^4.5.3",
|
||||||
"openurl": "^1.1.1"
|
"openurl": "^1.1.1",
|
||||||
|
"vscode-nls": "^5.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"azdata": "^1.0.0",
|
"azdata": "^1.0.0",
|
||||||
|
|||||||
@@ -4,6 +4,14 @@
|
|||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
import * as nls from 'vscode-nls';
|
||||||
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
|
// TempDB Messages
|
||||||
|
export const XEventsFailed = localize('XEventsFailed', 'XEvents operation failed.');
|
||||||
|
export const XEventsStarted = localize('XEventsStarted', 'XEvents sessions started for PageContention and ObjectContention.');
|
||||||
|
export const XEventsNotSupported = localize('XEventsNotSupported', 'XEvents sessions not supported.');
|
||||||
|
export const XEventsStopped = localize('XEventsStopped', 'XEvents sessions PageContention and ObjectContention removed.');
|
||||||
// CONFIG VALUES ///////////////////////////////////////////////////////////
|
// CONFIG VALUES ///////////////////////////////////////////////////////////
|
||||||
export const extensionConfigSectionName = 'server-reports';
|
export const extensionConfigSectionName = 'server-reports';
|
||||||
export const configLogDebugInfo = 'logDebugInfo';
|
export const configLogDebugInfo = 'logDebugInfo';
|
||||||
|
|||||||
@@ -8,16 +8,16 @@
|
|||||||
import * as azdata from 'azdata';
|
import * as azdata from 'azdata';
|
||||||
import * as Utils from '../utils';
|
import * as Utils from '../utils';
|
||||||
import ControllerBase from './controllerBase';
|
import ControllerBase from './controllerBase';
|
||||||
import * as fs from 'fs';
|
import { promises } from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as openurl from 'openurl';
|
import * as constants from '../constants';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main controller class that initializes the extension
|
* The main controller class that initializes the extension
|
||||||
*/
|
*/
|
||||||
export default class MainController extends ControllerBase {
|
export default class MainController extends ControllerBase {
|
||||||
|
private autoRefreshState: boolean = false;
|
||||||
|
|
||||||
public apiWrapper;
|
public apiWrapper;
|
||||||
// PUBLIC METHODS //////////////////////////////////////////////////////
|
// PUBLIC METHODS //////////////////////////////////////////////////////
|
||||||
@@ -38,26 +38,34 @@ export default class MainController extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private openurl(link: string): void {
|
private openurl(link: string): void {
|
||||||
openurl.open(link);
|
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(link));
|
||||||
}
|
}
|
||||||
|
|
||||||
private onExecute(connection: azdata.IConnectionProfile, fileName: string): void {
|
private async onExecute(connection: azdata.IConnectionProfile, fileName: string): Promise<void> {
|
||||||
// Command to start/stop autorefresh and run the query
|
// Command to start/stop autorefresh and run the query
|
||||||
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'type-of-contention', connection.id, true);
|
let connectionUri = await azdata.connection.getUriForConnection(connection.id);
|
||||||
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'metadata-contention', connection.id, true);
|
let connectionProvider = azdata.dataprotocol.getProvider<azdata.ConnectionProvider>(connection.providerName, azdata.DataProviderType.ConnectionProvider);
|
||||||
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'allocation-contention', connection.id, true);
|
connectionProvider.changeDatabase(connectionUri, 'tempdb');
|
||||||
let sqlContent = fs.readFileSync(path.join(__dirname, '..', 'sql', fileName)).toString();
|
let queryProvider = azdata.dataprotocol.getProvider<azdata.QueryProvider>(connection.providerName, azdata.DataProviderType.QueryProvider);
|
||||||
vscode.workspace.openTextDocument({ language: 'sql', content: sqlContent }).then(doc => {
|
let sqlContent: string = await promises.readFile(path.join(__dirname, '..', 'sql', fileName), {encoding: 'utf8'});
|
||||||
vscode.window.showTextDocument(doc, vscode.ViewColumn.Active, false).then(() => {
|
let seResult = await queryProvider.runQueryAndReturn(connectionUri, sqlContent);
|
||||||
let filePath = doc.uri.toString();
|
if (seResult.rowCount > 0 && seResult.rows[0][0].displayValue === '0') {
|
||||||
azdata.queryeditor.connect(filePath, connection.id).then(() => azdata.queryeditor.runQuery(filePath, undefined, false));
|
vscode.window.showInformationMessage( ( fileName === 'startEvent.sql' ) ? constants.XEventsStarted : constants.XEventsStopped );
|
||||||
});
|
this.autoRefreshState = ( fileName === 'startEvent.sql' ) ? true : false;
|
||||||
});
|
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'type-of-contention', connection.id, this.autoRefreshState);
|
||||||
|
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'metadata-contention', connection.id, this.autoRefreshState);
|
||||||
|
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'allocation-contention', connection.id, this.autoRefreshState);
|
||||||
|
} else if (seResult.rowCount > 0 && seResult.rows[0][0].displayValue === '1') {
|
||||||
|
vscode.window.showErrorMessage(constants.XEventsNotSupported);
|
||||||
|
} else {
|
||||||
|
vscode.window.showErrorMessage(constants.XEventsFailed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private stopAutoRefresh(connection: azdata.IConnectionProfile): void {
|
private stopAutoRefresh(connection: azdata.IConnectionProfile): void {
|
||||||
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'type-of-contention', connection.id, false);
|
this.autoRefreshState = !this.autoRefreshState === true;
|
||||||
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'metadata-contention', connection.id, false);
|
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'type-of-contention', connection.id, this.autoRefreshState);
|
||||||
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'allocation-contention', connection.id, false);
|
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'metadata-contention', connection.id, this.autoRefreshState);
|
||||||
|
vscode.commands.executeCommand('azdata.widget.setAutoRefreshState', 'allocation-contention', connection.id, this.autoRefreshState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
--Starts the XEvents sessions and creates the functions needed to find object id and give name to the page types
|
--Starts the XEvents sessions and creates the functions needed to find object id and give name to the page types
|
||||||
use tempdb
|
|
||||||
|
|
||||||
BEGIN TRY
|
BEGIN TRY
|
||||||
IF NOT EXISTS (SELECT * FROM sys.dm_xe_sessions WHERE name = 'PageContention')
|
IF NOT EXISTS (SELECT * FROM sys.dm_xe_sessions WHERE name = 'PageContention')
|
||||||
BEGIN
|
BEGIN
|
||||||
@@ -24,9 +22,11 @@ IF NOT EXISTS (SELECT * FROM sys.dm_xe_sessions WHERE name = 'ObjectContention'
|
|||||||
ALTER EVENT SESSION [ObjectContention] ON SERVER
|
ALTER EVENT SESSION [ObjectContention] ON SERVER
|
||||||
STATE = START
|
STATE = START
|
||||||
END
|
END
|
||||||
|
SELECT 0 AS RESULTCODE
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
PRINT 'XEvent fields not supported'
|
PRINT 'XEvent fields not supported'
|
||||||
|
SELECT 1 AS RESULTCODE
|
||||||
END CATCH
|
END CATCH
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
--Stops the XEvent Sessions
|
--Stops the XEvent Sessions
|
||||||
DROP EVENT SESSION [PageContention] ON SERVER
|
DROP EVENT SESSION [PageContention] ON SERVER
|
||||||
DROP EVENT SESSION [ObjectContention] ON SERVER
|
DROP EVENT SESSION [ObjectContention] ON SERVER
|
||||||
|
SELECT 0 AS RESULTCODE
|
||||||
|
|||||||
@@ -3973,6 +3973,11 @@ vsce@1.36.2:
|
|||||||
yauzl "^2.3.1"
|
yauzl "^2.3.1"
|
||||||
yazl "^2.2.2"
|
yazl "^2.2.2"
|
||||||
|
|
||||||
|
vscode-nls@^5.0.0:
|
||||||
|
version "5.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.0.0.tgz#99f0da0bd9ea7cda44e565a74c54b1f2bc257840"
|
||||||
|
integrity sha512-u0Lw+IYlgbEJFF6/qAqG2d1jQmJl0eyAGJHoAJqr2HT4M2BNuQYSEiSE75f52pXHSJm8AlTjnLLbBFPrdz2hpA==
|
||||||
|
|
||||||
vscode-test@^0.1.4:
|
vscode-test@^0.1.4:
|
||||||
version "0.1.5"
|
version "0.1.5"
|
||||||
resolved "https://registry.yarnpkg.com/vscode-test/-/vscode-test-0.1.5.tgz#250534f90e78d37a84419a00f9bd15341e1a4f8f"
|
resolved "https://registry.yarnpkg.com/vscode-test/-/vscode-test-0.1.5.tgz#250534f90e78d37a84419a00f9bd15341e1a4f8f"
|
||||||
|
|||||||
Reference in New Issue
Block a user