Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Feb 16 '13 at 21:48

This question came from our site for professional and enthusiast programmers.

    
SQL Server Profiler is your friend - msdn.microsoft.com/en-us/library/ms181091.aspx. While you can trace individual queries running analysis on the whole system under real load is more useful as it helps identify locking contention and other perf issues that isolated testing might not find –  Offbeatmammal Feb 16 '13 at 4:11

1 Answer 1

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...

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;
share|improve this answer
    
Prior to SQL Server 2008 (where the sys.dm_exec_procedure_stats DMV first appeared), you can write a similar query that joins sys.dm_exec_cached_plans with sys.dm_exec_query_stats‌​. –  Paul White Feb 17 '13 at 3:56
    
Thanks I had checked this DMV but in this environment the server seems to be restarted very often. Atleast once in a week is what I understand. So was not very sure how much to trust the output of DMVs. May be would it help to persist this output into a table on a daily basis? –  prasanth Feb 18 '13 at 2:52
    
Aren't tracing on a heavily loaded production server going to be costly? Because we are talking about collecting the complete work load. OR is there an efficient way of doing it? –  prasanth Feb 18 '13 at 2:56
    
3rd party monitoring tools (such as SQL Sentry's Power Suite) go to great lengths to minimize the overhead of collecting this data, and I guarantee our collection has less impact than anything you would cobble together to collect the same data at the same frequency. Disclaimer: I work for SQL Sentry. –  Aaron Bertrand Feb 18 '13 at 16:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.