{"id":1371,"date":"2014-01-24T13:00:45","date_gmt":"2014-01-24T13:00:45","guid":{"rendered":"http:\/\/writeasync.net\/?p=1371"},"modified":"2014-01-22T09:41:19","modified_gmt":"2014-01-22T09:41:19","slug":"decoding-eventsource-traces","status":"publish","type":"post","link":"http:\/\/writeasync.net\/?p=1371","title":{"rendered":"Decoding EventSource traces"},"content":{"rendered":"<p>In the <a href=\"http:\/\/writeasync.net\/?p=1321\">previous post<\/a>, I introduced an <a href=\"https:\/\/github.com\/brian-dot-net\/writeasync\/tree\/master\/projects\/EventSourceSample\">EventSource sample<\/a>. If you run the sample app, the calculator client will continually try to connect to the service and perform random operations, tracing all the while. That&#8217;s nice, but how do you actually read and decode these traces?<\/p>\n<p>First, you need to actually collect the traces. As usual, open an <strong>elevated<\/strong> command prompt and run <code>logman.exe create trace SampleTrace -p {0745B9D3-BC9A-4C33-953C-77DE89336B0D} -o SampleTrace.etl<\/code> (note that we use the <code>ClientEventSource<\/code> provider ID) to create the session and <code>logman.exe start SampleTrace<\/code> to start the session. Now run the app and let it go for 30 seconds or so. After you exit the app, run <code>logman.exe stop SampleTrace<\/code> to stop the session. You will now have a file <code>SampleTrace_000001.etl<\/code> (or similar). However, ETL is a binary format and a manifest is required to decode the trace data.<\/p>\n<p>Conveniently, I have created a PowerShell script to invoke <code>EventSource<\/code>&#8216;s method to generate the manifest file for types in a given assembly: <a href=\"https:\/\/github.com\/brian-dot-net\/writeasync\/blob\/master\/scripts\/GenerateManifests.cmd\">GenerateManifests.cmd<\/a>. To use it, pass in the assembly name and an optional output path (defaults to current directory). For the sample app, the command would be something like <code>GenerateManifests.cmd EventSourceSample.Core.dll<\/code>. The resulting file <code>EventSourceSample-ClientEventSource.man<\/code> can now be passed to <code>tracerpt.exe<\/code> to decode the events!<\/p>\n<p>Let&#8217;s try converting to XML:<br \/>\n<code>tracerpt.exe -l SampleTrace_000001.etl -import EventSourceSample-ClientEventSource.man -o SampleTrace.xml -of XML<\/code><\/p>\n<p>Opening up <code>SampleTrace.xml<\/code> you should see output similar to the following:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;Event xmlns=&quot;http:\/\/schemas.microsoft.com\/win\/2004\/08\/events\/event&quot;&gt;\r\n\t&lt;System&gt;\r\n\t\t&lt;Provider Name=&quot;ClientEventSource&quot; Guid=&quot;{0745b9d3-bc9a-4c33-953c-77de89336b0d}&quot; \/&gt;\r\n\t\t&lt;EventID&gt;30&lt;\/EventID&gt;\r\n\t\t&lt;Version&gt;0&lt;\/Version&gt;\r\n\t\t&lt;Level&gt;4&lt;\/Level&gt;\r\n\t\t&lt;Task&gt;0&lt;\/Task&gt;\r\n\t\t&lt;Opcode&gt;1&lt;\/Opcode&gt;\r\n\t\t&lt;Keywords&gt;0xF00000000008&lt;\/Keywords&gt;\r\n\t\t&lt;TimeCreated SystemTime=&quot;2014-01-24T12:00:20.612995800Z&quot; \/&gt;\r\n\t\t&lt;Correlation ActivityID=&quot;{00000000-0000-0000-0000-000000000000}&quot; \/&gt;\r\n\t\t&lt;Execution ProcessID=&quot;10824&quot; ThreadID=&quot;1076&quot; ProcessorID=&quot;0&quot; KernelTime=&quot;0&quot; UserTime=&quot;60&quot; \/&gt;\r\n\t\t&lt;Channel \/&gt;\r\n\t\t&lt;Computer \/&gt;\r\n\t&lt;\/System&gt;\r\n\t&lt;EventData&gt;\r\n\t\t&lt;Data Name=&quot;id&quot;&gt;{aeb41e37-cf40-4317-a989-7d5aa6a2dc87}&lt;\/Data&gt;\r\n\t&lt;\/EventData&gt;\r\n\t&lt;RenderingInfo Culture=&quot;en-US&quot;&gt;\r\n\t\t&lt;Level&gt;Information &lt;\/Level&gt;\r\n\t\t&lt;Opcode&gt;Start &lt;\/Opcode&gt;\r\n\t\t&lt;Keywords&gt;\r\n\t\t\t&lt;Keyword&gt;Connection &lt;\/Keyword&gt;\r\n\t\t&lt;\/Keywords&gt;\r\n\t\t&lt;Message&gt;Connection {aeb41e37-cf40-4317-a989-7d5aa6a2dc87} opening. &lt;\/Message&gt;\r\n\t&lt;\/RenderingInfo&gt;\r\n&lt;\/Event&gt;\r\n<\/pre>\n<p>There it is, in all its glory &#8212; the event header (in the <code>System<\/code> element) containing process, thread, timestamp, etc. and the decoded message (in the <code>RenderingInfo<\/code> element).<\/p>\n<p>This is a bit hard to read, so let&#8217;s try exporting to EVTX and using <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/cc766042.aspx\">Event Viewer<\/a> instead:<br \/>\n<code>tracerpt.exe -l SampleTrace_000001.etl -import EventSourceSample-ClientEventSource.man -o SampleTrace.evtx -of EVTX<\/code><\/p>\n<p>Typing the file name <code>SampleTrace.evtx<\/code> will launch Event Viewer to view the log. By default, the log will be sorted in descending timestamp order. In the upper pane, the table will show the event summary, e.g.:<\/p>\n<table>\n<tr>\n<td>Level<\/td>\n<td>Date and Time<\/td>\n<td>Source<\/td>\n<td>Event ID<\/td>\n<td>Task Category<\/td>\n<\/tr>\n<tr>\n<td>Information<\/td>\n<td>1\/24\/2014 12:00:20 PM<\/td>\n<td>ClientEventSource<\/td>\n<td>30<\/td>\n<td>None<\/td>\n<\/tr>\n<\/table>\n<p>The pane below this shows the decoded message and a detailed dump of the properties in the event. Within Event Viewer you can filter the log and resave it in different formats (e.g. CSV).<\/p>\n<p>These are the basic in-box tools you can use for dealing with ETL files. If you&#8217;re looking for a programmatic solution, e.g. to do more detailed analysis, stay tuned for a future post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous post, I introduced an EventSource sample. If you run the sample app, the calculator client will continually try to connect to the service and perform random operations, tracing all the while. That&#8217;s nice, but how do you&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71,31],"tags":[],"class_list":["post-1371","post","type-post","status-publish","format-standard","hentry","category-diagnostics","category-scripts"],"_links":{"self":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts\/1371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1371"}],"version-history":[{"count":0,"href":"http:\/\/writeasync.net\/index.php?rest_route=\/wp\/v2\/posts\/1371\/revisions"}],"wp:attachment":[{"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1371"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/writeasync.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}