-- by minsouk kim
-- 2012-03-21
select cpu_id, b.session_id, b.exec_context_id, e.blocking_session_id
, preemptive_switches_count, d.context_switches_count
, /*f.last_wait_type,*/g.wait_type,g.wait_duration_ms, g.blocking_exec_context_id,resource_description, task_state
, sql_handle, plan_handle
-- , a.*, b.*, c.*, d.*, e.*, f.*
from sys.dm_exec_sessions a -- 연결정보
join sys.dm_os_tasks b -- worker 와 연결하기위한 컨테이너
on a.session_id = b.session_id
join sys.dm_os_threads c -- windows thread 와 연결
on b.worker_address = c.worker_address
join sys.dm_os_schedulers d -- cpu 정보
on b.scheduler_id = d.scheduler_id
join sys.dm_os_workers f -- 실제 worker
on b.task_address = f.task_address
left join sys.dm_exec_requests e -- 요청중인 모든 세션을 볼 수 있음 (요청자 정보)
on b.task_address = e.task_address
left join sys.dm_os_waiting_tasks g
on b.task_address = g.waiting_task_address
where a.session_id > 50
order by b.session_id, b.exec_context_id