Find CPU from within SSMS

This is a great DMV if you don’t want to leave SSMS to see the CPU usage or if you don’t have access. What’s good about this method is it also shows you the history of the cpu usage.

[cc lang=”sql”]

declare @ts_now bigint

select @ts_now = cpu_ticks / (cpu_ticks/ms_ticks) 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 ‘%%’) as x

) as y

order by record_id desc

[/cc]

5 comments
Praveem 26 Dec 2017 at 4:56 pm

Hi,

I am running this SQL on a machine with 4 NUMA nodes and 96 logical cores.

This seems to return incorrect results for SQLProcessUtilization with values > 100.

Is there any work-around for this to determine the SQLProcessUtilization accurately?

Thanks.

sudhama 17 Nov 2014 at 4:21 pm

try by changing ‘VALUE’ to ‘value’

Tony Gallone 20 Feb 2017 at 4:11 pm

Change VALUE to value (lowercase), then it should run!

Sukhjinder 31 Oct 2014 at 5:30 am

Dieter, it gives error at record.VALUE function.
“VALUE” is not a valid function, property, or field.

Anitha 29 May 2014 at 10:37 am

Hi Derek,

Your scripts are simple and very handy.Keep Going.

Above script is not working in SQL 2008

getting below error

Msg 227, Level 15, State 1, Line 5
“VALUE” is not a valid function, property, or field.

I am a DBA and no idea on what should I do to get this off from my page. Please help

Featured Articles

 Site Author

  • Thanks for visiting!
css.php