-- execute sp_SQLskills_ConvertTraceToExtendedEvents @TraceID = 2, @SessionName = 'XEOverhead'

IF EXISTS (SELECT 1 FROM sys.server_event_sessions WHERE name = 'XEOverhead')
	DROP EVENT SESSION [XEOverhead] ON SERVER;
GO
CREATE EVENT SESSION [XEOverhead]
ON SERVER
ADD EVENT sqlserver.module_end(
	ACTION 
	(
			  sqlserver.client_app_name	-- ApplicationName from SQLTrace
			, sqlserver.client_pid	-- ClientProcessID from SQLTrace
			, sqlserver.nt_username	-- NTUserName from SQLTrace
			, sqlserver.server_principal_name	-- LoginName from SQLTrace
			, sqlserver.session_id	-- SPID from SQLTrace
			-- BinaryData not implemented in XE for this event
	)
),
ADD EVENT sqlserver.sp_statement_completed(
	ACTION 
	(
			  sqlserver.client_app_name	-- ApplicationName from SQLTrace
			, sqlserver.client_pid	-- ClientProcessID from SQLTrace
			, sqlserver.nt_username	-- NTUserName from SQLTrace
			, sqlserver.server_principal_name	-- LoginName from SQLTrace
			, sqlserver.session_id	-- SPID from SQLTrace
	)
)
ADD TARGET package0.event_file
(
	SET filename = 'c:\SQLskills\XEOverhead.xel',
		max_file_size = 500,
		max_rollover_files = 1
)
--WITH (MAX_MEMORY = 32MB);--, EVENT_RETENTION_MODE = NO_EVENT_LOSS);

ALTER EVENT SESSION XEOverhead
ON SERVER
STATE=START;

ALTER EVENT SESSION XEOverhead
ON SERVER
STATE=STOP;

exec sp_trace_setstatus 2, 2
