Skip to content

Instantly share code, notes, and snippets.

@yorek
Created August 25, 2014 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorek/e19cead532024da8457c to your computer and use it in GitHub Desktop.
Save yorek/e19cead532024da8457c to your computer and use it in GitHub Desktop.
Load and shows to top 25 highest wait stats taken in a period of 1 minute
if (object_id('tempdb..#t1') is not null) drop table #1
if (object_id('tempdb..#t2') is not null) drop table #2
go
select sample_date = sysdatetime(), * into #t1 from sys.dm_os_wait_stats
waitfor delay '00:00:01'
select sample_date = sysdatetime(), * into #t2 from sys.dm_os_wait_stats
go
select top 25
from_date = b.sample_date,
to_date = e.sample_date,
e.wait_type,
waiting_tasks_count = e.waiting_tasks_count - b.waiting_tasks_count,
wait_time_ms = e.wait_time_ms - b.wait_time_ms,
max_wait_time_ms = e.max_wait_time_ms - b.max_wait_time_ms,
signal_wait_time_ms = e.signal_wait_time_ms - b.signal_wait_time_ms
from
#t1 b inner join #t2 e on
b.wait_type = e.wait_type
where
e.wait_type not in (N'SOS_SCHEDULER_YIELD', N'CLR_SEMAPHORE', N'LAZYWRITER_SLEEP', N'RESOURCE_QUEUE',N'SLEEP_TASK',
N'SLEEP_SYSTEMTASK', N'SQLTRACE_BUFFER_FLUSH', N'WAITFOR', N'LOGMGR_QUEUE',
N'CHECKPOINT_QUEUE', N'REQUEST_FOR_DEADLOCK_SEARCH', N'XE_TIMER_EVENT',
N'BROKER_TO_FLUSH', N'BROKER_TASK_STOP', N'CLR_MANUAL_EVENT', N'CLR_AUTO_EVENT',
N'DISPATCHER_QUEUE_SEMAPHORE' ,N'FT_IFTS_SCHEDULER_IDLE_WAIT', N'XE_DISPATCHER_WAIT',
N'XE_DISPATCHER_JOIN', N'SQLTRACE_INCREMENTAL_FLUSH_SLEEP', N'ONDEMAND_TASK_QUEUE',
N'BROKER_EVENTHANDLER', N'SLEEP_BPOOL_FLUSH', N'SLEEP_DBSTARTUP', N'DIRTY_PAGE_POLL',
N'HADR_FILESTREAM_IOMGR_IOCOMPLETION',N'SP_SERVER_DIAGNOSTICS_SLEEP')
order by
wait_time_ms desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment