Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT TOP 5
- [Query] = [Query],
- [CPU] = SUM([CPU])
- FROM (
- SELECT
- [CPU] = [Total CPU Used],
- [Query] = dbo.fn_GetSQLNormalized([Parent Query])
- FROM
- (
- SELECT TOP 20
- [Average CPU Used] = total_worker_time / qs.execution_count,
- [Total CPU Used] = total_worker_time,
- [Execution COUNT] = qs.execution_count,
- [Individual Query] = SUBSTRING(
- qt.text,
- qs.statement_start_offset / 2,
- (CASE
- WHEN qs.statement_end_offset = -1
- THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
- ELSE qs.statement_end_offset
- END - qs.statement_start_offset) / 2
- ),
- [Parent Query] = qt.text,
- [DATABASE Name] = DB_NAME(qt.dbid)
- FROM
- sys.dm_exec_query_stats qs
- CROSS APPLY
- sys.dm_exec_sql_text(qs.sql_handle) AS qt
- ORDER BY
- [Average CPU Used] DESC
- ) AS Queries
- ) AS NormalizedQueries
- GROUP BY [Query]
- ORDER BY [CPU] DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement