Skip to content

Commit bbf1c6d

Browse files
doot doot
doot doot
1 parent eb779c7 commit bbf1c6d

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

sp_HumanEvents/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ ON SERVER
192192
| @log_schema_name | sysname | schema to store logging tables | a valid schema name | NULL |
193193
| @log_table_name_prefix| sysname | prefix for all logging tables | a valid table name prefix | 'HumanEventsBlockViewer' |
194194
| @log_retention_days | integer | Number of days to keep logs, 0 = keep indefinitely | a valid integer | 30 |
195+
| @max_blocking_events | bigint | maximum blocking events to analyze, 0 = unlimited | 0 to 9223372036854775807 | 5000 |
195196
| @help | bit | how you got here | 0 or 1 | 0 |
196197
| @debug | bit | dumps raw temp table contents | 0 or 1 | 0 |
197198
| @version | varchar | OUTPUT; for support | none; OUTPUT | none; OUTPUT |

sp_HumanEvents/sp_HumanEventsBlockViewer.sql

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ DECLARE
343343
@log_database_schema nvarchar(1024),
344344
@max_event_time datetime2(7),
345345
@dsql nvarchar(max) = N'',
346-
@mdsql nvarchar(max) = N'';
346+
@mdsql nvarchar(max) = N'',
347+
@actual_start_date datetime2(7),
348+
@actual_end_date datetime2(7),
349+
@actual_event_count bigint;
347350

348351
/*Use some sane defaults for input parameters*/
349352
IF @debug = 1
@@ -2825,8 +2828,23 @@ BEGIN
28252828
ap.avg_worker_time_ms DESC
28262829
OPTION(RECOMPILE, LOOP JOIN, HASH JOIN);
28272830

2831+
/* Capture actual date range and event count from the data */
2832+
SELECT
2833+
@actual_start_date = MIN(event_time),
2834+
@actual_end_date = MAX(event_time),
2835+
@actual_event_count = COUNT_BIG(DISTINCT monitor_loop)
2836+
FROM #blocked
2837+
WHERE event_time IS NOT NULL;
2838+
2839+
/* Use original dates if no data found */
2840+
SELECT
2841+
@actual_start_date = ISNULL(@actual_start_date, @start_date_original),
2842+
@actual_end_date = ISNULL(@actual_end_date, @end_date_original),
2843+
@actual_event_count = ISNULL(@actual_event_count, 0);
2844+
28282845
IF @debug = 1
28292846
BEGIN
2847+
RAISERROR('Actual date range: %s to %s, Event count: %I64d', 0, 1, @actual_start_date, @actual_end_date, @actual_event_count) WITH NOWAIT;
28302848
RAISERROR('Inserting #block_findings, check_id -1', 0, 1) WITH NOWAIT;
28312849
END;
28322850

@@ -2845,7 +2863,13 @@ BEGIN
28452863
database_name = N'erikdarling.com',
28462864
object_name = N'sp_HumanEventsBlockViewer version ' + CONVERT(nvarchar(30), @version) + N'.',
28472865
finding_group = N'https://code.erikdarling.com',
2848-
finding = N'blocking for period ' + CONVERT(nvarchar(30), @start_date_original, 126) + N' through ' + CONVERT(nvarchar(30), @end_date_original, 126) + N'.',
2866+
finding = N'blocking events from ' + CONVERT(nvarchar(30), @actual_start_date, 126) + N' to ' + CONVERT(nvarchar(30), @actual_end_date, 126) +
2867+
N' (' + CONVERT(nvarchar(30), @actual_event_count) + N' total events' +
2868+
CASE
2869+
WHEN @max_blocking_events > 0 AND @actual_event_count >= @max_blocking_events
2870+
THEN N', limited to most recent ' + CONVERT(nvarchar(30), @max_blocking_events) + N')'
2871+
ELSE N')'
2872+
END + N'.',
28492873
1;
28502874

28512875
IF @debug = 1

0 commit comments

Comments
 (0)