Skip to content

Instantly share code, notes, and snippets.

@chrisnas
Created February 11, 2019 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisnas/ae8fa6e01ddada2b1726fd49ee0d83fd to your computer and use it in GitHub Desktop.
Save chrisnas/ae8fa6e01ddada2b1726fd49ee0d83fd to your computer and use it in GitHub Desktop.
protected override void OnStart()
{
string sessionName = $"GcLogEtwSession_{_pid.ToString()}_{Guid.NewGuid().ToString()}";
Console.WriteLine($"Starting {sessionName}...\r\n");
_userSession = new TraceEventSession(sessionName, TraceEventSessionOptions.Create);
Task.Run(() =>
{
// only want to receive GC event
ClrEventsManager manager = new ClrEventsManager(_userSession, _pid, EventFilter.GC);
manager.GarbageCollection += OnGarbageCollection;
// this is a blocking call until the session is disposed
manager.ProcessEvents();
Console.WriteLine("End of CLR event processing");
});
// add a header to the .csv file
WriteLine(Header);
}
protected override void OnStop()
{
// when the session is disposed, the call to ProcessEvents() returns
_userSession.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment