Skip to content

Commit dc90a41

Browse files
authored
Merge pull request BrentOzarULTD#3942 from BrentOzarULTD/claude/nostalgic-kowalevski
sp_BlitzWho: add @onlyproblems parameter
2 parents ed5762e + 90c2c69 commit dc90a41

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

sp_BlitzFirst.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ DECLARE @StringToExecute NVARCHAR(MAX),
134134
@OutputTableNameWaitStats_Categories NVARCHAR(256),
135135
@OutputTableCleanupDate DATE,
136136
@ObjectFullName NVARCHAR(2000),
137-
@BlitzWho NVARCHAR(MAX) = N'EXEC dbo.sp_BlitzWho @ShowSleepingSPIDs = ' + CONVERT(NVARCHAR(1), @ShowSleepingSPIDs) + N';',
137+
@BlitzWho NVARCHAR(MAX) = N'EXEC dbo.sp_BlitzWho @ShowSleepingSPIDs = ' + CONVERT(NVARCHAR(1), @ShowSleepingSPIDs) + CASE WHEN @ExpertMode = 3 THEN N', @OnlyProblems = 1' ELSE N'' END + N';',
138138
@BlitzCacheMinutesBack INT,
139139
@UnquotedOutputServerName NVARCHAR(256) = @OutputServerName ,
140140
@UnquotedOutputDatabaseName NVARCHAR(256) = @OutputDatabaseName ,
@@ -280,7 +280,7 @@ END; /* IF @AsOf IS NOT NULL AND @OutputDatabaseName IS NOT NULL AND @OutputSche
280280
ELSE IF @LogMessage IS NULL /* IF @OutputType = 'SCHEMA' */
281281
BEGIN
282282
/* What's running right now? This is the first and last result set. */
283-
IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode = 1 AND @OutputType <> 'NONE' AND @OutputResultSets LIKE N'%BlitzWho_Start%'
283+
IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode IN (1, 3) AND @OutputType <> 'NONE' AND @OutputResultSets LIKE N'%BlitzWho_Start%'
284284
BEGIN
285285
IF OBJECT_ID('master.dbo.sp_BlitzWho') IS NULL AND OBJECT_ID('dbo.sp_BlitzWho') IS NULL
286286
BEGIN
@@ -290,7 +290,7 @@ BEGIN
290290
BEGIN
291291
EXEC (@BlitzWho);
292292
END;
293-
END; /* IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode = 1 AND @OutputType <> 'NONE' - What's running right now? This is the first and last result set. */
293+
END; /* IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode IN (1, 3) AND @OutputType <> 'NONE' - What's running right now? This is the first and last result set. */
294294

295295
/* Set start/finish times AFTER sp_BlitzWho runs. For more info: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/issues/2244 */
296296
IF @Seconds = 0 AND SERVERPROPERTY('EngineEdition') = 5 /*SERVERPROPERTY('Edition') = 'SQL Azure'*/
@@ -5372,7 +5372,7 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
53725372
DROP TABLE #BlitzFirstResults;
53735373

53745374
/* What's running right now? This is the first and last result set. */
5375-
IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode = 1 AND @OutputType <> 'NONE' AND @OutputResultSets LIKE N'%BlitzWho_End%'
5375+
IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode IN (1, 3) AND @OutputType <> 'NONE' AND @OutputResultSets LIKE N'%BlitzWho_End%'
53765376
BEGIN
53775377
IF OBJECT_ID('master.dbo.sp_BlitzWho') IS NULL AND OBJECT_ID('dbo.sp_BlitzWho') IS NULL
53785378
BEGIN
@@ -5382,7 +5382,7 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
53825382
BEGIN
53835383
EXEC (@BlitzWho);
53845384
END;
5385-
END; /* IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode = 1 AND @OutputType <> 'NONE' - What's running right now? This is the first and last result set. */
5385+
END; /* IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode IN (1, 3) AND @OutputType <> 'NONE' - What's running right now? This is the first and last result set. */
53865386

53875387
END; /* IF @LogMessage IS NULL */
53885388
END; /* ELSE IF @OutputType = 'SCHEMA' */

sp_BlitzWho.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ ALTER PROCEDURE dbo.sp_BlitzWho
5757
@Version VARCHAR(30) = NULL OUTPUT,
5858
@VersionDate DATETIME = NULL OUTPUT,
5959
@VersionCheckMode BIT = 0,
60-
@SortOrder NVARCHAR(256) = N'elapsed time'
60+
@SortOrder NVARCHAR(256) = N'elapsed time',
61+
@OnlyProblems BIT = 0
6162
AS
6263
BEGIN
6364
SET NOCOUNT ON;
@@ -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(s.open_transaction_count, 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)