Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log Sql server stored procedure start and end time

I have overloaded SQL Server, and I want to make some optimization.

For that purpose I'd like to get some statistics about the start and the finish time of the called stored procedures.

Is there any system table, or maybe other item, where I can get this information from?

like image 616
Johnny_D Avatar asked Jul 20 '11 13:07

Johnny_D


1 Answers

SELECT 
    [procedure] = QUOTENAME(OBJECT_SCHEMA_NAME([object_id]))
        + '.' + QUOTENAME(OBJECT_NAME([object_id])),
    last_execution_time,
    avg_execution_time = CONVERT(DECIMAL(30,2), total_worker_time * 1.0 / execution_count),
    max_worker_time
FROM sys.dm_exec_procedure_stats
WHERE database_id = DB_ID()
ORDER BY avg_execution_time DESC;
like image 94
Aaron Bertrand Avatar answered Sep 23 '22 01:09

Aaron Bertrand