Beispiel #1
0
        static void Main(string[] args)
        {
            // filter on process if any
            int pid = -1;

            if (args.Length == 1)
            {
                int.TryParse(args[0], out pid);
            }

            string sessionName = "EtwSessionForCLR_" + Guid.NewGuid().ToString();

            Console.WriteLine($"Starting {sessionName}...\r\n");
            using (TraceEventSession userSession = new TraceEventSession(sessionName, TraceEventSessionOptions.Create))
            {
                Task.Run(() =>
                {
                    ClrEventsManager manager      = new ClrEventsManager(userSession, pid);
                    manager.FirstChanceException += OnFirstChanceException;
                    manager.Finalize             += OnFinalize;
                    manager.Contention           += OnContention;
                    manager.GCStats += OnGCStats;
                    manager.GCEnd   += OnGcEnd;

                    // this is a blocking call until the session is disposed
                    manager.ProcessEvents();
                    Console.WriteLine("End of CLR event processing");
                });

                // wait for the user to dismiss the session
                Console.WriteLine("Presse ENTER to exit...");
                Console.ReadLine();
            }
        }
Beispiel #2
0
 private static void RegisterEventHandlers(ClrEventsManager manager)
 {
     manager.FirstChanceException += OnFirstChanceException;
     manager.Finalize             += OnFinalize;
     manager.Contention           += OnContention;
     //manager.ThreadPoolStarvation += OnThreadPoolStarvation;
     manager.GarbageCollection += OnGarbageCollection;
     //manager.AllocationTick += OnAllocationTick;
 }
Beispiel #3
0
        // ---------------------------------------------------------------------------------------------------------------
        // To debug this application, go to Project Properties | Debug tab and set the PID of the application to monitor
        // in "command line argument" text box.
        // The simulator application could be used for testing
        // ---------------------------------------------------------------------------------------------------------------
        //
        static void Main2(string[] args)
        {
            // filter on process if any
            int pid = -1;

            if (args.Length == 1)
            {
                int.TryParse(args[0], out pid);
            }

#if ETW
            // ETW implementation
            string sessionName = "EtwSessionForCLR_" + Guid.NewGuid().ToString();
            Console.WriteLine($"Starting {sessionName}...\r\n");
            using (TraceEventSession userSession = new TraceEventSession(sessionName, TraceEventSessionOptions.Create))
            {
                Task.Run(() =>
                {
                    // don't want allocation ticks by default because it might have a noticeable impact
                    ClrEventsManager manager = new ClrEventsManager(userSession, pid, EventFilter.All & ~EventFilter.AllocationTick);
                    RegisterEventHandlers(manager);

                    // this is a blocking call until the session is disposed
                    manager.ProcessEvents();
                    Console.WriteLine("End of CLR event processing");
                });

                // wait for the user to dismiss the session
                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();
            }
#else
            // EventPipe implementation
            Console.WriteLine($"Starting event pipe session...");
            Task.Run(() =>
            {
                // don't want allocation ticks by default because it might have a noticeable impact
                ClrEventsManager manager = new ClrEventsManager(pid, EventFilter.All & ~EventFilter.AllocationTick);
                RegisterEventHandlers(manager);

                // this is a blocking call until the session is disposed
                manager.ProcessEvents();
                Console.WriteLine("End of CLR event processing");
            });

            // wait for the user to dismiss the session
            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
#endif
        }
