SQL Server 环形缓冲区(Ring Buffer) -- RING_BUFFER_SCHEDULER_MONITOR 获取SQL

SQL Server 环形缓冲区(Ring Buffer) -- RING_BUFFER_SCHEDULER_MONITOR 获取SQL进程的CPU利用率

环形缓冲区存储了有关CPU利用率的信息。这些信息每分钟更新一次。所以你可以跟踪到4小时15分钟内给定时间点的CPU利用率。下面的输出显示了SQL实例的CPU利用率和其他活动进程的CPU利用率。这将帮助我们分析是否SQL Server进程占用大量CPU。

 

clip_image001

 

对于SQL Server 2005:

 

declare @ts_now bigint
select @ts_now = cpu_ticks / convert(float, cpu_ticks_in_ms) from sys.dm_os_sys_info
select record_id,
dateadd(ms, -1 * (@ts_now - [timestamp]), GetDate()) as EventTime,
SQLProcessUtilization,
SystemIdle,
100 - SystemIdle - SQLProcessUtilization as OtherProcessUtilization
from (
select
record.value('(./Record/@id)[1]', 'int') as record_id,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') as SystemIdle,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 'int') as SQLProcessUtilization,
timestamp
from (
select timestamp, convert(xml, record) as record
from sys.dm_os_ring_buffers
where ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
and record like '%<SystemHealth>%') as x
) as y
order by record_id desc

 

对于SQL Server 2008:

 

declare @ts_now bigint
select @ts_now = ms_ticks from
sys.dm_os_sys_info
select record_id, dateadd (ms, (y.[timestamp] -@ts_now), GETDATE()) as EventTime,
SQLProcessUtilization,
SystemIdle,
100 - SystemIdle - SQLProcessUtilization as OtherProcessUtilization
from (
select
record.value('(./Record/@id)[1]', 'int') as record_id,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int')
as SystemIdle,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]',
'int') as SQLProcessUtilization,
timestamp
from (
select timestamp, convert(xml, record) as record
from sys.dm_os_ring_buffers
where ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
and record like '%<SystemHealth>%') as x
) as y
order by record_id desc

 

常用SQL脚本:

 

select   
   record    
  ,CAST(record AS XML)    
  ,CAST(record as XML).value('/Record[1]/SchedulerMonitorEvent[1]/SystemHealth[1]/MemoryUtilization[1]','int') as MemUtil    
  ,CAST(record as XML).value('/Record[1]/SchedulerMonitorEvent[1]/SystemHealth[1]/PageFaults[1]','int') as PageFaults    
   ,CAST(record as XML).value('/Record[1]/SchedulerMonitorEvent[1]/SystemHealth[1]/WorkingSetDelta[1]','int') as workingSetDelta    
    ,CAST(record as XML).value('/Record[1]/SchedulerMonitorEvent[1]/SystemHealth[1]/KernelModeTime[1]','int') as KernelModeTime    
    ,CAST(record as XML).value('/Record[1]/SchedulerMonitorEvent[1]/SystemHealth[1]/UserModeTime[1]','bigint') as UserModeTime    
    ,CAST(record as XML).value('/Record[1]/SchedulerMonitorEvent[1]/SystemHealth[1]/ProcessUtilization[1]','int') as ProcessUtilization    
    ,CAST(record as XML).value('/Record[1]/SchedulerMonitorEvent[1]/SystemHealth[1]/SystemIdle[1]','int') as SystemIdle    
  from sys.dm_os_ring_buffers    
 where    
  ring_buffer_type = 'RING_BUFFER_SCHEDULER_MONITOR'



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值