Вы находитесь на странице: 1из 24

Module 12

Tracing Access to SQL Server with


Extended Events
Module Overview

• Extended Events Core Concepts


• Working with Extended Events
Lesson 1: Extended Events Core Concepts

• Extended Events, SQL Trace, and SQL Server


Profiler
• Extended Events Architecture
• Packages
• Events
• Predicates
• Actions
• Targets
• Sessions
• Types and Maps
• Demonstration: Creating an Extended Events
Session
Extended Events, SQL Trace, and SQL Server
Profiler

• SQL Trace and SQL Server Profiler are tools for


collecting trace information about activity on a
SQL Server instance
• Extended Events is the successor to SQL Trace
and will eventually replace it completely
• SQL Trace/SQL Server Profiler has been marked for
deprecation
• Extended Events is more flexible than SQL Trace
• Greater flexibility comes with greater complexity
Extended Events Architecture

• Extended Events engine provides capabilities


• User defines session
• Session collects event
• Event triggers action
• Event is filtered by predicate
• Session writes to target
• A package defines the objects available to a
session
Packages

• Executables and executable modules expose


Extended Events packages
• A package is a container for other object types:
• Events
• Predicates
• Actions
• Targets
• Maps
• Types
Events

• Events are logging points in executable code


• When an event fires, it indicates that the associated
code has been executed
• Returns data in a fixed schema
• Events are compatible with Event Tracing for Windows
Predicates

• Allow the construction of rules to filter event


capture
• Made up of two subcategories:
• Comparisons—logical operators (=, <, > and so on)
• Sources—values that might be used as inputs to comparisons
• Complex predicates might be constructed; every n
events, or every n seconds
Actions

• Actions provide supplementary information


about an event
• Each event might be linked to one or more actions
• Actions are triggered synchronously after an associated
event has fired
Targets

• Targets collect data from Extended Events


sessions
• A session may write to multiple targets
• Targets may be synchronous or asynchronous
• Event counter: synchronous
• Event file: asynchronous
• Event pairing: asynchronous
• Event Tracing for Windows: synchronous
• Histogram: asynchronous
• Ring buffer: asynchronous
• An event will only be written once to a target
Sessions

• A session links events to targets


• Events may include actions
• Events may be filtered with predicates
• Sessions are isolated from one another
• A session has a state (started or stopped)
• A session has a buffer to hold event data as it is
captured
Types and Maps

• Types
• Data type definitions for Extended Events data

• Maps
• Lookup tables to convert integer values to text values
Demonstration: Creating an Extended Events
Session

In this demonstration, you will see how to create


an Extended Events session
Lesson 2: Working with Extended Events

• Configuring Sessions
• Configuring Targets
• The system_health Extended Events Session
• Usage Scenarios for Extended Events
• Extended Events Best Practices
• Demonstration: Tracking Session-Level Waits
Configuring Sessions

• Session configuration options:


• MAX_MEMORY
• EVENT_RETENTION_MODE
• MAX_DISPATCH_LATENCY
• MAX_EVENT_SIZE
• MEMORY_PARTITION_MODE
• STARTUP_STATE
• TRACK_CAUSALITY
Configuring Targets

• Event File
• Event Pairing
• Ring Buffer
• Histogram
• Event Tracing for Windows

• Event Counter
• Takes no configuration
The system_health Extended Events Session

• Created by default on all database engines


• Starts at instance startup
• Captures events useful for troubleshooting
• Ring buffer and file targets
Usage Scenarios for Extended Events

Usage Scenario Event/Event column Targets

Execution Time-outs sqlserver.session_id, sqlserver.tsql_stack Event pairing

Troubleshooting sqlos.wait_info- wait_type of


Histogram
ASYNC_NETWORK_IO issues NETWORK_IO

Tracking Error Handling in T-


sqlserver.error_reported- is_intercepted Any
SQL code

sqlserver.sql_statement_recompile
Tracking Recompilations Any
sqlserver.tsql_stack- filter on database_id

tempdb Latch contention Latch_suspend_end Histogram

Lock Escalation sqlserver.lock_escalation Any

sqlserver.page_split,
Problematic Page Splits Any
sqlserver.transaction_log

Troubleshooting Orphaned database_transaction_begin and


Event pairing
Transactions database_transaction_end

Tracking Session Waits sqlos.wait_info Any

Tracking Database and Object


sqlserver.lock_acquired Histogram
usage
Extended Events Best Practices

• Run Extended Events sessions only when you


need them
• Use the SSMS GUI to browse available events
• Understand the limitations of the ring buffer
target
• Consider the performance impact of collecting
query execution plans
• Understand the deadlock graph format
Demonstration: Tracking Session-Level Waits

In this demonstration, you will see how to report


on wait types by session using Extended Events
Lab: Extended Events

• Exercise 1: Using the system_health Extended


Events Session
• Exercise 2: Tracking Page Splits Using Extended
Events

Logon Information
Virtual machine: 20764C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd

Estimated Time: 90 minutes


Lab Scenario

While investigating the general slowness of the


new SQL Server instance, you notice deadlock
occurrences and excessive fragmentation in
indexes caused by page split operations. In this
lab, you will review deadlock occurrences using
the default session, and implement a new
Extended Event session to identify workloads that
cause huge page splits.
Lab Review

• If an Extended Events session has no targets


defined, how would you view the data generated
by the session?
Module Review and Takeaways

• Review Question(s)

Вам также может понравиться