@@ -281,16 +281,23 @@ BEGIN
281281
282282 /* Set start/finish times AFTER sp_BlitzWho runs. For more info: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/issues/2244 */
283283 IF @Seconds = 0 AND SERVERPROPERTY (' EngineEdition' ) = 5 /* SERVERPROPERTY('Edition') = 'SQL Azure'*/
284- WITH WaitTimes AS (
285- SELECT wait_type, wait_time_ms,
286- NTILE (3 ) OVER (ORDER BY wait_time_ms) AS grouper
287- FROM sys .dm_os_wait_stats w
288- WHERE wait_type IN (' DIRTY_PAGE_POLL' ,' HADR_FILESTREAM_IOMGR_IOCOMPLETION' ,' LAZYWRITER_SLEEP' ,
289- ' LOGMGR_QUEUE' ,' REQUEST_FOR_DEADLOCK_SEARCH' ,' XE_TIMER_EVENT' )
290- )
291- SELECT @StartSampleTime = DATEADD (mi, AVG (- wait_time_ms / 1000 / 60 ), SYSDATETIMEOFFSET ()), @FinishSampleTime = SYSDATETIMEOFFSET ()
292- FROM WaitTimes
293- WHERE grouper = 2 ;
284+ BEGIN
285+ /* Use the most accurate (but undocumented) DMV if it's available: */
286+ 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' )
287+ SELECT @StartSampleTime = DATEADD (MINUTE,DATEDIFF (MINUTE, GETDATE (), GETUTCDATE ()),last_role_transition_time) , @FinishSampleTime = SYSDATETIMEOFFSET ()
288+ FROM sys .dm_cloud_database_epoch ;
289+ ELSE
290+ WITH WaitTimes AS (
291+ SELECT wait_type, wait_time_ms,
292+ NTILE (3 ) OVER (ORDER BY wait_time_ms) AS grouper
293+ FROM sys .dm_os_wait_stats w
294+ WHERE wait_type IN (' DIRTY_PAGE_POLL' ,' HADR_FILESTREAM_IOMGR_IOCOMPLETION' ,' LAZYWRITER_SLEEP' ,
295+ ' LOGMGR_QUEUE' ,' REQUEST_FOR_DEADLOCK_SEARCH' ,' XE_TIMER_EVENT' )
296+ )
297+ SELECT @StartSampleTime = DATEADD (mi, AVG (- wait_time_ms / 1000 / 60 ), SYSDATETIMEOFFSET ()), @FinishSampleTime = SYSDATETIMEOFFSET ()
298+ FROM WaitTimes
299+ WHERE grouper = 2 ;
300+ END
294301 ELSE IF @Seconds = 0 AND SERVERPROPERTY (' EngineEdition' ) <> 5 /* SERVERPROPERTY('Edition') <> 'SQL Azure'*/
295302 SELECT @StartSampleTime = DATEADD (MINUTE,DATEDIFF (MINUTE, GETDATE (), GETUTCDATE ()),create_date) , @FinishSampleTime = SYSDATETIMEOFFSET ()
296303 FROM sys .databases
0 commit comments