Reading the Ring Buffer in Extended Events

The much-maligned ring buffer target in Extended Events offers a simple, reliable place to store transient events. While it’s pretty easy to use the “Live Data” view in SQL Server Management Studio to view events as they happen, it can be helpful to programmatically extract data from the ring buffer manually.

The ring buffer target briefly holds event data in memory. This target can manage events in one of two modes.

The first mode is strict first-in first-out (FIFO), where the oldest event is discarded when all the memory allocated to the target is used. In this mode (the default), the occurrence_number option is set to 0.

The second mode is per-event FIFO, where a specified number of events of each type is kept. In this mode, the oldest events of each type are discarded when all the memory allocated to the target is used. You can configure the occurrence_number option to specify the number of events of each type to keep.

Not a ring buffer target, but still interesting enough!

Not a ring buffer target, but still interesting enough!

The code below offers a quick way to parse the ring buffer with a time-based filter.

Let me know if you have any questions about the code above!

See the rest of our series of posts on Extended Events.