I explained why you should care (if you are instrumenting server applications, you care), and outlined the basics of using the feature.
In short, in a world of concurrent/asynchronous activities, it allows you to focus on all events that are related causally, ignoring all the other concurrent activity on the system. This is critical in server scenarios.
In this blog post I what to insure you have what you need to actually experiment with the feature. In particular I have posted demonstration code as an attachment to this blog. This is a ZIP file that contains
- Source code (A VS2013 solution) containing a trivial C# application that has an EventSource that defines some activities that nest inside each other.
- A build of that C# (so you can run it yourself event without Visual Studio)
- A PerfView.etl.ZIP file containing the events that you would have collected if you follow the instructions.
Thus you have everything you need to walk through the feature. The source code is really just a single C# file 'Program.cs that contains
- An EventSource with various 'Start' and 'Stop' events, that represent particular activities.
- A fictitious request processing code that includes asynchronous events, network activities, nested activities, and event 'bad' activities (that start but do not stop) to simulate real request processing code.
- A driver that runs 20 of these requests in parallel.
There is a Visual Studio 2013 .SLN and .CSPROJ file so to compile it you can simply
- Click on the EventSourceActivityDemo.zip link below. Click through the security prompt and open the ZIP.
- Drag the EventSourceActivityDemo directory inside the ZIP file to a location on your local drive
- Open the EventSourceActivityDemo\EventSourceActivityDemo.sln file in Visual Studio
- Build (F6).
If you don't have Visual Studio Handy, I have already built the EXE as EventSourceActivityDemo\bin\Debug\EventSourceActivityDemo.exe. If you wish you can simply run that.
To gather data you will need a current version (V1.8) of the PerfView tool. You can get this at the PerfView Download Location. The demo code tells you how to collect data, but I repeat it here
- Run PerfView /Providers=*Microsoft-Demos-Activities collect
- While it is running run the EventSourceActivityDemo.exe
- When complete, tell PerfView to stop collection
As a reminder you need to have .NET 4.6 installed on your machine. If you are on Win10 you have it, but otherwise see yesterday's blog post for details about checking if you have it and getting it if you don't have it.
The result is a PerfViewData.etl.zip file that PerfView can examine. If you wish you can skip this part too (e.g. you don't have V4.6 installed), as I have already collected that data and included it in the EventSourceActivityDemo.zip file. It is in the EventSourceActivityDemo\bin\Debug\PerfVIewData.etl.zip file Thus you need only open this file in PerfView (e.g. PerfView EventSourceActivityDemo\bin\Debug\PerfVIewData.etl.zip).
Once you have the PerfVIewData.etl.zip opened in PerfView, you will want to look at the 'events' view by double clicking on it.
This will bring up the EventViewer as show below. (I strongly suggest using the blue hyperlinks at the top to learn more about the view). By Shift Clicking events names from the left hand pane, you can select all the 'Microsoft-Demos-Activities events. You may also wish to set the columns of interest by clicking on the 'Cols' button on the right and picking the 'ThreadID' and 'ActivityID' columns. Then you can hit 'Enter' (or click the 'update' button), to see the events you have specified.
What you will see is al the events from the program in chronological order each tagged with an ActivityID like //1/4/1/1. You can use the 'TextFilter' text box to see only events that have the given text pattern so putting //1/4 in that text box and hitting <enter> will show you all the events that were associated with that activity (or any of its children activities).
There you have it. You and now repro what I showed you in the last post. As extra credit you can look at the 'StartStopTree' view to look at the events as a tree sorted by activity rather than as a chronological display.