Posts tonen met het label CPU. Alle posts tonen
Posts tonen met het label CPU. Alle posts tonen

zaterdag 1 maart 2014

Relative load per DB in CPU, IO and CLR

What is the relative load per DB in CPU, IO and CLR?

[sql]
--****************************************************************************************
-- What is the relative load per DB in CPU, IO and CLR
--****************************************************************************************
-- Versie: 1.0
-- Author: Theo Ekelmans
-- Date: 2009-06-11
--
--****************************************************************************************
USE master
SELECT a.[value] AS [dbid]
, ISNULL(DB_NAME(CONVERT(INT,a.[value])),'Resource') AS [DB Name]
, SUM(qs.[execution_count]) AS [Counts]
, SUM(qs.[total_worker_time]) / 1000 AS [Total Worker Time (mSecs)]
, SUM(qs.[total_physical_reads]) AS [Total Physical Reads]
, SUM(qs.[total_logical_reads]) AS [Total Logical Reads]
, SUM(qs.[total_logical_writes]) AS [Total Logical Writes]
, SUM(qs.[total_clr_time]) / 1000 AS [Total CLR Time (mSecs)]
, SUM(qs.[total_elapsed_time]) / 1000 AS [Total Elapsed Time (mSecs)]
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_plan_attributes(qs.Plan_handle) AS a
WHERE a.[attribute] = 'dbid'
GROUP BY [value], ISNULL(DB_NAME(CONVERT(INT,a.[value])),'Resource')
ORDER BY [Total Worker Time (mSecs)] DESC
[/sql]

CPU history (256 minutes)

Show the CPU load in last 256 minutes

[sql]
/*
Description : Show the CPU load in last 256 minutes
Note : For SQL 2012 replace "cpu_ticks / 1000" by "cpu_ticks_in_ms / 1000"
Author : Theo Ekelmans
Version/Date : 1.0 2013-03-23
*/


SELECT Dateadd(ms, -1 * ( cpu_ticks / ( cpu_ticks / ms_ticks ) - [timestamp] ), Getdate()) AS DT
,CAST(( 1.0 * ms_ticks / ( 24 * 60 * 60 * 1000 ) ) AS DECIMAL(10, 2)) AS system_uptime_days
,cpu_count
,cpu_ticks / 1000 AS cpu_MHz
,hyperthread_ratio
,SQLProcessUtilization
,100 - SystemIdle - SQLProcessUtilization AS OtherProcessUtilization
,SystemIdle
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
--top 1
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>%'
--order by timestamp desc
) AS x) AS y,
sys.dm_os_sys_info
ORDER BY timestamp DESC


[/sql]