Beispiel #4
0
        // ---------------------------------------------------------------------------------------------------------------
        // To debug this application, go to Project Properties | Debug tab and set the PID of the application to monitor
        // in "command line argument" text box.
        // The simulator application could be used for testing
        // ---------------------------------------------------------------------------------------------------------------
        //
        static void Main(string[] args)
        {
            // filter on process if any
            int pid = -1;

            if (args.Length == 1)
            {
                int.TryParse(args[0], out pid);
            }

            string sessionName = "EtwSessionForCLR_" + Guid.NewGuid().ToString();

            Console.WriteLine($"Starting {sessionName}...\r\n");
            using (TraceEventSession userSession = new TraceEventSession(sessionName, TraceEventSessionOptions.Create))
            {
                Task.Run(() =>
                {
                    // don't want allocation ticks by default because it might have a noticeable impact
                    ClrEventsManager manager      = new ClrEventsManager(userSession, pid, EventFilter.All & ~EventFilter.AllocationTick);
                    manager.FirstChanceException += OnFirstChanceException;
                    manager.Finalize             += OnFinalize;
                    manager.Contention           += OnContention;
                    manager.ThreadPoolStarvation += OnThreadPoolStarvation;
                    manager.GarbageCollection    += OnGarbageCollection;
                    //manager.AllocationTick += OnAllocationTick;

                    // this is a blocking call until the session is disposed
                    manager.ProcessEvents();
                    Console.WriteLine("End of CLR event processing");
                });

                // wait for the user to dismiss the session
                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();
            }
        }
Beispiel #5
0
        // ---------------------------------------------------------------------------------------------------------------
        // To debug this application, go to Project Properties | Debug tab and set the PID of the application to monitor
        // in "command line argument" text box.
        // The simulator application could be used for testing
        // ---------------------------------------------------------------------------------------------------------------
        //
        static void Main(string[] args)
        {
            //// filter on process if any
            //int pid = -1;
            //if (args.Length == 1)
            //{
            //    int.TryParse(args[0], out pid);
            //}

            int pid = Process.GetCurrentProcess().Id;

#if !ETW
            // ETW implementation
            string sessionName = "EtwSessionForCLR_" + Guid.NewGuid().ToString();
            Console.WriteLine($"Starting {sessionName}...\r\n");
            using (TraceEventSession userSession = new TraceEventSession(sessionName, TraceEventSessionOptions.Create))
            {
                Task.Run(() =>
                {
                    // don't want allocation ticks by default because it might have a noticeable impact
                    //ClrEventsManager manager = new ClrEventsManager(userSession, pid, EventFilter.All & ~EventFilter.AllocationTick);
                    ClrEventsManager manager = new ClrEventsManager(userSession, pid, EventFilter.AllocationTick);
                    RegisterEventHandlers(manager);

                    // this is a blocking call until the session is disposed
                    manager.ProcessEvents();
                    Console.WriteLine("End of CLR event processing");
                });

                Console.WriteLine("Press [ENTER] to start large allocs...");
                Console.ReadLine();

                var largeAlloc = new LargeAlloc();
                largeAlloc.Ready += (sender, e) =>
                {
                    Console.WriteLine("LargeAlloc ready. Press [ENTER] to continue...");
                    Console.ReadLine();
                };
                largeAlloc.Go();

                // wait for the user to dismiss the session
                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();
            }
#else
            // EventPipe implementation
            Console.WriteLine($"Starting event pipe session...");
            Task.Run(() =>
            {
                // don't want allocation ticks by default because it might have a noticeable impact
                //ClrEventsManager manager = new ClrEventsManager(pid, EventFilter.All & ~EventFilter.AllocationTick);

                ClrEventsManager manager = new ClrEventsManager(pid, /*EventFilter.GC |*/ EventFilter.AllocationTick);
                RegisterEventHandlers(manager);

                // this is a blocking call until the session is disposed
                manager.ProcessEvents();
                Console.WriteLine("End of CLR event processing");
            });

            Console.WriteLine("Press [ENTER] to start large allocs...");
            Console.ReadLine();

            var largeAlloc = new LargeAlloc();
            largeAlloc.Ready += (sender, e) =>
            {
                Console.WriteLine("LargeAlloc ready. Press [ENTER] to continue...");
                Console.ReadLine();
            };
            largeAlloc.Go();


            // wait for the user to dismiss the session
            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
#endif
        }