Extended event sessions can use multiple targets to store captured information. We should use different targets depending on the type of data we are capturing and the structure of the data outcome we desire. The available targets include the following: event counter, ring buffer, event file, histogram, event tracing for Windows (ETW), and Event Pairing.
扩展事件会话可以使用多个目标来存储捕获的信息。 我们应根据要捕获的数据类型和所需数据结果的结构使用不同的目标。 可用目标包括:事件计数器,环形缓冲区,事件文件,直方图,Windows事件跟踪(ETW)和事件配对 。
Event pairing matches two events using captured data. There are many types of events that occur in pairs, such as locks, where an example pair would be an acquired lock and released lock. We can utilize the event pairing target to find and determine when a specified paired event hasn’t occurred in the matching set. Working with our example, we can track when a lock was acquired, but not released.
事件配对使用捕获的数据匹配两个事件。 成对发生的事件有很多类型,例如锁,其中示例对将是获取的锁和释放的锁。 我们可以利用事件配对目标来查找和确定匹配集中未发生指定的配对事件。 通过我们的示例,我们可以跟踪何时获得但未释放锁。
After two events are paired, both of them are discarded. Discarding matching events frees space for still unmatched events and allows for easy overview. A great example is the Mahjong game, when two tiles of the same type are matched, they are removed.
在两个事件配对后,它们都将被丢弃。 丢弃匹配事件将为尚不匹配的事件释放空间,并允许轻松查看。 一个很好的例子是麻将游戏,当两个相同类型的图块匹配时,它们将被删除。
Event pairing is an asynchronous process. The data is first kept in the memory buffer, and then sent to the target asynchronously. Usually the events are not sent immediately and specifics of the memory mechanism result in a minimal delay. The data stored within the target will be lost when the SQL Server is restarted.
事件配对是一个异步过程。 数据首先保存在内存缓冲区中,然后异步发送到目标。 通常情况下,事件不会立即发送,并且存储机制的细节会导致延迟最小。 重新启动SQL Server时,目标中存储的数据将丢失。
Within the article, we will go true the creation of an Extended Events session; the configuration parameters of the Event Pairing target, and obtain meaningful data from it.
在本文中,我们将实现扩展事件会话的创建; 事件配对目标的配置参数,并从中获取有意义的数据。
We will start with creating a common extended events session. Its aim is to capture information for SQL Server locks. These events occur when a lock is acquired on an object or when a lock is released.
我们将从创建一个公共扩展事件会话开始。 其目的是捕获SQL Server锁的信息。 当在对象上获取锁或释放锁时,会发生这些事件。
CREATE EVENT SESSION [XE_collect_locks] ON SERVER
ADD EVENT sqlserver.lock_acquired,
ADD EVENT sqlserver.lock_released
GO
Without creating a target for the extended event session, the data is only stored in memory and we can use the SQL Server Management Studio to access it. Shown is the captured data consisting of lock_acquired and lock_released events, each one of them representing a single lock action.
无需为扩展事件会话创建目标,数据仅存储在内存中,我们可以使用SQL Server Management Studio进行访问。 显示的是由lock_acquired和lock_released事件组成的捕获数据,其中每个事件代表一个锁定动作。