Overview and XE Profiler
Using Profiler and the old tracing infrastructure has been deprecated since SQL Server 2012. This includes the server-side SQL Trace functionality. A frequent usage of Profiler has been do trace something live. Scenarios such as:
"I wonder what happens when I press this button"
"I want to see resource usage and performance for these SQL queries"
Extended Events (XE) is a great trace engine, and the GUI in SQL Server Management Studio is also pretty good, provided that
XE Profile | Event session name |
Standard | QuickSessionStandard |
TSQL | QuickSessionTSQL |
IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'QuickSessionTSQL')
DROP EVENT SESSION QuickSessionTSQL ON SERVER
GO
CREATE EVENT SESSION QuickSessionTSQL ON SERVER
ADD EVENT sqlserver.rpc_completed(
ACTION(sqlserver.client_app_name,sqlserver.database_id,sqlserver.database_name,sqlserver.server_principal_name,sqlserver.session_id)
WHERE
([sqlserver].[not_equal_i_sql_unicode_string]([sqlserver].[client_app_name],N'Microsoft SQL Server Management Studio - Transact-SQL IntelliSense')
AND [sqlserver].[client_app_name]<>N'SQLServerCEIP')),
ADD EVENT sqlserver.sql_batch_completed(
ACTION(sqlserver.client_app_name,sqlserver.database_id,sqlserver.database_name,sqlserver.server_principal_name,sqlserver.session_id)
WHERE
([sqlserver].[not_equal_i_sql_unicode_string]([batch_text],N'SELECT @@SPID;')
AND [sqlserver].[not_equal_i_sql_unicode_string]([sqlserver].[client_app_name],N'Microsoft SQL Server Management Studio - Transact-SQL IntelliSense')
AND [sqlserver].[client_app_name]<>N'SQLServerCEIP'))
WITH (MAX_MEMORY=8192 KB, MAX_DISPATCH_LATENCY=5 SECONDS, MAX_EVENT_SIZE=0 KB, MEMORY_PARTITION_MODE=PER_CPU)
This is basically the same as above, but capture per query instead of per batch.
IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name = 'QuickSessionStandard')
DROP EVENT SESSION QuickSessionStandard ON SERVER
GO
CREATE EVENT SESSION QuickSessionStandard ON SERVER
ADD EVENT sqlserver.sp_statement_completed(
ACTION(sqlserver.client_app_name,sqlserver.database_id,sqlserver.database_name,sqlserver.server_principal_name,sqlserver.session_id)
WHERE
(
sqlserver.not_equal_i_sql_unicode_string(sqlserver.client_app_name, N'Microsoft SQL Server Management Studio - Transact-SQL IntelliSense')
AND
sqlserver.client_app_name <> N'SQLServerCEIP')
),
ADD EVENT sqlserver.sql_statement_completed(
ACTION(sqlserver.client_app_name,sqlserver.database_id,sqlserver.database_name,sqlserver.server_principal_name,sqlserver.session_id)
WHERE
(
sqlserver.not_equal_i_sql_unicode_string(sqlserver.client_app_name, N'Microsoft SQL Server Management Studio - Transact-SQL IntelliSense')
AND
[sqlserver].[client_app_name]<>N'SQLServerCEIP')
)
ADD TARGET package0.event_file
(
SET filename=N'R:\QuickSessionStandard.xel'
,max_file_size=(50)
,max_rollover_files=(2))
WITH
(
MAX_DISPATCH_LATENCY=3 SECONDS
,MAX_EVENT_SIZE=0 KB
)
GO