首页 > 代码库 > SQL Server 环形缓冲区(Ring Buffer) -- RING_BUFFER_SCHEDULER_MONITOR 获取SQL
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。
对于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‘
本文出自 “滴水石穿” 博客,请务必保留此出处http://ultrasql.blog.51cto.com/9591438/1583973
SQL Server 环形缓冲区(Ring Buffer) -- RING_BUFFER_SCHEDULER_MONITOR 获取SQL
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。