1- -- Compile Date: 02/15 /2026 15:13:30 UTC
1+ -- Compile Date: 02/17 /2026 16:48:32 UTC
22SET ANSI_NULLS ON;
33SET ANSI_PADDING ON;
44SET ANSI_WARNINGS ON;
@@ -50,6 +50,8 @@ ALTER PROCEDURE
5050 @wait_duration_ms bigint = 500, /*Minimum duration to show query waits*/
5151 @wait_round_interval_minutes bigint = 60, /*Nearest interval to round wait stats to*/
5252 @skip_locks bit = 0, /*Skip the blocking and deadlocks*/
53+ @skip_waits bit = 0, /*Skip the wait stats*/
54+ @use_ring_buffer bit = 0, /*Use ring_buffer target instead of file target for system_health session*/
5355 @pending_task_threshold integer = 10, /*Minimum number of pending tasks to care about*/
5456 @log_to_table bit = 0, /*enable logging to permanent tables*/
5557 @log_database_name sysname = NULL, /*database to store logging tables*/
7173 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
7274
7375 SELECT
74- @version = '3.2.5 ',
75- @version_date = '20260206 ';
76+ @version = '3.4 ',
77+ @version_date = '20260217 ';
7678
7779 IF @help = 1
7880 BEGIN
@@ -102,6 +104,8 @@ BEGIN
102104 WHEN N'@wait_duration_ms' THEN N'minimum wait duration'
103105 WHEN N'@wait_round_interval_minutes' THEN N'interval to round minutes to for wait stats'
104106 WHEN N'@skip_locks' THEN N'skip the blocking and deadlocking section'
107+ WHEN N'@skip_waits' THEN N'skip the wait stats section'
108+ WHEN N'@use_ring_buffer' THEN N'use ring_buffer target instead of file target for faster collection'
105109 WHEN N'@pending_task_threshold' THEN N'minimum number of pending tasks to display'
106110 WHEN N'@log_to_table' THEN N'enable logging to permanent tables instead of returning results'
107111 WHEN N'@log_database_name' THEN N'database to store logging tables'
@@ -124,6 +128,8 @@ BEGIN
124128 WHEN N'@wait_duration_ms' THEN N'the minimum duration of a wait for queries with interesting waits'
125129 WHEN N'@wait_round_interval_minutes' THEN N'interval to round minutes to for top wait stats by count and duration'
126130 WHEN N'@skip_locks' THEN N'0 or 1'
131+ WHEN N'@skip_waits' THEN N'0 or 1'
132+ WHEN N'@use_ring_buffer' THEN N'0 or 1'
127133 WHEN N'@pending_task_threshold' THEN N'a valid integer'
128134 WHEN N'@log_to_table' THEN N'0 or 1'
129135 WHEN N'@log_database_name' THEN N'any valid database name'
@@ -146,6 +152,8 @@ BEGIN
146152 WHEN N'@wait_duration_ms' THEN N'500'
147153 WHEN N'@wait_round_interval_minutes' THEN N'60'
148154 WHEN N'@skip_locks' THEN N'0'
155+ WHEN N'@skip_waits' THEN N'0'
156+ WHEN N'@use_ring_buffer' THEN N'0'
149157 WHEN N'@pending_task_threshold' THEN N'10'
150158 WHEN N'@log_to_table' THEN N'0'
151159 WHEN N'@log_database_name' THEN N'NULL (current database)'
@@ -457,6 +465,8 @@ AND ca.utc_timestamp < @end_date';
457465 @wait_duration_ms = ISNULL(@wait_duration_ms, 500),
458466 @wait_round_interval_minutes = ISNULL(@wait_round_interval_minutes, 60),
459467 @skip_locks = ISNULL(@skip_locks, 0),
468+ @skip_waits = ISNULL(@skip_waits, 0),
469+ @use_ring_buffer = ISNULL(@use_ring_buffer, 0),
460470 @pending_task_threshold = ISNULL(@pending_task_threshold, 10);
461471
462472 /*Validate what to check*/
@@ -1349,6 +1359,9 @@ AND ca.utc_timestamp < @end_date';
13491359 WHEN v.area_name = 'locking'
13501360 AND @skip_locks = 1
13511361 THEN 0
1362+ WHEN v.area_name = 'waits'
1363+ AND @skip_waits = 1
1364+ THEN 0
13521365 ELSE 1
13531366 END
13541367 WHEN @what_to_check = v.area_name
@@ -1455,7 +1468,8 @@ AND ca.utc_timestamp < @end_date';
14551468 );
14561469
14571470 /*The more you ignore waits, the worser they get*/
1458- IF @what_to_check IN ('all', 'waits')
1471+ IF @what_to_check IN ('all', 'waits')
1472+ AND @skip_waits = 0
14591473 BEGIN
14601474 IF @debug = 1
14611475 BEGIN
@@ -1532,87 +1546,101 @@ AND ca.utc_timestamp < @end_date';
15321546 ORDER BY
15331547 ca.id;
15341548
1535- OPEN @collection_cursor;
1549+ /*
1550+ File target collection: read from system_health .xel files on disk
1551+ Skip this path when using ring_buffer target or on Managed Instance
1552+ */
1553+ IF @mi = 0
1554+ AND @use_ring_buffer = 0
1555+ BEGIN
1556+ OPEN @collection_cursor;
15361557
1537- FETCH NEXT
1538- FROM @collection_cursor
1539- INTO
1540- @area_name,
1541- @object_name,
1542- @temp_table,
1543- @insert_list;
1558+ FETCH NEXT
1559+ FROM @collection_cursor
1560+ INTO
1561+ @area_name,
1562+ @object_name,
1563+ @temp_table,
1564+ @insert_list;
15441565
1545- WHILE @@FETCH_STATUS = 0
1546- BEGIN
1547- /* Build the SQL statement for this collection area */
1548- SET
1549- @collection_sql =
1550- REPLACE
1551- (
1566+ WHILE @@FETCH_STATUS = 0
1567+ BEGIN
1568+ /* Build the SQL statement for this collection area */
1569+ SET
1570+ @collection_sql =
15521571 REPLACE
15531572 (
15541573 REPLACE
15551574 (
1556- @sql_template,
1557- '{object_name}',
1558- @object_name
1575+ REPLACE
1576+ (
1577+ @sql_template,
1578+ '{object_name}',
1579+ @object_name
1580+ ),
1581+ '{temp_table}',
1582+ @temp_table
15591583 ),
1560- '{temp_table}',
1561- @temp_table
1562- ),
1563- '{insert_list}',
1564- @insert_list
1565- );
1584+ '{insert_list}',
1585+ @insert_list
1586+ );
15661587
1567- IF @debug = 1
1568- BEGIN
1569- RAISERROR('Collecting data for area: %s, object: %s, target table: %s', 0, 1, @area_name, @object_name, @temp_table) WITH NOWAIT;
1570- PRINT @collection_sql;
1571- END;
1588+ IF @debug = 1
1589+ BEGIN
1590+ RAISERROR('Collecting data for area: %s, object: %s, target table: %s', 0, 1, @area_name, @object_name, @temp_table) WITH NOWAIT;
1591+ PRINT @collection_sql;
1592+ END;
15721593
1573- IF @debug = 1
1574- BEGIN
1575- RAISERROR('Executing collection SQL for dates between %s and %s', 0, 0, @start_date_debug, @end_date_debug) WITH NOWAIT;
1576- SET STATISTICS XML ON;
1577- END;
1594+ IF @debug = 1
1595+ BEGIN
1596+ RAISERROR('Executing collection SQL for dates between %s and %s', 0, 0, @start_date_debug, @end_date_debug) WITH NOWAIT;
1597+ SET STATISTICS XML ON;
1598+ END;
15781599
1579- EXECUTE sys.sp_executesql
1580- @collection_sql,
1581- @params,
1582- @start_date,
1583- @end_date;
1600+ EXECUTE sys.sp_executesql
1601+ @collection_sql,
1602+ @params,
1603+ @start_date,
1604+ @end_date;
15841605
1585- IF @debug = 1
1586- BEGIN
1587- SET STATISTICS XML OFF;
1588- END;
1606+ IF @debug = 1
1607+ BEGIN
1608+ SET STATISTICS XML OFF;
1609+ END;
15891610
1590- UPDATE
1591- @collection_areas
1592- SET
1593- is_processed = 1
1594- WHERE temp_table = @temp_table
1595- AND should_collect = 1;
1611+ UPDATE
1612+ @collection_areas
1613+ SET
1614+ is_processed = 1
1615+ WHERE temp_table = @temp_table
1616+ AND should_collect = 1;
15961617
1597- FETCH NEXT
1598- FROM @collection_cursor
1599- INTO
1600- @area_name,
1601- @object_name,
1602- @temp_table,
1603- @insert_list;
1604- END;
1618+ FETCH NEXT
1619+ FROM @collection_cursor
1620+ INTO
1621+ @area_name,
1622+ @object_name,
1623+ @temp_table,
1624+ @insert_list;
1625+ END;
16051626
1606- IF @debug = 1
1607- BEGIN
1608- RAISERROR('Data collection complete', 0, 0) WITH NOWAIT;
1609- END;
1627+ IF @debug = 1
1628+ BEGIN
1629+ RAISERROR('Data collection complete', 0, 0) WITH NOWAIT;
1630+ END;
1631+ END; /*End file target collection*/
16101632
1633+ /*
1634+ Ring buffer collection: read from system_health ring_buffer target
1635+ Used for Managed Instance (always) and on-prem when @use_ring_buffer = 1
1636+ Faster than file target because it avoids disk I/O
1637+ */
16111638 IF @mi = 1
1639+ OR @use_ring_buffer = 1
16121640 BEGIN
16131641 IF @debug = 1
16141642 BEGIN
1615- RAISERROR('Starting Managed Instance analysis', 0, 0) WITH NOWAIT;
1643+ RAISERROR('Starting ring_buffer analysis', 0, 0) WITH NOWAIT;
16161644 RAISERROR('Inserting #x', 0, 0) WITH NOWAIT;
16171645 END;
16181646
@@ -1675,11 +1703,12 @@ AND ca.utc_timestamp < @end_date';
16751703 FROM #ring_buffer AS x;
16761704 END;
16771705
1678- IF @what_to_check IN ('all', 'waits')
1706+ IF @what_to_check IN ('all', 'waits')
1707+ AND @skip_waits = 0
16791708 BEGIN
16801709 IF @debug = 1
16811710 BEGIN
1682- RAISERROR('Checking Managed Instance waits', 0, 0) WITH NOWAIT;
1711+ RAISERROR('Checking ring_buffer waits', 0, 0) WITH NOWAIT;
16831712 RAISERROR('Inserting #wait_info', 0, 0) WITH NOWAIT;
16841713 END;
16851714
@@ -1701,7 +1730,7 @@ AND ca.utc_timestamp < @end_date';
17011730 BEGIN
17021731 IF @debug = 1
17031732 BEGIN
1704- RAISERROR('Checking Managed Instance sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT;
1733+ RAISERROR('Checking ring_buffer sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT;
17051734 RAISERROR('Inserting #sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT;
17061735 END;
17071736
@@ -1728,7 +1757,7 @@ AND ca.utc_timestamp < @end_date';
17281757 BEGIN
17291758 IF @debug = 1
17301759 BEGIN
1731- RAISERROR('Checking Managed Instance deadlocks', 0, 0) WITH NOWAIT;
1760+ RAISERROR('Checking ring_buffer deadlocks', 0, 0) WITH NOWAIT;
17321761 RAISERROR('Inserting #xml_deadlock_report', 0, 0) WITH NOWAIT;
17331762 END;
17341763
@@ -1752,7 +1781,7 @@ AND ca.utc_timestamp < @end_date';
17521781 BEGIN
17531782 IF @debug = 1
17541783 BEGIN
1755- RAISERROR('Checking Managed Instance scheduler monitor', 0, 0) WITH NOWAIT;
1784+ RAISERROR('Checking ring_buffer scheduler monitor', 0, 0) WITH NOWAIT;
17561785 RAISERROR('Inserting #scheduler_monitor', 0, 0) WITH NOWAIT;
17571786 END;
17581787
@@ -1776,7 +1805,7 @@ AND ca.utc_timestamp < @end_date';
17761805 BEGIN
17771806 IF @debug = 1
17781807 BEGIN
1779- RAISERROR('Checking Managed Instance error reported events', 0, 0) WITH NOWAIT;
1808+ RAISERROR('Checking ring_buffer error reported events', 0, 0) WITH NOWAIT;
17801809 RAISERROR('Inserting #error_reported', 0, 0) WITH NOWAIT;
17811810 END;
17821811
@@ -1800,7 +1829,7 @@ AND ca.utc_timestamp < @end_date';
18001829 BEGIN
18011830 IF @debug = 1
18021831 BEGIN
1803- RAISERROR('Checking Managed Instance memory broker events', 0, 0) WITH NOWAIT;
1832+ RAISERROR('Checking ring_buffer memory broker events', 0, 0) WITH NOWAIT;
18041833 RAISERROR('Inserting #memory_broker', 0, 0) WITH NOWAIT;
18051834 END;
18061835
@@ -1824,7 +1853,7 @@ AND ca.utc_timestamp < @end_date';
18241853 BEGIN
18251854 IF @debug = 1
18261855 BEGIN
1827- RAISERROR('Checking Managed Instance memory node OOM events', 0, 0) WITH NOWAIT;
1856+ RAISERROR('Checking ring_buffer memory node OOM events', 0, 0) WITH NOWAIT;
18281857 RAISERROR('Inserting #memory_node_oom', 0, 0) WITH NOWAIT;
18291858 END;
18301859
@@ -1884,7 +1913,8 @@ AND ca.utc_timestamp < @end_date';
18841913 END;
18851914
18861915 /*Parse out the wait_info data*/
1887- IF @what_to_check IN ('all', 'waits')
1916+ IF @what_to_check IN ('all', 'waits')
1917+ AND @skip_waits = 0
18881918 BEGIN
18891919 IF @debug = 1
18901920 BEGIN
@@ -1970,6 +2000,8 @@ AND ca.utc_timestamp < @end_date';
19702000 WHEN @what_to_check NOT IN ('all', 'waits')
19712001 THEN 'waits skipped, @what_to_check set to ' +
19722002 @what_to_check
2003+ WHEN @skip_waits = 1
2004+ THEN 'waits skipped, @skip_waits set to 1'
19732005 WHEN @what_to_check IN ('all', 'waits')
19742006 THEN 'no queries with significant waits found between ' +
19752007 RTRIM(CONVERT(date, @start_date)) +
@@ -2222,6 +2254,8 @@ AND ca.utc_timestamp < @end_date';
22222254 WHEN @what_to_check NOT IN ('all', 'waits')
22232255 THEN 'waits skipped, @what_to_check set to ' +
22242256 @what_to_check
2257+ WHEN @skip_waits = 1
2258+ THEN 'waits skipped, @skip_waits set to 1'
22252259 WHEN @what_to_check IN ('all', 'waits')
22262260 THEN 'no significant waits found between ' +
22272261 RTRIM(CONVERT(date, @start_date)) +
@@ -2480,6 +2514,8 @@ AND ca.utc_timestamp < @end_date';
24802514 WHEN @what_to_check NOT IN ('all', 'waits')
24812515 THEN 'waits skipped, @what_to_check set to ' +
24822516 @what_to_check
2517+ WHEN @skip_waits = 1
2518+ THEN 'waits skipped, @skip_waits set to 1'
24832519 WHEN @what_to_check IN ('all', 'waits')
24842520 THEN 'no significant waits found between ' +
24852521 RTRIM(CONVERT(date, @start_date)) +
0 commit comments