Skip to content

Commit

Permalink
#3504 sp_BlitzFirst Azure SQL DB
Browse files Browse the repository at this point in the history
More accurate startup time detection. Closes #3504.
  • Loading branch information
BrentOzar committed Apr 19, 2024
1 parent 58d491e commit 62152b1
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions sp_BlitzFirst.sql
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,23 @@ BEGIN

/* Set start/finish times AFTER sp_BlitzWho runs. For more info: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/issues/2244 */
IF @Seconds = 0 AND SERVERPROPERTY('EngineEdition') = 5 /*SERVERPROPERTY('Edition') = 'SQL Azure'*/
WITH WaitTimes AS (
SELECT wait_type, wait_time_ms,
NTILE(3) OVER(ORDER BY wait_time_ms) AS grouper
FROM sys.dm_os_wait_stats w
WHERE wait_type IN ('DIRTY_PAGE_POLL','HADR_FILESTREAM_IOMGR_IOCOMPLETION','LAZYWRITER_SLEEP',
'LOGMGR_QUEUE','REQUEST_FOR_DEADLOCK_SEARCH','XE_TIMER_EVENT')
)
SELECT @StartSampleTime = DATEADD(mi, AVG(-wait_time_ms / 1000 / 60), SYSDATETIMEOFFSET()), @FinishSampleTime = SYSDATETIMEOFFSET()
FROM WaitTimes
WHERE grouper = 2;
BEGIN
/* Use the most accurate (but undocumented) DMV if it's available: */
IF EXISTS(SELECT * FROM sys.all_columns ac WHERE ac.object_id = OBJECT_ID('sys.dm_cloud_database_epoch') AND ac.name = 'last_role_transition_time')
SELECT @StartSampleTime = DATEADD(MINUTE,DATEDIFF(MINUTE, GETDATE(), GETUTCDATE()),last_role_transition_time) , @FinishSampleTime = SYSDATETIMEOFFSET()
FROM sys.dm_cloud_database_epoch;
ELSE
WITH WaitTimes AS (
SELECT wait_type, wait_time_ms,
NTILE(3) OVER(ORDER BY wait_time_ms) AS grouper
FROM sys.dm_os_wait_stats w
WHERE wait_type IN ('DIRTY_PAGE_POLL','HADR_FILESTREAM_IOMGR_IOCOMPLETION','LAZYWRITER_SLEEP',
'LOGMGR_QUEUE','REQUEST_FOR_DEADLOCK_SEARCH','XE_TIMER_EVENT')
)
SELECT @StartSampleTime = DATEADD(mi, AVG(-wait_time_ms / 1000 / 60), SYSDATETIMEOFFSET()), @FinishSampleTime = SYSDATETIMEOFFSET()
FROM WaitTimes
WHERE grouper = 2;
END
ELSE IF @Seconds = 0 AND SERVERPROPERTY('EngineEdition') <> 5 /*SERVERPROPERTY('Edition') <> 'SQL Azure'*/
SELECT @StartSampleTime = DATEADD(MINUTE,DATEDIFF(MINUTE, GETDATE(), GETUTCDATE()),create_date) , @FinishSampleTime = SYSDATETIMEOFFSET()
FROM sys.databases
Expand Down

0 comments on commit 62152b1

Please sign in to comment.