Extended Events

Extended Events
[email protected]
Agenda

What are Extended Events?

How do they compare with Profiler

Concepts

Tutorial

Use cases
What are Extended Events

Real-time data capture

No performance penalty


Lightweight

Lock:Aquired, Lock:Released with little performance degradation.
Based on Event Tracing for Windows (ETW)


Allows integration with OS operations, for example we can now trace if
a file copy operation is degrading performance on SQL Server.
Full programmability support

TSQL

SMO

PowerShell
How do they compare with Profiler

XE Designed to replace Profiler/SQL Trace

XE Captures more value/properties/events than profiler

XE is integrated with ETW and Management Studio Activity Monitor

XE does not require a connection to SQL Server

SQL Trace will be deprecated in SQL Next (still ships in SQL 2017)

SQL 2008 – no nice interface for Extended Events

Extended Events Manager https://extendedeventmanager.codeplex.com/

SQL 2012 baked into Management Studio

Allows you to obtain wait statistics on a query/proc/statement.
ETW
ETW
Logman query providers c:\temp\out.txt
 Select * from sys.dm_xe_packages
Package0 60AA9FBF-673B-4553-B7ED-71DCA7F5E972
Sqlos
BD97CC63-3F38-4922-AA93-607BD12E78B2
XeDkPkg 52FC232C-03D5-4E1F-A6BF-BBC66FE20E6A
sqlserver
655FD93F-3364-40D5-B2BA-330F7FFB6491
SecAudit F235752A-D5C0-4C9A-A735-9C3B6F6E43B1
ucs
C0AB75C5-B1EA-445B-B7DF-F897686F94E7
sqlclr
1E99FE90-A4FE-45E6-9DFD-A45041F02314
filestream B086C2F3-2738-4389-B119-D80B5362B5CA
sqlserver
03FDA7D0-91BA-45F8-9875-8B6DD0B8E9F2

Traces vs XE
Tracecs vs XE
2500
2000
1500
1000
500
0
0
1
2
3
4
sys.event_traces
5
sys.dm_xe_objects
6
7
8
9
Well what about the black box
trace then?


SQL 2012 adds default xe sessions (traces)

AlwaysOn_Health

System_health
SQL 2014 adds


Nothing
SQL 2016 adds

Telemetry_xevents

Mainly for diagnostics – error collection
Ring buffer

Getting ahead of ourselves but…
Extended Events Object Model
XE - packages

select * from sys.dm_xe_packages where coalesce(capabilities,1)=1
sqlos
Extended events for SQL Operating System
sqlserver
Extended events for Microsoft SQL Server
SecAudit
Security Audit Events
sqlserver
ucs
Extended events for Unified
Communications Stack
sqlclr
Extended events for SQL CLR
filestream Extended events for SQL Server FILESTREAM and FileTable
sqlserver
Extended events for Microsoft SQL Server
qds
Extended events for Query Store
XtpRuntime Extended events for the XTP Runtime
XtpCompile Extended events for the XTP Compile
XtpEngine Extended events for the XTP Engine
XTP (eXtreme Transaction Processing – Hekaton).
Extended Events Object Model
Packages
Events and Actions
Filters and Predicates
Sessions
Targets
XE- Events

Well known endpoints in SQL Server Code, ie
sp_statement_completed, rpc_starting, rpc_completed.

Events are categorized in ETW as

Admin – error reports, deprecated events, blocks, deadlocks

Analytical – this is of most interest to us.

Debug – css primarily.

Operational – managing admin events – attaching dbs, dropping dbs.
Blocked Process Report.
Extended Events Object Model
Packages
Events and Actions
Filters and Predicates
Sessions
Targets
XE-Actions

Capability to execute additional actions when the event fires within
the engine. Think of these like the columns in Profiler
Extended Events Object Model
Packages
Events and Actions
Filters and Predicates
Sessions
Targets
XE-Predicates

Allow you to filter on certain events.

Source – and Compare
Extended Events Object Model
Packages
Events and Actions
Filters and Predicates
Sessions
Targets
XE-types and maps

Select * from sys.dm_xe_objects where object_type in ('type','map')

type scalar

Map – list

Select * from sys.dm_xe_objects where object_type in ('type','map')
and name='wait_types'

Select * from sys.dm_xe_map_values where name='wait_types'
Extended Events Object Model
Packages
Events and Actions
Filters and Predicates
Sessions
Targets
XE-Target

Where data ends up

etw_classic_sync_target-Event Tracing for Windows (ETW) Synchronous Target

Histogram-Use the histogram target to aggregate event data based on a
specific event data field or action associated with the event. The histogram
allows you to analyze distribution of the event data over the period of the event
session.

event_file-Use the event_file target to save the event data to an XEL file, which
can be archived and used for later analysis and review. You can merge multiple
XEL files to view the combined data from separate event sessions.

pair_matching-Pairing target

event_counter-Use the event_counter target to count the number of
occurrences of each event in the event session.

ring_buffer-Asynchronous ring buffer target.
XE Templates – locks and blocks

Locks and Blocks

Count Query Locks

Use this template to identify the most lock intensive queries for investigation
and tuning.
XE Templates – Query Execution

Query Execution

Query Batch Sampling


Query Batch Tracking




Samples 20% (by default) of your batches and RPC statements in your workload and error information.
Collects all batch and RPC level statements as well as error information. Can be very large.
Query Detail Sampling

Samples 20% (by default) of your statements in your workload and error information.

Collects the query hash and query plan hash for every statement it tracks.
Query Detail Tracking

Collects all detailed statement and error information.

Can be used to determine which statement in a batch or procedure threw the error.

Collects the query hash and query plan hash for every statement it tracks.

Can be very large.
Query Wait Statistics

Tracks internal and external wait statistics for individual query statements, batches and RPCs.

20 % sample rate.
XE Templates - System Monitoring

Activity Tracking


Connection Monitoring


Most similar to trace.
Tracks connection activity for a server. Normal connection activity is tracked
using the login and logout events, and problems are recorded using the
connectivity_ring_buffer_recorded event.
Database Log File IO Tracking

Monitors the IO for database log files on a server by tracking asynchronous
IO, database log flushes, file writes, spinlock backoffs of type LOGFLUSHQ
and waits of type WRITELOG.
Top Resource Consumers

High Performance.SQL

Master database on publisher, table called called Perf
Timeouts

Timeouts1.sql
Page Splits

PageSplits.sql

https://www.sqlskills.com/blogs/jonathan/tracking-problematicpages-splits-in-sql-server-2012-extended-events-no-really-this-time/
Errors

Errors.sql
Converting a profiler trace to XE

From
http://blogs.msdn.com/b/extended_events/archive/2010/12/10/mi
grating-from-sql-trace-to-extended-events.aspx

C:\ExtendedEvents\Converting my SQL Server Trace File to an
Extended Event
Blocking
Debugging

use master
GO
insert into dm_hadr_database_replica_states
select recovery_lsn, truncation_lsn, last_hardened_lsn,
last_received_lsn,
log_send_queue_size,log_send_queue_size/log_send_rate[log_send_q
ueue_size/log_send_rate],log_send_rate,redo_queue_size,
last_redone_lsn, last_redone_time,database_id, getdate() dtstamp,
db_name(database_id) databaseName
from sys.dm_hadr_database_replica_states where log_send_rate>0