x
login about faq Site discussion (meta-askssc)

capturing showplan XML in traces/profiler for ONLY CPU greater than 999

I have a database that has a lot of adhoc sql being run against it, so i don't want to capture all execution plans. Only want those plans that are consuming lots of CPU.

Is there an elegant way to do this? I cannot seem to filter out all the showplans for insignificant queries

more ▼

asked Nov 30 '09 at 10:27 PM in Default

Nick Kavadias gravatar image

Nick Kavadias
466 3 3 7

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

No, there's no way to filter what you capture using trace events. What you can do though is to pull the execution plan out of the cache. You can query the dynamic management object sys.dm_exec_query_stats. That will give you aggregate information on the queries that have been running on the system. You can use this to determine which queries you're interested in, the longest running, most frequently called, etc. That comes with a plan_handle that you can then use to query against the dynamic management object sys.dm_exec_query_plan to get the execution plan for the longest running queries.

If you have a lot of ad hoc queries running, you might want to automate this to run every 1/2 hour or some other interval since these queries are cache dependent.

Also, since you're looking at ad hoc queries, you can use the query_hash in sys.dm_exec_query_stats as a means of combining queries that are similar to get better information. Of course, if you do that, you will need to worry about having X number of query plans returned, so there might be a bit of a balancing act needed there.

more ▼

answered Nov 30 '09 at 11:42 PM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
62.2k 12 20 66

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x34
x30
x15
x5
x3

asked: Nov 30 '09 at 10:27 PM

Seen: 1376 times

Last Updated: Nov 30 '09 at 11:46 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.