Skip to content

Commit 24043ab

Browse files
Merge pull request #632 from ReeceGoding/dev
Made sp_HumanEventsBlockViewer able to use the ring buffer for system_health.
2 parents 3006a51 + c5d0a7a commit 24043ab

1 file changed

Lines changed: 52 additions & 17 deletions

File tree

sp_HumanEvents/sp_HumanEventsBlockViewer.sql

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,12 @@ CREATE TABLE
878878
sort_order bigint
879879
);
880880

881+
CREATE TABLE
882+
#sp_server_diagnostics_component_result
883+
(
884+
sp_server_diagnostics_component_result xml
885+
);
886+
881887
IF LOWER(@target_type) = N'table'
882888
BEGIN
883889
GOTO TableMode;
@@ -962,9 +968,11 @@ BEGIN
962968
END;
963969
END;
964970

965-
/* Dump whatever we got into a temp table */
971+
/*
972+
Dump whatever we got into a temp table
973+
Note that system_health hits this branch if we use the ring_buffer target.
974+
*/
966975
IF LOWER(@target_type) = N'ring_buffer'
967-
AND @is_system_health = 0
968976
BEGIN
969977
IF @azure = 0
970978
BEGIN
@@ -1205,24 +1213,51 @@ IF @is_system_health = 1
12051213
BEGIN
12061214
IF @debug = 1
12071215
BEGIN
1208-
RAISERROR('Inserting to #sp_server_diagnostics_component_result for system health: %s', 0, 1, @is_system_health_msg) WITH NOWAIT;
1216+
RAISERROR('Inserting to #sp_server_diagnostics_component_result for target type: %s and system health: %s', 0, 1, @target_type, @is_system_health_msg) WITH NOWAIT;
12091217
END;
12101218

1211-
SELECT
1212-
xml.sp_server_diagnostics_component_result
1213-
INTO #sp_server_diagnostics_component_result
1214-
FROM
1215-
(
1219+
IF @target_type = N'ring_buffer'
1220+
BEGIN
1221+
INSERT
1222+
#sp_server_diagnostics_component_result
1223+
WITH
1224+
(TABLOCKX)
1225+
(
1226+
sp_server_diagnostics_component_result
1227+
)
12161228
SELECT
1217-
sp_server_diagnostics_component_result =
1218-
TRY_CAST(fx.event_data AS xml)
1219-
FROM sys.fn_xe_file_target_read_file(N'system_health*.xel', NULL, NULL, NULL) AS fx
1220-
WHERE fx.object_name = N'sp_server_diagnostics_component_result'
1221-
) AS xml
1222-
CROSS APPLY xml.sp_server_diagnostics_component_result.nodes('/event') AS e(x)
1223-
WHERE e.x.exist('//data[@name="data"]/value/queryProcessing/blockingTasks/blocked-process-report') = 1
1224-
AND e.x.exist('@timestamp[. >= sql:variable("@start_date") and .< sql:variable("@end_date")]') = 1
1225-
OPTION(RECOMPILE);
1229+
sp_server_diagnostics_component_result = e.x.query('.')
1230+
FROM #x AS xml
1231+
CROSS APPLY xml.x.nodes('/RingBufferTarget/event') AS e(x)
1232+
WHERE e.x.exist('@name[ .= "sp_server_diagnostics_component_result"]') = 1
1233+
AND e.x.exist('//data[@name="data"]/value/queryProcessing/blockingTasks/blocked-process-report') = 1
1234+
AND e.x.exist('@timestamp[. >= sql:variable("@start_date") and .< sql:variable("@end_date")]') = 1
1235+
OPTION(RECOMPILE);
1236+
END
1237+
ELSE
1238+
BEGIN
1239+
INSERT
1240+
#sp_server_diagnostics_component_result
1241+
WITH
1242+
(TABLOCKX)
1243+
(
1244+
sp_server_diagnostics_component_result
1245+
)
1246+
SELECT
1247+
xml.sp_server_diagnostics_component_result
1248+
FROM
1249+
(
1250+
SELECT
1251+
sp_server_diagnostics_component_result =
1252+
TRY_CAST(fx.event_data AS xml)
1253+
FROM sys.fn_xe_file_target_read_file(N'system_health*.xel', NULL, NULL, NULL) AS fx
1254+
WHERE fx.object_name = N'sp_server_diagnostics_component_result'
1255+
) AS xml
1256+
CROSS APPLY xml.sp_server_diagnostics_component_result.nodes('/event') AS e(x)
1257+
WHERE e.x.exist('//data[@name="data"]/value/queryProcessing/blockingTasks/blocked-process-report') = 1
1258+
AND e.x.exist('@timestamp[. >= sql:variable("@start_date") and .< sql:variable("@end_date")]') = 1
1259+
OPTION(RECOMPILE);
1260+
END;
12261261

12271262
IF @debug = 1
12281263
BEGIN

0 commit comments

Comments
 (0)