diff --git a/Install-All/DarlingData.sql b/Install-All/DarlingData.sql index d4d3f271..98d30e6d 100644 --- a/Install-All/DarlingData.sql +++ b/Install-All/DarlingData.sql @@ -1,4 +1,4 @@ --- Compile Date: 02/15/2026 15:13:30 UTC +-- Compile Date: 02/17/2026 16:51:34 UTC SET ANSI_NULLS ON; SET ANSI_PADDING ON; SET ANSI_WARNINGS ON; @@ -50,6 +50,8 @@ ALTER PROCEDURE @wait_duration_ms bigint = 500, /*Minimum duration to show query waits*/ @wait_round_interval_minutes bigint = 60, /*Nearest interval to round wait stats to*/ @skip_locks bit = 0, /*Skip the blocking and deadlocks*/ + @skip_waits bit = 0, /*Skip the wait stats*/ + @use_ring_buffer bit = 0, /*Use ring_buffer target instead of file target for system_health session*/ @pending_task_threshold integer = 10, /*Minimum number of pending tasks to care about*/ @log_to_table bit = 0, /*enable logging to permanent tables*/ @log_database_name sysname = NULL, /*database to store logging tables*/ @@ -71,8 +73,8 @@ BEGIN SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SELECT - @version = '3.2.5', - @version_date = '20260206'; + @version = '3.4', + @version_date = '20260217'; IF @help = 1 BEGIN @@ -102,6 +104,8 @@ BEGIN WHEN N'@wait_duration_ms' THEN N'minimum wait duration' WHEN N'@wait_round_interval_minutes' THEN N'interval to round minutes to for wait stats' WHEN N'@skip_locks' THEN N'skip the blocking and deadlocking section' + WHEN N'@skip_waits' THEN N'skip the wait stats section' + WHEN N'@use_ring_buffer' THEN N'use ring_buffer target instead of file target for faster collection' WHEN N'@pending_task_threshold' THEN N'minimum number of pending tasks to display' WHEN N'@log_to_table' THEN N'enable logging to permanent tables instead of returning results' WHEN N'@log_database_name' THEN N'database to store logging tables' @@ -124,6 +128,8 @@ BEGIN WHEN N'@wait_duration_ms' THEN N'the minimum duration of a wait for queries with interesting waits' WHEN N'@wait_round_interval_minutes' THEN N'interval to round minutes to for top wait stats by count and duration' WHEN N'@skip_locks' THEN N'0 or 1' + WHEN N'@skip_waits' THEN N'0 or 1' + WHEN N'@use_ring_buffer' THEN N'0 or 1' WHEN N'@pending_task_threshold' THEN N'a valid integer' WHEN N'@log_to_table' THEN N'0 or 1' WHEN N'@log_database_name' THEN N'any valid database name' @@ -146,6 +152,8 @@ BEGIN WHEN N'@wait_duration_ms' THEN N'500' WHEN N'@wait_round_interval_minutes' THEN N'60' WHEN N'@skip_locks' THEN N'0' + WHEN N'@skip_waits' THEN N'0' + WHEN N'@use_ring_buffer' THEN N'0' WHEN N'@pending_task_threshold' THEN N'10' WHEN N'@log_to_table' THEN N'0' WHEN N'@log_database_name' THEN N'NULL (current database)' @@ -457,6 +465,8 @@ AND ca.utc_timestamp < @end_date'; @wait_duration_ms = ISNULL(@wait_duration_ms, 500), @wait_round_interval_minutes = ISNULL(@wait_round_interval_minutes, 60), @skip_locks = ISNULL(@skip_locks, 0), + @skip_waits = ISNULL(@skip_waits, 0), + @use_ring_buffer = ISNULL(@use_ring_buffer, 0), @pending_task_threshold = ISNULL(@pending_task_threshold, 10); /*Validate what to check*/ @@ -1349,6 +1359,9 @@ AND ca.utc_timestamp < @end_date'; WHEN v.area_name = 'locking' AND @skip_locks = 1 THEN 0 + WHEN v.area_name = 'waits' + AND @skip_waits = 1 + THEN 0 ELSE 1 END WHEN @what_to_check = v.area_name @@ -1455,7 +1468,8 @@ AND ca.utc_timestamp < @end_date'; ); /*The more you ignore waits, the worser they get*/ - IF @what_to_check IN ('all', 'waits') + IF @what_to_check IN ('all', 'waits') + AND @skip_waits = 0 BEGIN IF @debug = 1 BEGIN @@ -1532,87 +1546,101 @@ AND ca.utc_timestamp < @end_date'; ORDER BY ca.id; - OPEN @collection_cursor; + /* + File target collection: read from system_health .xel files on disk + Skip this path when using ring_buffer target or on Managed Instance + */ + IF @mi = 0 + AND @use_ring_buffer = 0 + BEGIN + OPEN @collection_cursor; - FETCH NEXT - FROM @collection_cursor - INTO - @area_name, - @object_name, - @temp_table, - @insert_list; + FETCH NEXT + FROM @collection_cursor + INTO + @area_name, + @object_name, + @temp_table, + @insert_list; - WHILE @@FETCH_STATUS = 0 - BEGIN - /* Build the SQL statement for this collection area */ - SET - @collection_sql = - REPLACE - ( + WHILE @@FETCH_STATUS = 0 + BEGIN + /* Build the SQL statement for this collection area */ + SET + @collection_sql = REPLACE ( REPLACE ( - @sql_template, - '{object_name}', - @object_name + REPLACE + ( + @sql_template, + '{object_name}', + @object_name + ), + '{temp_table}', + @temp_table ), - '{temp_table}', - @temp_table - ), - '{insert_list}', - @insert_list - ); + '{insert_list}', + @insert_list + ); - IF @debug = 1 - BEGIN - RAISERROR('Collecting data for area: %s, object: %s, target table: %s', 0, 1, @area_name, @object_name, @temp_table) WITH NOWAIT; - PRINT @collection_sql; - END; + IF @debug = 1 + BEGIN + RAISERROR('Collecting data for area: %s, object: %s, target table: %s', 0, 1, @area_name, @object_name, @temp_table) WITH NOWAIT; + PRINT @collection_sql; + END; - IF @debug = 1 - BEGIN - RAISERROR('Executing collection SQL for dates between %s and %s', 0, 0, @start_date_debug, @end_date_debug) WITH NOWAIT; - SET STATISTICS XML ON; - END; + IF @debug = 1 + BEGIN + RAISERROR('Executing collection SQL for dates between %s and %s', 0, 0, @start_date_debug, @end_date_debug) WITH NOWAIT; + SET STATISTICS XML ON; + END; - EXECUTE sys.sp_executesql - @collection_sql, - @params, - @start_date, - @end_date; + EXECUTE sys.sp_executesql + @collection_sql, + @params, + @start_date, + @end_date; - IF @debug = 1 - BEGIN - SET STATISTICS XML OFF; - END; + IF @debug = 1 + BEGIN + SET STATISTICS XML OFF; + END; - UPDATE - @collection_areas - SET - is_processed = 1 - WHERE temp_table = @temp_table - AND should_collect = 1; + UPDATE + @collection_areas + SET + is_processed = 1 + WHERE temp_table = @temp_table + AND should_collect = 1; - FETCH NEXT - FROM @collection_cursor - INTO - @area_name, - @object_name, - @temp_table, - @insert_list; - END; + FETCH NEXT + FROM @collection_cursor + INTO + @area_name, + @object_name, + @temp_table, + @insert_list; + END; - IF @debug = 1 - BEGIN - RAISERROR('Data collection complete', 0, 0) WITH NOWAIT; - END; + IF @debug = 1 + BEGIN + RAISERROR('Data collection complete', 0, 0) WITH NOWAIT; + END; + END; /*End file target collection*/ + /* + Ring buffer collection: read from system_health ring_buffer target + Used for Managed Instance (always) and on-prem when @use_ring_buffer = 1 + Faster than file target because it avoids disk I/O + */ IF @mi = 1 + OR @use_ring_buffer = 1 BEGIN IF @debug = 1 BEGIN - RAISERROR('Starting Managed Instance analysis', 0, 0) WITH NOWAIT; + RAISERROR('Starting ring_buffer analysis', 0, 0) WITH NOWAIT; RAISERROR('Inserting #x', 0, 0) WITH NOWAIT; END; @@ -1675,11 +1703,12 @@ AND ca.utc_timestamp < @end_date'; FROM #ring_buffer AS x; END; - IF @what_to_check IN ('all', 'waits') + IF @what_to_check IN ('all', 'waits') + AND @skip_waits = 0 BEGIN IF @debug = 1 BEGIN - RAISERROR('Checking Managed Instance waits', 0, 0) WITH NOWAIT; + RAISERROR('Checking ring_buffer waits', 0, 0) WITH NOWAIT; RAISERROR('Inserting #wait_info', 0, 0) WITH NOWAIT; END; @@ -1701,7 +1730,7 @@ AND ca.utc_timestamp < @end_date'; BEGIN IF @debug = 1 BEGIN - RAISERROR('Checking Managed Instance sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT; + RAISERROR('Checking ring_buffer sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT; RAISERROR('Inserting #sp_server_diagnostics_component_result', 0, 0) WITH NOWAIT; END; @@ -1728,7 +1757,7 @@ AND ca.utc_timestamp < @end_date'; BEGIN IF @debug = 1 BEGIN - RAISERROR('Checking Managed Instance deadlocks', 0, 0) WITH NOWAIT; + RAISERROR('Checking ring_buffer deadlocks', 0, 0) WITH NOWAIT; RAISERROR('Inserting #xml_deadlock_report', 0, 0) WITH NOWAIT; END; @@ -1752,7 +1781,7 @@ AND ca.utc_timestamp < @end_date'; BEGIN IF @debug = 1 BEGIN - RAISERROR('Checking Managed Instance scheduler monitor', 0, 0) WITH NOWAIT; + RAISERROR('Checking ring_buffer scheduler monitor', 0, 0) WITH NOWAIT; RAISERROR('Inserting #scheduler_monitor', 0, 0) WITH NOWAIT; END; @@ -1776,7 +1805,7 @@ AND ca.utc_timestamp < @end_date'; BEGIN IF @debug = 1 BEGIN - RAISERROR('Checking Managed Instance error reported events', 0, 0) WITH NOWAIT; + RAISERROR('Checking ring_buffer error reported events', 0, 0) WITH NOWAIT; RAISERROR('Inserting #error_reported', 0, 0) WITH NOWAIT; END; @@ -1800,7 +1829,7 @@ AND ca.utc_timestamp < @end_date'; BEGIN IF @debug = 1 BEGIN - RAISERROR('Checking Managed Instance memory broker events', 0, 0) WITH NOWAIT; + RAISERROR('Checking ring_buffer memory broker events', 0, 0) WITH NOWAIT; RAISERROR('Inserting #memory_broker', 0, 0) WITH NOWAIT; END; @@ -1824,7 +1853,7 @@ AND ca.utc_timestamp < @end_date'; BEGIN IF @debug = 1 BEGIN - RAISERROR('Checking Managed Instance memory node OOM events', 0, 0) WITH NOWAIT; + RAISERROR('Checking ring_buffer memory node OOM events', 0, 0) WITH NOWAIT; RAISERROR('Inserting #memory_node_oom', 0, 0) WITH NOWAIT; END; @@ -1884,7 +1913,8 @@ AND ca.utc_timestamp < @end_date'; END; /*Parse out the wait_info data*/ - IF @what_to_check IN ('all', 'waits') + IF @what_to_check IN ('all', 'waits') + AND @skip_waits = 0 BEGIN IF @debug = 1 BEGIN @@ -1970,6 +2000,8 @@ AND ca.utc_timestamp < @end_date'; WHEN @what_to_check NOT IN ('all', 'waits') THEN 'waits skipped, @what_to_check set to ' + @what_to_check + WHEN @skip_waits = 1 + THEN 'waits skipped, @skip_waits set to 1' WHEN @what_to_check IN ('all', 'waits') THEN 'no queries with significant waits found between ' + RTRIM(CONVERT(date, @start_date)) + @@ -2222,6 +2254,8 @@ AND ca.utc_timestamp < @end_date'; WHEN @what_to_check NOT IN ('all', 'waits') THEN 'waits skipped, @what_to_check set to ' + @what_to_check + WHEN @skip_waits = 1 + THEN 'waits skipped, @skip_waits set to 1' WHEN @what_to_check IN ('all', 'waits') THEN 'no significant waits found between ' + RTRIM(CONVERT(date, @start_date)) + @@ -2480,6 +2514,8 @@ AND ca.utc_timestamp < @end_date'; WHEN @what_to_check NOT IN ('all', 'waits') THEN 'waits skipped, @what_to_check set to ' + @what_to_check + WHEN @skip_waits = 1 + THEN 'waits skipped, @skip_waits set to 1' WHEN @what_to_check IN ('all', 'waits') THEN 'no significant waits found between ' + RTRIM(CONVERT(date, @start_date)) +