码迷,mamicode.com
首页 > 数据库 > 详细

DB中耗时的 存储过程 及执行详细情况

时间:2016-01-11 17:52:40      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

 

SELECT  a.object_id, a.database_id, OBJECT_NAME(object_id, database_id) proc name,
a.cached_time, a.last_execution_time, a.total_elapsed_time, a.total_elapsed_time/a.execution_count AS [avg_elapsed_time],
a.execution_count,
a.total_physical_reads/a.execution_count avg_physical_reads,
a.total_logical_writes,
a.total_logical_writes/ a.execution_count  avg_logical_reads,
a.last_elapsed_time,
a.total_elapsed_time / a.execution_count   avg_elapsed_time,
b.text,c.query_plan 
FROM sys.dm_exec_procedure_stats AS a
CROSS APPLY sys.dm_exec_sql_text(a.sql_handle)  b
CROSS APPLY sys.dm_exec_query_plan(a.plan_handle) c
ORDER BY [total_worker_time] DESC;
GO


select creation_time 编译时间,
  last_execution_time 上次执行时间,
  total_physical_reads 物理读取总次数,
  total_logical_reads/execution_count 每次逻辑读次数,
  total_logical_reads 逻辑读次数,
  total_logical_writes 逻辑写次数,
  execution_count 执行总次数,
  total_worker_time/1000 占用CPU总时间(毫秒),
  total_elapsed_time/1000 总花费时间(毫秒),
  (execution_count/total_elapsed_time)/1000 平均执行时间(毫秒),
  substring(st.text,(qs.statement_start_offset/2)+1,((case qs.statement_end_offset when -1 then datalength(st.text) else qs.statement_end_offset end -qs.statement_start_offset)/2)+1) 执行的SQL语句,
  getdate() 执行收集时间
   from sys.dm_exec_query_stats as qs 
cross apply sys.dm_exec_sql_text(qs.sql_handle)as st
where substring(st.text,(qs.statement_start_offset/2)+1,((case qs.statement_end_offset when -1 then datalength(st.text) else qs.statement_end_offset end -qs.statement_start_offset)/2)+1)
not like %FETCH%
ORDER BY total_elapsed_time/execution_count desc

 

DB中耗时的 存储过程 及执行详细情况

标签:

原文地址:http://www.cnblogs.com/davidhou/p/5121667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!