Exemplo n.º 1
0
        public void Test_EventSource_EtwManifestGeneration()
        {
            RemoteExecutor.Invoke(() =>
            {
                using (RemoteInvokeHandle handle = RemoteExecutor.Invoke(() =>
                {
                    var es = new SimpleEventSource();
                    for (var i = 0; i < 100; i++)
                    {
                        es.WriteSimpleInt(i);
                        Thread.Sleep(100);
                    }
                }))
                {
                    var etlFileName  = @"file.etl";
                    var tracesession = new TraceEventSession("testname", etlFileName);

                    tracesession.EnableProvider("SimpleEventSource");

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    tracesession.Flush();

                    // Sleep after requesting flush to ensure that the manifest payload generated
                    // is fully written to the etl file.
                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    tracesession.DisableProvider("SimpleEventSource");
                    tracesession.Dispose();

                    Assert.True(VerifyManifestAndRemoveFile(etlFileName));
                }
            }).Dispose();
        }
        public void Test_EventSource_EtwManifestGenerationRollover()
        {
            RemoteExecutor.Invoke(() =>
            {
                using (RemoteInvokeHandle handle = RemoteExecutor.Invoke(() =>
                {
                    var es = new SimpleEventSource();
                    for (var i = 0; i < 100; i++)
                    {
                        es.WriteSimpleInt(i);
                        Thread.Sleep(100);
                    }
                }))
                {
                    var initialFileName  = @"initialFile.etl";
                    var rolloverFileName = @"rolloverFile.etl";
                    var tracesession     = new TraceEventSession("testname", initialFileName);
                    var max_retries      = 50;

                    tracesession.EnableProvider("SimpleEventSource");

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    tracesession.Flush();

                    tracesession.SetFileName(rolloverFileName);

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    tracesession.Flush();

                    tracesession.DisableProvider("SimpleEventSource");
                    tracesession.Dispose();

                    bool initialFileHasManifest  = false;
                    bool rollOverFileHasManifest = false;

                    for (int i = 0; i < max_retries; i++)
                    {
                        if (VerifyManifestAndRemoveFile(initialFileName))
                        {
                            initialFileHasManifest = true;
                            break;
                        }
                        Thread.Sleep(1000);
                    }
                    for (int i = 0; i < max_retries; i++)
                    {
                        if (VerifyManifestAndRemoveFile(rolloverFileName))
                        {
                            rollOverFileHasManifest = true;
                            break;
                        }
                        Thread.Sleep(1000);
                    }
                    Assert.True(initialFileHasManifest);
                    Assert.True(rollOverFileHasManifest);
                }
            }).Dispose();
        }
Exemplo n.º 3
0
        public void Test_WriteEvent_ToChannel_Coverage()
        {
            TestUtilities.CheckNoEventSourcesRunning("Start");

            using (var log = new SimpleEventSource())
                using (var el = new LoudListener(log))
                {
                    log.WriteIntToAdmin(10);
                }
            TestUtilities.CheckNoEventSourcesRunning("Stop");
        }
        public void then_try_write_using_event_source()
        {
            SimpleEventSource       ses      = new SimpleEventSource();
            ObservableEventListener listener = new ObservableEventListener();

            using (listener)
            {
                listener.EnableEvents(ses, EventLevel.LogAlways, EventKeywords.All);
                listener.LogToElasticsearch(Environment.MachineName, this.elasticsearchUrl, "slabqwe-{0:yyyy.MM}", "etw");

                ses.MyEvent1("qwe1", 2);
            }
        }
Exemplo n.º 5
0
        public static int Main(string[] args)
        {
            int iter = 100;

            // Create an EventListener.
            using (SimpleEventListener myListener = new SimpleEventListener("SimpleEventSource", EventLevel.Verbose, iter))
            {
                string displayName  = "Mock Counter";
                string displayUnits = "Count";

                SimpleEventSource eventSource = new SimpleEventSource(displayName, displayUnits);

                // increment 100 times
                for (int i = 0; i < iter; i++)
                {
                    eventSource.IncrementCounter();
                }

                evnt.WaitOne(10000);

                if (iter != myListener.incrementSum)
                {
                    Console.WriteLine("Test Failed");
                    Console.WriteLine($"Expected to see {iter} events - saw {myListener.incrementSum}");
                    return(1);
                }

                if (displayName != myListener.displayName)
                {
                    Console.WriteLine("Test Failed");
                    Console.WriteLine($"Expected to see {displayName} as DisplayName property in payload - saw {myListener.displayName}");
                    return(1);
                }

                if (displayUnits != myListener.displayUnits)
                {
                    Console.WriteLine("Test Failed");
                    Console.WriteLine($"Expected to see {displayUnits} as DisplayUnits property in payload - saw {myListener.displayUnits}");
                    return(1);
                }

                if (!myListener.displayRateTimeScale.Equals("00:00:01"))
                {
                    Console.WriteLine("Test failed");
                    Console.WriteLine($"Wrong DisplayRateTimeScale: {myListener.displayRateTimeScale}");
                }

                Console.WriteLine("Test passed");
                return(100);
            }
        }
