首页 > 其他 > 详细

convert Timestamp to Real time

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!