<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tags 'troubleshooting', 'Extended Events', and 'Denali'</title><link>http://msmvps.com/search/SearchResults.aspx?q=app:weblogs&amp;tag=troubleshooting,Extended+Events,Denali&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'troubleshooting', 'Extended Events', and 'Denali'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Wait stats information to Synchronous Bucketizer Target in Denali CTP1 with Extended Events</title><link>http://msmvps.com/blogs/eladio_rincon/archive/2010/11/10/wait-stats-information-to-synchronous-bucketizer-target-in-denali-ctp1-with-extended-events.aspx</link><pubDate>Wed, 10 Nov 2010 06:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1782047</guid><dc:creator>Eladio</dc:creator><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Following the article yesterday published in our &lt;a title="http://www.solidq.com/sqj" href="http://www.solidq.com/sqj"&gt;http://www.solidq.com/sqj&lt;/a&gt; (Know Where Your Query Spends Its Time), here is the code to send the wait stats information to a synchronous bucketizer; the obvious pros are that the structure is in memory, and you don’t need to stop the session to process the data; the cons are that you cannot reset the data read (unless you re-create the session); the other big con is that you cannot sum values in the columns (in the case of the wait_stats time is important).&lt;/p&gt;  &lt;p&gt;Here is the code:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Create the session:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;--&lt;/span&gt;
&lt;span class="rem"&gt;-- Extended Events (query level wait stats)&lt;/span&gt;
&lt;span class="rem"&gt;--&lt;/span&gt;
&lt;span class="rem"&gt;-- Eladio Rincon&lt;/span&gt;
&lt;span class="rem"&gt;-- Solid Quality Mentors 2010&lt;/span&gt;
&lt;span class="rem"&gt;-- http://creativecommons.org/licenses/by-sa/3.0/&lt;/span&gt;
&lt;span class="rem"&gt;-- Attribution-NonCommercial-ShareAlike 3.0&lt;/span&gt;
&lt;span class="rem"&gt;--&lt;/span&gt;
&lt;span class="rem"&gt;-- http://blogs.solidq.com/elrinconDelDBA&lt;/span&gt;
&lt;span class="rem"&gt;-- http://siquelnet.com&lt;/span&gt;
&lt;span class="rem"&gt;--&lt;/span&gt;