Exemplo n.º 6
0
        public void Test_EventSource_EtwManifestGeneration()
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions {
                TimeOut = 300_000                                                     /* ms */
            };

            RemoteExecutor.Invoke(() =>
            {
                RemoteInvokeOptions localOptions = new RemoteInvokeOptions {
                    TimeOut = 300_000                                                          /* ms */
                };
                using (RemoteInvokeHandle handle = RemoteExecutor.Invoke(() =>
                {
                    var es = new SimpleEventSource();
                    for (var i = 0; i < 100; i++)
                    {
                        es.WriteSimpleInt(i);
                        Thread.Sleep(100);
                    }
                }, localOptions))
                {
                    var etlFileName  = @"file.etl";
                    var tracesession = new TraceEventSession("testname", etlFileName);

                    tracesession.EnableProvider("SimpleEventSource");

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    tracesession.Flush();

                    tracesession.DisableProvider("SimpleEventSource");
                    tracesession.Dispose();

                    var manifestExists = false;
                    var max_retries    = 50;

                    for (int i = 0; i < max_retries; i++)
                    {
                        if (VerifyManifestAndRemoveFile(etlFileName))
                        {
                            manifestExists = true;
                            break;
                        }
                        Thread.Sleep(1000);
                    }
                    Assert.True(manifestExists);
                }
            }, options).Dispose();
        }
Exemplo n.º 7
0
        public static int Main(string[] args)
        {
            // Create an EventListener.
            using (SimpleEventListener myListener = new SimpleEventListener("SimpleEventSource", EventLevel.Verbose))
            {
                string displayName  = "Mock Counter";
                string displayUnits = "Count";

                SimpleEventSource eventSource = new SimpleEventSource(displayName, displayUnits);
                int iter = 100;

                // increment 100 times
                for (int i = 0; i < iter; i++)
                {
                    eventSource.WriteOne();
                }

                myListener.sawEvent.WaitOne(-1); // Block until we see at least one event

                if (!myListener.validateMean())
                {
                    Console.WriteLine("Test Failed - Incorrect mean calculation");
                    return(1);
                }

                if (displayName != myListener.displayName)
                {
                    Console.WriteLine("Test Failed");
                    Console.WriteLine($"Expected to see {displayName} as DisplayName property in payload - saw {myListener.displayName}");
                    return(1);
                }

                if (displayUnits != myListener.displayUnits)
                {
                    Console.WriteLine("Test Failed");
                    Console.WriteLine($"Expected to see {displayUnits} as DisplayUnits property in payload - saw {myListener.displayUnits}");
                    return(1);
                }

                if (myListener.callbackCount == 0)
                {
                    Console.WriteLine("Test Failed: Expected to see 1 or more EventListener callback but got none");
                }

                Console.WriteLine("Test passed");
                return(100);
            }
        }
Exemplo n.º 8
0
        public static int Main(string[] args)
        {
            // Create an EventListener.
            using (SimpleEventListener myListener = new SimpleEventListener("SimpleEventSource", EventLevel.Verbose))
            {
                SimpleEventSource eventSource = new SimpleEventSource(getMockedCount, getSuccessCount);

                // Want to sleep for 5000 ms to get some counters piling up.
                Thread.Sleep(5000);

                if (myListener.FailureEventCount > 0 && myListener.SuccessEventCount > 0 && !myListener.Failed && (mockedCountCalled > 0 && successCountCalled > 0))
                {
                    Console.WriteLine("Test Passed");
                    return(100);
                }
                else
                {
                    Console.WriteLine("Test Failed");
                    return(1);
                }
            }
        }
Exemplo n.º 9
0
        public static int Main(string[] args)
        {
            // Create an EventListener.
            using (SimpleEventListener myListener = new SimpleEventListener("SimpleEventSource", EventLevel.Verbose))
            {
                SimpleEventSource eventSource = new SimpleEventSource(getMockedCount);

                // Want to sleep for 5000 ms to get some counters piling up.
                Thread.Sleep(5000);

                if (myListener.Failed || mockedCountCalled <= 0)
                {
                    Console.WriteLine($"Test Failed - mockedCountCalled = {mockedCountCalled}, myListener.Failed = {myListener.Failed}");
                    return(1);
                }

                if (myListener.displayRateTimeScale != "00:00:01")
                {
                    Console.WriteLine($"Test Failed - Incorrect DisplayRateTimeScale in payload: {myListener.displayRateTimeScale}");
                    return(1);
                }

                if (myListener.displayName != "Failure Count")
                {
                    Console.WriteLine($"Test Failed - Incorrect DisplayName in payload: {myListener.displayName}");
                    return(1);
                }

                if (myListener.displayUnits != "Count")
                {
                    Console.WriteLine($"Test failed - Incorrect DisplayUnits in payload: {myListener.displayUnits}");
                    return(1);
                }

                Console.WriteLine("Test passed");
                return(100);
            }
        }
Exemplo n.º 10
0
        public static int Main(string[] args)
        {
            // Create an EventListener.
            using (SimpleEventListener myListener = new SimpleEventListener("SimpleEventSource", EventLevel.Verbose))
            {
                // Reflect over System.Private.CoreLib and get the PollingCounter type.
                Assembly SPC = typeof(System.Diagnostics.Tracing.EventSource).Assembly;
                if (SPC == null)
                {
                    Console.WriteLine("Failed to get System.Private.CoreLib assembly.");
                    return(1);
                }
                Type PollingCounterType = SPC.GetType("System.Diagnostics.Tracing.PollingCounter");
                if (PollingCounterType == null)
                {
                    Console.WriteLine("Failed to get System.Diagnostics.Tracing.PollingCounter type.");
                    return(1);
                }

                SimpleEventSource eventSource = new SimpleEventSource(getMockedCount, getSuccessCount, PollingCounterType);

                // Want to sleep for 5000 ms to get some counters piling up.
                Thread.Sleep(5000);

                if (myListener.FailureEventCount > 0 && myListener.SuccessEventCount > 0 && !myListener.Failed && (mockedCountCalled > 0 && successCountCalled > 0))
                {
                    Console.WriteLine("Test Passed");
                    return(100);
                }
                else
                {
                    Console.WriteLine("Test Failed");
                    return(1);
                }
            }
        }