This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing one TSQL script to find top 20 Stored Procedures, which are utilizing more CPU time and degrade the performance of SQL Server.
The database performance optimization is one the most important task for Database Professionals.
We have found that many times SQL Server occupying more CPU resources and at that time it is required to find which stored procedure is occupying more CPU resources.
I am using sys.dm_exec_procedure_stats to find CPU used by all the stored procedures.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
SELECT TOP 20 DB_NAME(database_id) AS DatabaseName ,OBJECT_SCHEMA_NAME(object_id,database_id) AS SchemaName ,OBJECT_NAME(object_id,database_id)AS ObjectName ,cached_time AS CachedTime ,last_execution_time AS LastExecutionTime ,execution_count AS TotalNumberOfExecution ,(total_worker_time / execution_count) AS AverageCPUTime ,(total_elapsed_time / execution_count) AS AverageElapsedTime ,(total_logical_reads / execution_count) AS AverageLogicalReads ,(total_logical_writes / execution_count) AS AverageLogicalWrites ,(total_physical_reads / execution_count) AS AveragePhysicalReads FROM sys.dm_exec_procedure_stats ORDER BY AverageLogicalReads DESC |