patternsqlModerate
Stored procedure performance metrics
Viewed 0 times
storedmetricsperformanceprocedure
Problem
I am taking over a new project which is having ~2500 SPs! and would like to know at current state what is the maximum / minimum time taken by each of the stored procs. Also IO, Logical Reads used by each of the SPs. Would like to benchmark it that way. After each new drop would use this benchmark to compare whether the changes done has helped or not.
Can DMVs or Extended Events be of help here? or do i need to run a trace covering my complete work load to capture this?
Can DMVs or Extended Events be of help here? or do i need to run a trace covering my complete work load to capture this?
Solution
This will get you the top 100 with the highest average duration since the last service restart. This DMV is reset when SQL Server restarts, so if you need to go beyond that, you'll need to trace, use extended events, use auditing of some kind (built-in or manual), or invest in a 3rd party monitoring tool.
You can adjust that obviously, or go after different metrics such as physical or logical reads...
You can adjust that obviously, or go after different metrics such as physical or logical reads...
USE [Your Database Name];
GO
SELECT TOP (100)
OBJECT_SCHEMA_NAME([object_id]),
OBJECT_NAME([object_id]),
type_desc,
cached_time,
last_execution_time,
execution_count,
total_worker_time,
last_worker_time,
min_worker_time,
max_worker_time,
total_physical_reads,
last_physical_reads,
min_physical_reads,
max_physical_reads,
total_logical_writes,
last_logical_writes,
min_logical_writes,
max_logical_writes,
total_logical_reads,
last_logical_reads,
min_logical_reads,
max_logical_reads,
total_elapsed_time,
last_elapsed_time,
min_elapsed_time,
max_elapsed_time
FROM sys.dm_exec_procedure_stats
WHERE DB_NAME(database_id) = N'Your Database Name'
ORDER BY total_elapsed_time / execution_count DESC;Code Snippets
USE [Your Database Name];
GO
SELECT TOP (100)
OBJECT_SCHEMA_NAME([object_id]),
OBJECT_NAME([object_id]),
type_desc,
cached_time,
last_execution_time,
execution_count,
total_worker_time,
last_worker_time,
min_worker_time,
max_worker_time,
total_physical_reads,
last_physical_reads,
min_physical_reads,
max_physical_reads,
total_logical_writes,
last_logical_writes,
min_logical_writes,
max_logical_writes,
total_logical_reads,
last_logical_reads,
min_logical_reads,
max_logical_reads,
total_elapsed_time,
last_elapsed_time,
min_elapsed_time,
max_elapsed_time
FROM sys.dm_exec_procedure_stats
WHERE DB_NAME(database_id) = N'Your Database Name'
ORDER BY total_elapsed_time / execution_count DESC;Context
StackExchange Database Administrators Q#34867, answer score: 10
Revisions (0)
No revisions yet.