Submit a ticketCall us

Get a crash course on Network Monitoring delivered right to your inbox
This free 7-day email course provides a primer to the philosophy, theory, and fundamental concepts involved in IT monitoring. Lessons will explain not only how to perform various monitoring tasks, but why and when you should use them. Sign up now.

Home > Success Center > Network Performance Monitor (NPM) > Determine which Stored Procedure is using the most CPU, I/O, or has the longest duration

Determine which Stored Procedure is using the most CPU, I/O, or has the longest duration

Table of contents
Created by Wendell Bazile, last modified by Rodim Suarez on Aug 26, 2016

Views: 13 Votes: 0 Revisions: 4

Overview

Determine which Stored Procedure is using the most CPU, I/O, or has the longest duration.

Environment

All Orion based applications

Steps

Attach to the database via Database Manager or SQL Management Studio and run the following query:

SELECT DB_NAME(st.dbid) DBName

      ,OBJECT_SCHEMA_NAME(st.objectid,dbid) SchemaName

      ,OBJECT_NAME(st.objectid,dbid) StoredProcedure

      ,max(cp.usecounts) Execution_count

      ,sum(qs.total_worker_time) total_cpu_time

      ,sum(qs.total_worker_time) / (max(cp.usecounts) * 1.0)  avg_cpu_time

 

 FROM sys.dm_exec_cached_plans cp join sys.dm_exec_query_stats qs on cp.plan_handle = qs.plan_handle

      CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) st

 where DB_NAME(st.dbid) is not null and cp.objtype = 'proc'

 group by DB_NAME(st.dbid),OBJECT_SCHEMA_NAME(objectid,st.dbid), OBJECT_NAME(objectid,st.dbid)

 order by sum(qs.total_worker_time) desc

 

See also Get the execution count of a Stored Procedure for more information.

 

Last modified
18:58, 25 Aug 2016

Tags

Classifications

Public