Exemplo n.º 1
0
        static int Main(string[] args)
        {
            bool pass = false;

            using (var listener = new SimpleEventListener("SimpleEventSource", EventLevel.Verbose))
            {
                SimpleEventSource eventSource = new SimpleEventSource();

                Console.WriteLine("\tStart: Messaging.");
                // Send messages
                // Use random numbers and addition as a simple, human readble checksum
                Random generator = new Random();
                for (int i = 0; i < messageIterations; i++)
                {
                    int    x       = generator.Next(1, 1000);
                    int    y       = generator.Next(1, 1000);
                    string formula = String.Format("{0} + {1} = {2}", x, y, x + y);

                    eventSource.MathResult(x, y, x + y, formula);
                }
                Console.WriteLine("\tEnd: Messaging.\n");

                Console.WriteLine($"\tEventListener received {listener.EventCount} event(s)\n");
                pass = listener.EventCount == messageIterations;
            }

            return(pass ? 100 : -1);
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            SimpleEventListener.EnableKeywords = (EventKeywords)0;
            using (SimpleEventListener noEventsListener = new SimpleEventListener("NoEvents"))
            {
                // Create an EventListener.
                SimpleEventListener.EnableKeywords = (EventKeywords)0x4c14fccbd;
                using (SimpleEventListener listener = new SimpleEventListener("Simple"))
                {
                    // Trigger the allocator task.
                    System.Threading.Tasks.Task.Run(new Action(Allocator));

                    // Wait for events.
                    Thread.Sleep(1000);

                    // Generate some GC events.
                    GC.Collect(2, GCCollectionMode.Forced);

                    // Wait for more events.
                    Thread.Sleep(1000);

                    // Ensure that we've seen some events.
                    Assert.True("listener.EventCount > 0", listener.EventCount > 0);
                }

                // Generate some more GC events.
                GC.Collect(2, GCCollectionMode.Forced);

                // Ensure that we've seen no events.
                Assert.True("noEventsListener.EventCount == 0", noEventsListener.EventCount == 0);
            }

            return(100);
        }
        static int Main(string[] args)
        {
            SimpleEventListener.EnableKeywords = (EventKeywords)0;
            using (SimpleEventListener noEventsListener = new SimpleEventListener("NoEvents"))
            {
                // Create an EventListener.
                SimpleEventListener.EnableKeywords = (EventKeywords)0x4c14fccbd;
                using (SimpleEventListener listener = new SimpleEventListener("Simple"))
                {
                    // Trigger the allocator task.
                    Task.Run(new Action(Allocator));

                    // If on Windows, attempt some Overlapped IO (triggers ThreadPool events)
                    if (OperatingSystem.IsWindows())
                    {
                        DoOverlappedIO();
                    }

                    // Generate some GC events.
                    GC.Collect(2, GCCollectionMode.Forced);

                    Stopwatch sw = Stopwatch.StartNew();

                    while (sw.Elapsed <= TimeSpan.FromMinutes(1))
                    {
                        Thread.Sleep(100);

                        if ((OperatingSystem.IsWindows() && listener.SeenProvidersAndEvents.Contains("Microsoft-Windows-DotNETRuntime/EVENTID(65)")) ||
                            (!OperatingSystem.IsWindows() && listener.EventCount > 0))
                        {
                            break;
                        }
                    }

                    // Ensure that we've seen some events.
                    foreach (string s in listener.SeenProvidersAndEvents)
                    {
                        Console.WriteLine(s);
                    }

                    Assert.True("listener.EventCount > 0", listener.EventCount > 0);

                    if (OperatingSystem.IsWindows())
                    {
                        Assert.True("Saw the ThreadPoolIOPack event", listener.SeenProvidersAndEvents.Contains("Microsoft-Windows-DotNETRuntime/EVENTID(65)"));
                    }
                }

                // Generate some more GC events.
                GC.Collect(2, GCCollectionMode.Forced);

                // Ensure that we've seen no events.
                Assert.True("noEventsListener.EventCount == 0", noEventsListener.EventCount == 0);
            }

            return(100);
        }
Exemplo n.º 4
0
        static int Main(string[] args)
        {
            // Get the RuntimeEventSource.
            EventSource eventSource = RuntimeEventSource.Log;

            using (SimpleEventListener noEventsListener = new SimpleEventListener("NoEvents"))
            {
                // Enable the provider, but not any keywords, so we should get no events as long as no rundown occurs.
                noEventsListener.EnableEvents(eventSource, EventLevel.Critical, (EventKeywords)(0));

                // Create an EventListener.
                using (SimpleEventListener listener = new SimpleEventListener("Simple"))
                {
                    // Trigger the allocator task.
                    System.Threading.Tasks.Task.Run(new Action(Allocator));

                    // Enable events.
                    listener.EnableEvents(eventSource, EventLevel.Verbose, (EventKeywords)(0x4c14fccbd));

                    // Wait for events.
                    Thread.Sleep(1000);

                    // Generate some GC events.
                    GC.Collect(2, GCCollectionMode.Forced);

                    // Wait for more events.
                    Thread.Sleep(1000);

                    // Ensure that we've seen some events.
                    Assert.True("listener.EventCount > 0", listener.EventCount > 0);
                }

                // Generate some more GC events.
                GC.Collect(2, GCCollectionMode.Forced);

                // Ensure that we've seen no events.
                Assert.True("noEventsListener.EventCount == 0", noEventsListener.EventCount == 0);
            }

            return(100);
        }