&lt;span class="kwrd"&gt;USE&lt;/span&gt; AdventureWorks
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; DB_ID(&lt;span class="str"&gt;&amp;#39;adventureworks&amp;#39;&lt;/span&gt;) dbid, &lt;span class="preproc"&gt;@@spid&lt;/span&gt; spid
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; EVENT &lt;span class="kwrd"&gt;SESSION&lt;/span&gt; xe_waits_bucket
&lt;span class="kwrd"&gt;ON&lt;/span&gt; SERVER
&lt;span class="kwrd"&gt;ADD&lt;/span&gt; EVENT
    sqlos.wait_info (
        &lt;span class="kwrd"&gt;WHERE&lt;/span&gt;  (sqlserver.database_id = 7 &lt;span class="kwrd"&gt;AND&lt;/span&gt; sqlserver.session_id = 59 &lt;span class="kwrd"&gt;AND&lt;/span&gt; opcode = 1)
    )
&lt;span class="kwrd"&gt;ADD&lt;/span&gt; TARGET package0.synchronous_bucketizer ( 
&lt;span class="kwrd"&gt;SET&lt;/span&gt; filtering_event_name=&lt;span class="str"&gt;&amp;#39;sqlos.wait_info&amp;#39;&lt;/span&gt;
, source_type=0
, source=&lt;span class="str"&gt;&amp;#39;wait_type&amp;#39;&lt;/span&gt;
)
&lt;span class="kwrd"&gt;WITH&lt;/span&gt; 
(
    MAX_MEMORY = 4096KB, 
    EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS, 
    MAX_DISPATCH_LATENCY = 1 SECONDS, 
    MEMORY_PARTITION_MODE = &lt;span class="kwrd"&gt;NONE&lt;/span&gt;, 
    TRACK_CAUSALITY = &lt;span class="kwrd"&gt;ON&lt;/span&gt;, 
    STARTUP_STATE = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;
)&lt;/pre&gt;


&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Then start the session:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;ALTER&lt;/span&gt; EVENT &lt;span class="kwrd"&gt;SESSION&lt;/span&gt; xe_waits_bucket
&lt;span class="kwrd"&gt;ON&lt;/span&gt; SERVER
&lt;span class="kwrd"&gt;STATE&lt;/span&gt; = START&lt;/pre&gt;


&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Run a sample query:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;from&lt;/span&gt; HumanResources.vEmployee&lt;/pre&gt;


&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Now; if you want to know where is the information, run the following query:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;span class="kwrd"&gt;CAST&lt;/span&gt;(xest.target_data &lt;span class="kwrd"&gt;AS&lt;/span&gt; XML) xml_data
&lt;span class="kwrd"&gt;FROM&lt;/span&gt; sys.dm_xe_session_targets xest
&lt;span class="kwrd"&gt;JOIN&lt;/span&gt; sys.dm_xe_sessions xes &lt;span class="kwrd"&gt;ON&lt;/span&gt; xes.address = xest.event_session_address
&lt;span class="kwrd"&gt;JOIN&lt;/span&gt; sys.server_event_sessions ses &lt;span class="kwrd"&gt;ON&lt;/span&gt; xes.name = ses.name
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt; xest.target_name = &lt;span class="str"&gt;&amp;#39;synchronous_bucketizer&amp;#39;&lt;/span&gt; &lt;span class="kwrd"&gt;AND&lt;/span&gt; xes.name = &lt;span class="str"&gt;&amp;#39;xe_waits_bucket&amp;#39;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Bear in mind the xes.name column that is the name of the session.&lt;/p&gt;

&lt;p&gt;if you see the resultant XML, you’ll see something like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;BucketizerTarget truncated=&lt;span class="str"&gt;&amp;quot;0&amp;quot;&lt;/span&gt; buckets=&lt;span class="str"&gt;&amp;quot;256&amp;quot;&lt;/span&gt;&amp;gt;
  &amp;lt;Slot count=&lt;span class="str"&gt;&amp;quot;183&amp;quot;&lt;/span&gt; trunc=&lt;span class="str"&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span class="kwrd"&gt;value&lt;/span&gt;&amp;gt;121&amp;lt;/&lt;span class="kwrd"&gt;value&lt;/span&gt;&amp;gt;
  &amp;lt;/Slot&amp;gt;
  &amp;lt;Slot count=&lt;span class="str"&gt;&amp;quot;75&amp;quot;&lt;/span&gt; trunc=&lt;span class="str"&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span class="kwrd"&gt;value&lt;/span&gt;&amp;gt;66&amp;lt;/&lt;span class="kwrd"&gt;value&lt;/span&gt;&amp;gt;
  &amp;lt;/Slot&amp;gt;
  &amp;lt;Slot count=&lt;span class="str"&gt;&amp;quot;11&amp;quot;&lt;/span&gt; trunc=&lt;span class="str"&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span class="kwrd"&gt;value&lt;/span&gt;&amp;gt;99&amp;lt;/&lt;span class="kwrd"&gt;value&lt;/span&gt;&amp;gt;
  &amp;lt;/Slot&amp;gt;
&amp;lt;/BucketizerTarget&amp;gt;&lt;/pre&gt;


&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Here is the nice part:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;value is an internal code for the wait type &lt;/li&gt;

  &lt;li&gt;count is the number of occurrences &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, the thing is find out how to translate the value in the XML to the wait_type description.&lt;/p&gt;

&lt;p&gt;you’ll get that information from the sys.dm_xe_map_values, DMV.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;finally, the query will be the following:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;-- wait stats&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; 
    v.&lt;span class="kwrd"&gt;count&lt;/span&gt; 
    , k.map_value wait_type
&lt;span class="kwrd"&gt;from&lt;/span&gt; (
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
     t.x.&lt;span class="kwrd"&gt;value&lt;/span&gt;(&lt;span class="str"&gt;&amp;#39;(value)[1]&amp;#39;&lt;/span&gt;, &lt;span class="str"&gt;&amp;#39;int&amp;#39;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; k 
     , t.x.&lt;span class="kwrd"&gt;value&lt;/span&gt;(&lt;span class="str"&gt;&amp;#39;(@count)[1]&amp;#39;&lt;/span&gt;, &lt;span class="str"&gt;&amp;#39;int&amp;#39;&lt;/span&gt;) &lt;span class="kwrd"&gt;AS&lt;/span&gt; [&lt;span class="kwrd"&gt;count&lt;/span&gt;]
&lt;span class="kwrd"&gt;from&lt;/span&gt; ( 
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;span class="kwrd"&gt;CAST&lt;/span&gt;(xest.target_data &lt;span class="kwrd"&gt;AS&lt;/span&gt; XML) xml_data
&lt;span class="kwrd"&gt;FROM&lt;/span&gt; sys.dm_xe_session_targets xest
&lt;span class="kwrd"&gt;JOIN&lt;/span&gt; sys.dm_xe_sessions xes &lt;span class="kwrd"&gt;ON&lt;/span&gt; xes.address = xest.event_session_address
&lt;span class="kwrd"&gt;JOIN&lt;/span&gt; sys.server_event_sessions ses &lt;span class="kwrd"&gt;ON&lt;/span&gt; xes.name = ses.name
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt; xest.target_name = &lt;span class="str"&gt;&amp;#39;synchronous_bucketizer&amp;#39;&lt;/span&gt; &lt;span class="kwrd"&gt;AND&lt;/span&gt; xes.name = &lt;span class="str"&gt;&amp;#39;xe_waits_bucket&amp;#39;&lt;/span&gt;
) v
&lt;span class="kwrd"&gt;CROSS&lt;/span&gt; APPLY xml_data.nodes (&lt;span class="str"&gt;&amp;#39;//BucketizerTarget/Slot&amp;#39;&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; T (x)
) v
&lt;span class="kwrd"&gt;left&lt;/span&gt; &lt;span class="kwrd"&gt;join&lt;/span&gt; sys.dm_xe_map_values k
&lt;span class="kwrd"&gt;on&lt;/span&gt;  v.k = k.map_key
&lt;span class="kwrd"&gt;where&lt;/span&gt; k.name = &lt;span class="str"&gt;&amp;#39;wait_types&amp;#39;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;In my case, the results will look like this:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;count       wait_type
----------- -------------------------------
215         SOS_SCHEDULER_YIELD
75          PAGEIOLATCH_SH
11          NETWORK_IO&lt;/pre&gt;


&lt;p&gt;Final Notes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The JOIN doesn’t resolve correctly in SQL 2008 because aparently the keys doesn’t match with the dm_xe_map_values (I couldn’t find the relation). &lt;/li&gt;

  &lt;li&gt;This works on Denali CTP1; I’m not sure it it will work on next CTPs. &lt;strong&gt;UPDATE: &lt;/strong&gt;&lt;a href="http://sqlblog.com/blogs/jonathan_kehayias" target="_blank"&gt;Jonathan Kehayias&lt;/a&gt; (SQL Server MVP) pointed this PM that this issue is fixed in SQL Server 2008 SP2 (&lt;a href="http://support.microsoft.com/kb/2285068" target="_blank"&gt;280004&lt;/a&gt;); however, still doesn’t work on SQL Server 2008 R2.&lt;/li&gt;

  &lt;li&gt;it would be nice if in the future you could select aggegate operations in other columns (such sums, avgs, maxs, etc) &lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>