码迷,mamicode.com
首页 > 其他好文 > 详细

convert Timestamp to Real time

时间:2014-06-09 14:07:21      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   a   tar   color   

select r.ring_buffer_address,

r.ring_buffer_type,

dateadd (ms, r.[timestamp] - sysinfo.sqlserver_start_time_ms_ticks, sysinfo.sqlserver_start_time) as record_time,

cast(r.record as xml) record

from sys.dm_os_ring_buffers r

cross join sys.dm_os_sys_info sysinfo

where ring_buffer_type=‘RING_BUFFER_RESOURCE_MONITOR‘ 

order by 3 desc

 

select r.ring_buffer_address,

r.ring_buffer_type,

dateadd (ms, r.[timestamp] - sysinfo.ms_ticks, getdate()) as record_time,

cast(r.record as xml) record

from sys.dm_os_ring_buffers r

cross join sys.dm_os_sys_info sysinfo

where ring_buffer_type=‘RING_BUFFER_RESOURCE_MONITOR‘ 

order by 3 desc

 

DATEADD (ms, -1 * ((sys.cpu_ticks / sys.cpu_ticks_in_ms) - r.timestamp), GETDATE()) as record_time -- sys.cpu_ticks_in_ms 在2008R2中才有

 

DECLARE @ts_now bigint = (SELECT cpu_ticks/(cpu_ticks/ms_ticks) FROM sys.dm_os_sys_info);

SELECT TOP(2)

SQLProcessUtilization AS [SQL Server Process CPU Utilization],

SystemIdle AS [System Idle Process],

100 - SystemIdle - SQLProcessUtilization AS [Other Process CPU Utilization],

DATEADD(ms, -1 * (@ts_now - [timestamp]), GETDATE()) AS [Event Time] 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;

 

convert Timestamp to Real time,布布扣,bubuko.com

convert Timestamp to Real time

标签:des   c   style   a   tar   color   

原文地址:http://www.cnblogs.com/princessd8251/p/3776729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!