Skip to content

Commit 6302827

Browse files
authored
Merge pull request #3526 from erikdarlingdata/issue_3525
Adds DeadlockType parameter for filtering to regular or parallel deadlocks
2 parents ffc7d39 + bb963e5 commit 6302827

File tree

1 file changed

+58
-41
lines changed

1 file changed

+58
-41
lines changed

sp_BlitzLock.sql

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ ALTER PROCEDURE
1818
@EventSessionName sysname = N'system_health',
1919
@TargetSessionType sysname = NULL,
2020
@VictimsOnly bit = 0,
21-
@Debug bit = 0,
21+
@DeadlockType nvarchar(20) = NULL,
22+
@Debug bit = 0,
2223
@Help bit = 0,
2324
@Version varchar(30) = NULL OUTPUT,
2425
@VersionDate datetime = NULL OUTPUT,
@@ -198,7 +199,7 @@ BEGIN
198199
@StartDateOriginal datetime = @StartDate,
199200
@EndDateOriginal datetime = @EndDate,
200201
@StartDateUTC datetime,
201-
@EndDateUTC datetime;
202+
@EndDateUTC datetime;;
202203

203204
/*Temporary objects used in the procedure*/
204205
DECLARE
@@ -708,50 +709,63 @@ BEGIN
708709
END CATCH;
709710
END;
710711

712+
IF @DeadlockType IS NOT NULL
713+
BEGIN
714+
SELECT
715+
@DeadlockType =
716+
CASE
717+
WHEN LOWER(@DeadlockType) LIKE 'regular%'
718+
THEN N'Regular Deadlock'
719+
WHEN LOWER(@DeadlockType) LIKE N'parallel%'
720+
THEN N'Parallel Deadlock'
721+
ELSE NULL
722+
END;
723+
END;
724+
711725
/*If @TargetSessionType, we need to figure out if it's ring buffer or event file*/
712726
/*Azure has differently named views, so we need to separate. Thanks, Azure.*/
713727

714-
IF
715-
(
716-
@Azure = 0
717-
AND @TargetSessionType IS NULL
718-
)
719-
BEGIN
720-
RAISERROR('@TargetSessionType is NULL, assigning for non-Azure instance', 0, 1) WITH NOWAIT;
721-
722-
SELECT TOP (1)
723-
@TargetSessionType = t.target_name
724-
FROM sys.dm_xe_sessions AS s
725-
JOIN sys.dm_xe_session_targets AS t
726-
ON s.address = t.event_session_address
727-
WHERE s.name = @EventSessionName
728-
AND t.target_name IN (N'event_file', N'ring_buffer')
729-
ORDER BY t.target_name
730-
OPTION(RECOMPILE);
731-
732-
RAISERROR('@TargetSessionType assigned as %s for non-Azure', 0, 1, @TargetSessionType) WITH NOWAIT;
733-
END;
728+
IF
729+
(
730+
@Azure = 0
731+
AND @TargetSessionType IS NULL
732+
)
733+
BEGIN
734+
RAISERROR('@TargetSessionType is NULL, assigning for non-Azure instance', 0, 1) WITH NOWAIT;
735+
736+
SELECT TOP (1)
737+
@TargetSessionType = t.target_name
738+
FROM sys.dm_xe_sessions AS s
739+
JOIN sys.dm_xe_session_targets AS t
740+
ON s.address = t.event_session_address
741+
WHERE s.name = @EventSessionName
742+
AND t.target_name IN (N'event_file', N'ring_buffer')
743+
ORDER BY t.target_name
744+
OPTION(RECOMPILE);
734745

735-
IF
736-
(
737-
@Azure = 1
738-
AND @TargetSessionType IS NULL
739-
)
740-
BEGIN
741-
RAISERROR('@TargetSessionType is NULL, assigning for Azure instance', 0, 1) WITH NOWAIT;
746+
RAISERROR('@TargetSessionType assigned as %s for non-Azure', 0, 1, @TargetSessionType) WITH NOWAIT;
747+
END;
742748

743-
SELECT TOP (1)
744-
@TargetSessionType = t.target_name
745-
FROM sys.dm_xe_database_sessions AS s
746-
JOIN sys.dm_xe_database_session_targets AS t
747-
ON s.address = t.event_session_address
748-
WHERE s.name = @EventSessionName
749-
AND t.target_name IN (N'event_file', N'ring_buffer')
750-
ORDER BY t.target_name
751-
OPTION(RECOMPILE);
749+
IF
750+
(
751+
@Azure = 1
752+
AND @TargetSessionType IS NULL
753+
)
754+
BEGIN
755+
RAISERROR('@TargetSessionType is NULL, assigning for Azure instance', 0, 1) WITH NOWAIT;
756+
757+
SELECT TOP (1)
758+
@TargetSessionType = t.target_name
759+
FROM sys.dm_xe_database_sessions AS s
760+
JOIN sys.dm_xe_database_session_targets AS t
761+
ON s.address = t.event_session_address
762+
WHERE s.name = @EventSessionName
763+
AND t.target_name IN (N'event_file', N'ring_buffer')
764+
ORDER BY t.target_name
765+
OPTION(RECOMPILE);
752766

753-
RAISERROR('@TargetSessionType assigned as %s for Azure', 0, 1, @TargetSessionType) WITH NOWAIT;
754-
END;
767+
RAISERROR('@TargetSessionType assigned as %s for Azure', 0, 1, @TargetSessionType) WITH NOWAIT;
768+
END;
755769

756770

757771
/*The system health stuff gets handled different from user extended events.*/
@@ -3449,7 +3463,8 @@ BEGIN
34493463
AND (d.client_app = @AppName OR @AppName IS NULL)
34503464
AND (d.host_name = @HostName OR @HostName IS NULL)
34513465
AND (d.login_name = @LoginName OR @LoginName IS NULL)
3452-
OPTION (RECOMPILE, LOOP JOIN, HASH JOIN);
3466+
AND (d.deadlock_type = @DeadlockType OR @DeadlockType IS NULL)
3467+
OPTION (RECOMPILE, LOOP JOIN, HASH JOIN);
34533468

34543469
UPDATE d
34553470
SET d.inputbuf =
@@ -4063,6 +4078,8 @@ BEGIN
40634078
@TargetSessionType,
40644079
VictimsOnly =
40654080
@VictimsOnly,
4081+
DeadlockType =
4082+
@DeadlockType,
40664083
Debug =
40674084
@Debug,
40684085
Help =

0 commit comments

Comments
 (0)