Exemple #1
0
        static int Main(string[] args)
        {
            using (var netPerfFile = NetPerfFile.Create(args))
            {
                SimpleEventSource eventSource = new SimpleEventSource();

                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.Enable(GetConfig(eventSource, netPerfFile.Path));
                Console.WriteLine("\tEnd: Enable tracing.\n");

                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("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                FileInfo outputMeta = new FileInfo(netPerfFile.Path);
                Console.WriteLine("\tCreated {0} bytes of data", outputMeta.Length);

                return(outputMeta.Length > trivialSize ? 100 : -1);
            }
        }
        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);
        }
Exemple #3
0
        static int Main(string[] args)
        {
            bool pass       = true;
            bool keepOutput = false;

            // Use the first arg as an output filename if there is one
            string outputFilename = null;

            if (args.Length >= 1)
            {
                outputFilename = args[0];
                keepOutput     = true;
            }
            else
            {
                outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            }

            SimpleEventSource eventSource = new SimpleEventSource();

            try
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.Enable(GetConfig(eventSource, outputFilename));
                Console.WriteLine("\tEnd: Enable tracing.\n");

                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("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                Console.WriteLine("\tStart: Processing events from file.");
                int msgCount = 0;
                using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(outputFilename))
                {
                    var names = new HashSet <string>();

                    trace.Dynamic.All += delegate(TraceEvent data)
                    {
                        if (!names.Contains(data.ProviderName))
                        {
                            Console.WriteLine("\t{0}", data.ProviderName);
                            names.Add(data.ProviderName);
                        }

                        if (data.ProviderName == "SimpleEventSource")
                        {
                            msgCount += 1;
                        }
                    };

                    trace.Process();
                }
                Console.WriteLine("\tEnd: Processing events from file.\n");

                Console.WriteLine("\tProcessed {0} events from EventSource", msgCount);

                pass &= msgCount == messageIterations;
            }
            finally {
                if (keepOutput)
                {
                    Console.WriteLine("\n\tOutput file: {0}", outputFilename);
                }
                else
                {
                    System.IO.File.Delete(outputFilename);
                }
            }

            return(pass ? 100 : 0);
        }
Exemple #4
0
        static int Main(string[] args)
        {
            bool pass = true;

            using (SimpleEventSource eventSource = new SimpleEventSource())
            {
                using (var netPerfFile = NetPerfFile.Create(args))
                {
                    Console.WriteLine("\tStart: Enable tracing.");
                    TraceControl.Enable(GetConfig(eventSource, netPerfFile.Path));
                    Console.WriteLine("\tEnd: Enable tracing.\n");

                    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("\tStart: Disable tracing.");
                    TraceControl.Disable();
                    Console.WriteLine("\tEnd: Disable tracing.\n");

                    Console.WriteLine("\tStart: Processing events from file.");
                    int msgCount = 0;
                    using (var trace = new TraceLog(TraceLog.CreateFromEventPipeDataFile(netPerfFile.Path)).Events.GetSource())
                    {
                        var names = new HashSet <string>();

                        trace.Dynamic.All += delegate(TraceEvent data)
                        {
                            if (!names.Contains(data.ProviderName))
                            {
                                Console.WriteLine("\t{0}", data.ProviderName);
                                names.Add(data.ProviderName);
                            }

                            if (data.ProviderName == "SimpleEventSource")
                            {
                                msgCount += 1;
                            }
                        };

                        trace.Process();
                    }
                    Console.WriteLine("\tEnd: Processing events from file.\n");

                    Console.WriteLine("\tProcessed {0} events from EventSource", msgCount);

                    pass &= msgCount == messageIterations;
                }
            }

            return(pass ? 100 : 0);
        }
        static int Main(string[] args)
        {
            bool keepOutput = false;
            // Use the first arg as an output filename if there is one
            string outputFilename = null;

            if (args.Length >= 1)
            {
                outputFilename = args[0];
                keepOutput     = true;
            }
            else
            {
                outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            }

            SimpleEventSource eventSource = new SimpleEventSource();

            Console.WriteLine("\tStart: Enable tracing.");
            TraceControl.Enable(GetConfig(eventSource, outputFilename));
            Console.WriteLine("\tEnd: Enable tracing.\n");

            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("\tStart: Disable tracing.");
            TraceControl.Disable();
            Console.WriteLine("\tEnd: Disable tracing.\n");

            FileInfo outputMeta = new FileInfo(outputFilename);

            Console.WriteLine("\tCreated {0} bytes of data", outputMeta.Length);

            bool pass = false;

            if (outputMeta.Length > trivialSize)
            {
                pass = true;
            }

            if (keepOutput)
            {
                Console.WriteLine(String.Format("\tOutput file: {0}", outputFilename));
            }
            else
            {
                System.IO.File.Delete(outputFilename);
            }

            return(pass ? 100 : -1);
        }