Created
December 29, 2019 18:22
-
-
Save hakanak/855b07c655d10cef9b363985fd441bb7 to your computer and use it in GitHub Desktop.
Performance Tuning Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH DB_CPU_STATS_ON_INSTANCE | |
AS | |
(SELECT DatabaseID, DB_Name(DatabaseID) AS [DatabaseName], SUM(total_worker_time) AS [CPU_Time_Ms] | |
FROM sys.dm_exec_query_stats AS qs | |
CROSS APPLY (SELECT CONVERT(int, value) AS [DatabaseID] | |
FROM sys.dm_exec_plan_attributes(qs.plan_handle) | |
WHERE attribute = N'dbid') AS F_DB | |
GROUP BY DatabaseID) | |
SELECT ROW_NUMBER() OVER(ORDER BY [CPU_Time_Ms] DESC) AS [row_num], | |
DatabaseName, [CPU_Time_Ms], | |
CAST([CPU_Time_Ms] * 1.0 / SUM([CPU_Time_Ms]) OVER() * 100.0 AS DECIMAL(5, 2)) AS [CPUPercent] | |
FROM DB_CPU_STATS_ON_INSTANCE | |
WHERE DatabaseID > 4 | |
AND DatabaseID <> 32767 | |
ORDER BY row_num OPTION (RECOMPILE); |
Author
hakanak
commented
Dec 29, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment