August 2, 2013 at 7:32 am
I need to capture all the stored procedures and queries that takes more than 20 seconds to run from SQL Profiler.
Please guide?
August 2, 2013 at 7:48 am
i have this saved in my snippets as the top 20 slowest performaning queries;
this might get you started:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT TOP 20
CAST((qs.total_elapsed_time / 1000000.0) AS DECIMAL(28,2)) as total_elapsed_time,
CAST((qs.total_worker_time) / 1000000.0 AS DECIMAL(28,2))
AS [Total CPU time (s)]
, CAST(qs.total_worker_time * 100.0 / qs.total_elapsed_time
AS DECIMAL(28,2)) AS [% CPU]
, CAST((qs.total_elapsed_time - qs.total_worker_time)* 100.0 /
qs.total_elapsed_time AS DECIMAL(28, 2)) AS [% Waiting], qs.execution_count
, CAST((qs.total_worker_time) / 1000000.0
/ qs.execution_count AS DECIMAL(28, 2)) AS [CPU time average (s)]
, SUBSTRING (qt.text,(qs.statement_start_offset/2) + 1,
((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) + 1) AS [Individual Query]
, qt.text AS [Parent Query]
, DB_NAME(qt.dbid) AS DatabaseName
, qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
WHERE qs.total_elapsed_time > 0
ORDER BY [Total CPU time (s)] DESC
Lowell
August 2, 2013 at 8:50 am
How can i pull the time it Ran?
August 2, 2013 at 8:55 am
There's a last_execution_time column in dm_exec_query_stats.
John
August 2, 2013 at 9:02 am
Sorry i mean date and time it Ran?
August 2, 2013 at 9:39 am
huum (8/2/2013)
Sorry i mean date and time it Ran?
i don't think you can find that, AFAIK all you can find is the last execution time; you cannot see , for example 50 entries, one for each execution.
just a totals and averages.
Lowell
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy