|
52 | 52 | @rows_marked bigint = 0, |
53 | 53 | @rows_parsed bigint = 0, |
54 | 54 | @start_time datetime2(7) = SYSDATETIME(), |
| 55 | + @utc_offset_minutes integer = DATEDIFF(MINUTE, GETUTCDATE(), SYSDATETIME()), |
| 56 | + @start_date_local datetime2(7) = NULL, |
| 57 | + @end_date_local datetime2(7) = NULL, |
55 | 58 | @error_message nvarchar(4000), |
56 | 59 | @error_number integer, |
57 | 60 | @blockviewer_database sysname = NULL, |
@@ -136,23 +139,44 @@ BEGIN |
136 | 139 | AND bx.event_time IS NOT NULL |
137 | 140 | OPTION(RECOMPILE); |
138 | 141 |
|
| 142 | + /* |
| 143 | + Convert UTC event_time to local time for sp_HumanEventsBlockViewer |
| 144 | + The proc expects local time inputs and converts to UTC internally |
| 145 | + Raw table event_time is UTC (from XE @timestamp attribute) |
| 146 | + */ |
| 147 | + SELECT |
| 148 | + @start_date_local = DATEADD(MINUTE, @utc_offset_minutes, @start_date), |
| 149 | + @end_date_local = DATEADD(MINUTE, @utc_offset_minutes, @end_date); |
| 150 | + |
139 | 151 | IF @debug = 1 |
140 | 152 | BEGIN |
141 | | - SET @debug_msg = N'Derived date range from unprocessed rows: ' + ISNULL(CONVERT(nvarchar(30), @start_date, 121), N'NULL') + N' to ' + ISNULL(CONVERT(nvarchar(30), @end_date, 121), N'NULL'); |
| 153 | + SET @debug_msg = N'Derived date range (UTC): ' + ISNULL(CONVERT(nvarchar(30), @start_date, 121), N'NULL') + N' to ' + ISNULL(CONVERT(nvarchar(30), @end_date, 121), N'NULL'); |
| 154 | + RAISERROR(@debug_msg, 0, 1) WITH NOWAIT; |
| 155 | + SET @debug_msg = N'Converted to local: ' + ISNULL(CONVERT(nvarchar(30), @start_date_local, 121), N'NULL') + N' to ' + ISNULL(CONVERT(nvarchar(30), @end_date_local, 121), N'NULL'); |
142 | 156 | RAISERROR(@debug_msg, 0, 1) WITH NOWAIT; |
143 | 157 | END; |
144 | 158 | END; |
| 159 | + ELSE |
| 160 | + BEGIN |
| 161 | + /* |
| 162 | + User provided explicit dates (assumed local time) |
| 163 | + No conversion needed — pass through directly |
| 164 | + */ |
| 165 | + SELECT |
| 166 | + @start_date_local = @start_date, |
| 167 | + @end_date_local = @end_date; |
| 168 | + END; |
145 | 169 |
|
146 | 170 | /* |
147 | 171 | Delete existing parsed blocking events for the time range to prevent duplicates |
148 | 172 | sp_HumanEventsBlockViewer will re-insert fresh parsed data |
149 | 173 | */ |
150 | | - IF @start_date IS NOT NULL AND @end_date IS NOT NULL |
| 174 | + IF @start_date_local IS NOT NULL AND @end_date_local IS NOT NULL |
151 | 175 | BEGIN |
152 | 176 | DELETE b |
153 | 177 | FROM collect.blocking_BlockedProcessReport AS b |
154 | | - WHERE b.event_time >= @start_date |
155 | | - AND b.event_time <= @end_date; |
| 178 | + WHERE b.event_time >= @start_date_local |
| 179 | + AND b.event_time <= @end_date_local; |
156 | 180 |
|
157 | 181 | SELECT |
158 | 182 | @rows_deleted = ROWCOUNT_BIG(); |
@@ -192,19 +216,20 @@ BEGIN |
192 | 216 | N'@log_retention_days integer, @max_events_to_process integer, @start_date datetime2(7), @end_date datetime2(7), @debug bit', |
193 | 217 | @log_retention_days = @log_retention_days, |
194 | 218 | @max_events_to_process = @max_events_to_process, |
195 | | - @start_date = @start_date, |
196 | | - @end_date = @end_date, |
| 219 | + @start_date = @start_date_local, |
| 220 | + @end_date = @end_date_local, |
197 | 221 | @debug = @debug; |
198 | 222 |
|
199 | 223 | /* |
200 | 224 | Verify sp_HumanEventsBlockViewer produced parsed results before marking rows as processed |
201 | 225 | If no results were inserted, leave rows unprocessed so they are retried next run |
| 226 | + Parsed results use local time (sp_HumanEventsBlockViewer converts UTC to local) |
202 | 227 | */ |
203 | 228 | SELECT |
204 | 229 | @rows_parsed = COUNT_BIG(*) |
205 | 230 | FROM collect.blocking_BlockedProcessReport AS b |
206 | | - WHERE b.event_time >= @start_date |
207 | | - AND b.event_time <= @end_date |
| 231 | + WHERE b.event_time >= @start_date_local |
| 232 | + AND b.event_time <= @end_date_local |
208 | 233 | OPTION(RECOMPILE); |
209 | 234 |
|
210 | 235 | IF @rows_parsed > 0 |
|
0 commit comments