Created
May 8, 2021 01:17
-
-
Save noahfalk/ca503276cea4b97c6630ebe672318ece to your computer and use it in GitHub Desktop.
Create and collect ETW events from a custom EventSource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Steps to run this sample: | |
// 1. Create a console app and replace Program.cs with this source | |
// 2. Build the app (for example with dotnet build). My exe is produced in | |
// "E:\temp\EventSourceSample\bin\Debug\net5.0\EventSourceSample.exe" | |
// 3. Download PerfView if you don't already have it: https://github.com/microsoft/perfview/blob/main/documentation/Downloading.md | |
// 4. In an admin command prompt, run this PerfView command substituting the path to your executable: | |
// PerfView.exe -OnlyProviders:MyEventSource run E:\temp\EventSourceSample\bin\Debug\net5.0\EventSourceSample.exe | |
// 5. After PerfView finishes collecting, open the Events view and confirm that 1 event of type MyEventSource/HelloWorld was collected in | |
// addition to the other events | |
using System; | |
using System.Diagnostics.Tracing; | |
namespace EventSourceSample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
MyEventSource source = new MyEventSource(); | |
source.HelloWorld(); | |
} | |
} | |
[EventSource(Name="MyEventSource")] | |
class MyEventSource : EventSource | |
{ | |
[Event(1)] | |
public void HelloWorld() | |
{ | |
WriteEvent(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment