Пример #1
0
        private static void PrintRuntimeGCEvents(string file)
        {
            var source = new EventPipeEventSource(file);

            // https://devblogs.microsoft.com/dotnet/glad-part-2/
            source.NeedLoadedDotNetRuntimes();
            source.AddCallbackOnProcessStart(proc =>
            {
                proc.AddCallbackOnDotNetRuntimeLoad(runtime =>
                {
                    runtime.GCEnd += RuntimeOnGCEnd;
                });
            });

            //source.Clr.All += (TraceEvent obj) => { Console.WriteLine(obj.EventName); };
            try
            {
                source.Process();
            }
            // NOTE: This exception does not currently exist. It is something that needs to be added to TraceEvent.
            catch (Exception e)
            {
                Console.WriteLine("Error encountered while processing events");
                Console.WriteLine(e.ToString());
            }
        }
        static void PrintRuntimeGCEvents(int processId)
        {
            var providers = new List <EventPipeProvider>()
            {
                new EventPipeProvider("Microsoft-Windows-DotNETRuntime",
                                      EventLevel.Informational, (long)ClrTraceEventParser.Keywords.GC)
            };

            var client = new DiagnosticsClient(processId);

            using (var session = client.StartEventPipeSession(providers, false))
            {
                var source = new EventPipeEventSource(session.EventStream);

                // https://devblogs.microsoft.com/dotnet/glad-part-2/
                source.NeedLoadedDotNetRuntimes();
                source.AddCallbackOnProcessStart(proc =>
                {
                    proc.AddCallbackOnDotNetRuntimeLoad(runtime =>
                    {
                        runtime.GCEnd += RuntimeOnGCEnd;
                    });
                });

                source.Clr.All += (TraceEvent obj) => { Console.WriteLine(obj.EventName); };
                try
                {
                    source.Process();
                }
                // NOTE: This exception does not currently exist. It is something that needs to be added to TraceEvent.
                catch (Exception e)
                {
                    Console.WriteLine("Error encountered while processing events");
                    Console.WriteLine(e.ToString());
                }
            }
        }