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


    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
  • 相关阅读:
    [Javascript] Drawing Paths
    [Javascript] Drawing Paths
    [Whole Web] [AngularJS + Grunt] Using ng-html2js to Convert Templates into JavaScript
    [TypeScript] 1. Catching JavaScript Mistakes with TypeScript
    [TypeScript] 0.First Example
    [AngularJS] Introduction to angular-formly
    Runoob-Java:Java String 类
    Runoob-Java:Java Number & Math 类
    Runoob-Java:Java switch case
    Runoob-Java:Java 条件语句
  • 原文地址:https://www.cnblogs.com/davidhou/p/5121667.html
Copyright © 2020-2023  润新知