Skip to content

Commit 99e82ab

Browse files
BrentOzarclaude
andcommitted
sp_BlitzWho: add @onlyproblems parameter
Adds @onlyproblems BIT = 0 so users can restrict output to sessions that are actually problematic: blocking or blocked, waiting on something, sleeping with an open transaction, or running >= 30 seconds. Default 0 preserves current behavior. Fixes BrentOzarULTD#3941 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ed5762e commit 99e82ab

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

sp_BlitzWho.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ALTER PROCEDURE dbo.sp_BlitzWho
5050
@MinTempdbMB INT = 0 ,
5151
@MinRequestedMemoryKB INT = 0 ,
5252
@MinBlockingSeconds INT = 0 ,
53+
@OnlyProblems BIT = 0 ,
5354
@CheckDateOverride DATETIMEOFFSET = NULL,
5455
@ShowActualParameters BIT = 0,
5556
@GetOuterCommand BIT = 0,
@@ -941,6 +942,18 @@ IF (@MinElapsedSeconds + @MinCPUTime + @MinLogicalReads + @MinPhysicalReads + @M
941942
SET @StringToExecute += N' ) ';
942943
END
943944

945+
IF @OnlyProblems = 1
946+
BEGIN
947+
/* Only show queries that are blocking, blocked, waiting, sleeping with an open transaction, or running >= 30 seconds. */
948+
SET @StringToExecute += N' AND (
949+
r.blocking_session_id <> 0
950+
OR blocked.session_id IS NOT NULL
951+
OR wt.wait_info IS NOT NULL
952+
OR (s.status = ''sleeping'' AND COALESCE(r.open_transaction_count, blocked.open_tran, 0) >= 1)
953+
OR ABS(COALESCE(r.total_elapsed_time, 0)) / 1000 >= 30
954+
) ';
955+
END
956+
944957
SET @StringToExecute +=
945958
N' ORDER BY ' + CASE WHEN @SortOrder = 'session_id' THEN '[session_id] DESC'
946959
WHEN @SortOrder = 'query_cost' THEN '[query_cost] DESC'

0 commit comments

Comments
 (0)