using Microsoft.Diagnostics.NETCore.Client; using Microsoft.Diagnostics.Tracing; using Microsoft.Diagnostics.Tracing.EventPipe; using Microsoft.Diagnostics.Tracing.Parsers; using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.Tracing; public class RuntimeGCEventsPrinter { public static void PrintRuntimeGCEvents(int processId) { var providers = new List() { new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, (long)ClrTraceEventParser.Keywords.Default) }; var client = new DiagnosticsClient(processId); using (EventPipeSession session = client.StartEventPipeSession(providers, false)) { var source = new EventPipeEventSource(session.EventStream); var blacklist = ImmutableHashSet.Create( "Method/ILToNativeMap", "GC/BulkMovedObjectRanges", "GC/BulkSurvivingObjectRanges" ); var fnFilter = (TraceEvent te) => { //Console.WriteLine(obj.ToString()); if( blacklist.Contains( te.EventName ) ) return; log.info( $"{te}", cat: "clr" ); }; source.Clr.All += fnFilter; source.Kernel.All += fnFilter; source.Dynamic.All += fnFilter; try { source.Process(); } catch (Exception e) { Console.WriteLine("Error encountered while processing events"); Console.WriteLine(e.ToString()); } } } }