Skip to content

Commit

Permalink
Add TrackApiCursor XE and fix SSMS version info
Browse files Browse the repository at this point in the history
  • Loading branch information
ktaranov committed Nov 27, 2020
1 parent 79b15e0 commit 3850ccc
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
97 changes: 97 additions & 0 deletions Extended_Events/TrackApiCursor.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
https://blog.pythian.com/extended-events-fetching-api-cursors/
by Shawn Melton January 3, 2017
*/

DROP EVENT SESSION TrackApiCursor ON SERVER;
GO

CREATE EVENT SESSION TrackApiCursor ON SERVER
ADD EVENT sqlserver.cursor_close(
ACTION(
sqlserver.client_app_name,
sqlserver.database_name,
sqlserver.is_system,
sqlserver.session_id,
sqlserver.sql_text)
WHERE (
[sqlserver].[is_system]<>(0)
-- AND [sqlserver].[client_app_name]=N'Steely-Eyed-Missle-Man'
)
),
ADD EVENT sqlserver.cursor_open(
ACTION(
sqlserver.client_app_name,
sqlserver.database_name,
sqlserver.is_system,
sqlserver.query_hash,
sqlserver.session_id,
sqlserver.sql_text)
WHERE (
[sqlserver].[is_system]<>(0)
-- AND [sqlserver].[client_app_name]=N'Steely-Eyed-Missle-Man'
)
),
ADD EVENT sqlserver.rpc_completed(
ACTION(
sqlserver.client_app_name,
sqlserver.database_name,
sqlserver.is_system,
sqlserver.query_hash,
sqlserver.session_id,
sqlserver.sql_text)
WHERE (
[sqlserver].[is_system]<>(0)
-- AND [sqlserver].[client_app_name]=N'Steely-Eyed-Missle-Man'
)
)
ADD TARGET package0.event_file(SET filename=N'Track_api_cursor.xel')
WITH (
MAX_DISPATCH_LATENCY=12 SECONDS,
TRACK_CAUSALITY=ON
);
GO

ALTER EVENT SESSION TrackApiCursor ON SERVER STATE = START;
GO

/* Read the data */
IF OBJECT_ID('tempdb..#XEResults') IS NOT NULL
DROP TABLE #XEResults ;
GO
IF OBJECT_ID('tempdb..#XEResultsParsed') IS NOT NULL
DROP TABLE #XEResultsParsed ;
GO

-- Create results table to load data from XE files
CREATE TABLE #XEResults
(
[RowID] INT IDENTITY
PRIMARY KEY,
[event_data] XML
);

-- Load the event data from the file target
INSERT INTO #XEResults
([event_data])
SELECT CAST([event_data] AS XML) AS event_data
FROM [sys].[fn_xe_file_target_read_file](N'Track_api_cursor*xel',NULL,NULL,NULL) ;

--SELECT * FROM #XEResults

-- Query the Event data from the Target.
SELECT [event].[value]('(@name)[1]', 'varchar(50)') AS event_name
-- , DATEADD(hh, DATEDIFF(hh, GETUTCDATE(), CURRENT_TIMESTAMP), [event].[value]('(@timestamp)[1]', 'datetime2')) AS [timestamp]
,[event].[value]('(action[@name="session_id"]/value)[1]', 'int') AS [session_id]
,[event].[value]('(action[@name="database_name"]/value)[1]','varchar(128)') AS [database_name]
,[event].[value]('(action[@name="client_app_name"]/value)[1]','varchar(500)') AS [client_app_name]
,[event].[value]('(data[@name="object_name"]/value)[1]', 'varchar(50)') AS [object_name]
,[event].[value]('(action[@name="sql_text"]/value)[1]','varchar(max)') AS [sql_text]
,[event].[value]('(data[@name="statement"]/value)[1]', 'varchar(1000)') AS [statement]
,[event].[value]('(action[@name="attach_activity_id_xfer"]/value)[1]', 'varchar(200)') AS [attach_activity_id_xfer]
,[event].[value]('(action[@name="attach_activity_id"]/value)[1]', 'varchar(200)') AS [attach_activity_id]
FROM #XEResults
CROSS APPLY [event_data].[nodes]('event') AS [q] ([event])
ORDER BY DATEADD(hh, DATEDIFF(hh, GETUTCDATE(), CURRENT_TIMESTAMP),[event].[value]('(@timestamp)[1]', 'datetime2'))
,[event].[value]('(action[@name="attach_activity_id"]/value)[1]', 'varchar(200)');

6 changes: 3 additions & 3 deletions SSMS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ SSMS 18.x is based on the new Visual Studio 2017 Isolated Shell: The new shell u

| Version/Download Link | Info | Build | Release Date | Size, Mb |
| --------------------------|----------------|---------------|--------------|---------:|
| [18.7.1 GA Release] | **Latest GA** | 15.0.18358.0 | 2020-07-27 | 635 |
| [18.7. GA Release] | | 15.0.18357.0 | 2020-07-20 | 635 |
| [18.7.1 GA Release] | **Latest GA** | 15.0.18358.0 | 2020-10-27 | 635 |
| [18.7. GA Release] | | 15.0.18357.0 | 2020-10-20 | 635 |
| [18.6 GA Release] | | 15.0.18338.0 | 2020-07-22 | 534 |
| [18.5.1 GA Release] | | 15.0.18333.0 | 2020-07-09 | 535 |
| [18.5.1 GA Release] | | 15.0.18333.0 | 2020-06-09 | 535 |
| [18.5 GA Release] | | 15.0.18183.0 | 2020-04-07 | 535 |
| [18.4 GA Release] | | 15.0.18206.0 | 2019-11-04 | 539 |
| [18.3.1 GA Release] | | 15.0.18183.0 | 2019-10-02 | 534 |
Expand Down

0 comments on commit 3850ccc

Please sign in to comment.